| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013, Google Inc. All rights reserved. | 2 * Copyright (C) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class V8PromiseCustom { | 32 class V8PromiseCustom { |
| 33 public: | 33 public: |
| 34 enum InternalFieldIndex { | 34 enum InternalFieldIndex { |
| 35 InternalStateIndex, | 35 InternalStateIndex, |
| 36 InternalResultIndex, | 36 InternalResultIndex, |
| 37 InternalFulfillCallbackIndex, | 37 InternalFulfillCallbackIndex, |
| 38 InternalRejectCallbackIndex, | 38 InternalRejectCallbackIndex, |
| 39 InternalFieldCount, // This entry must always be at the bottom. | 39 InternalFieldCount, // This entry must always be at the bottom. |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 enum PromiseStatus { | 42 enum PromiseState { |
| 43 Pending, | 43 Pending, |
| 44 Fulfilled, | 44 Fulfilled, |
| 45 Rejected, | 45 Rejected, |
| 46 }; | 46 }; |
| 47 |
| 48 enum SynchronousMode { |
| 49 Synchronous, |
| 50 Asynchronous, |
| 51 }; |
| 52 |
| 53 // Create Promise and PromiseResolver instances and set them to |promise| an
d |resolver| respectively. |
| 54 static void createPromise(v8::Handle<v8::Object> creationContext, v8::Local<
v8::Object>* promise, v8::Local<v8::Object>* resolver, v8::Isolate*); |
| 55 |
| 56 // |resolver| must be a PromiseResolver instance. |
| 57 static void fulfillResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::
Value> result, SynchronousMode, v8::Isolate*); |
| 58 // |resolver| must be a PromiseResolver instance. |
| 59 static void rejectResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::V
alue> result, SynchronousMode, v8::Isolate*); |
| 60 |
| 61 // |promise| must be a Promise instance. |
| 62 // |fulfillCallback| and |rejectCallback| can be an empty function respectiv
ely. |
| 63 static void append(v8::Handle<v8::Object> promise, v8::Handle<v8::Function>
fulfillCallback, v8::Handle<v8::Function> rejectCallback, v8::Isolate*); |
| 64 |
| 65 // This function can take either Promise or PromiseResolver objects. |
| 66 // This function cannot be called when the internal object is detached from
|promiseOrResolver|. |
| 67 // Note that internal object can be detached only from PromiseResolver. |
| 68 static v8::Local<v8::Object> getInternal(v8::Handle<v8::Object> promiseOrRes
olver); |
| 69 |
| 70 // Return true if the internal object is detached from |resolver|. |
| 71 // |resolver| must be a PromiseResolver instance. |
| 72 static bool isInternalDetached(v8::Handle<v8::Object> resolver); |
| 73 |
| 74 // Detach the internal object from |resolver|. |
| 75 // |resolver| must be a PromiseResolver instance. |
| 76 static void detachInternal(v8::Handle<v8::Object> resolver, v8::Isolate*); |
| 77 |
| 78 // Clear the Promise / PromiseResolver internal object with the given state
and result. |
| 79 // This function clears callbacks in the object. |
| 80 static void clearInternal(v8::Handle<v8::Object> internal, PromiseState, v8:
:Handle<v8::Value> result); |
| 81 |
| 82 // |internal| must be an Promise / PromiseResolver internal object. |
| 83 static PromiseState getState(v8::Handle<v8::Object> internal); |
| 84 // |internal| must be an Promise / PromiseResolver internal object. |
| 85 static void setState(v8::Handle<v8::Object> internal, PromiseState); |
| 86 |
| 87 // Call |function| synchronously or asynchronously, depending on |mode|. |
| 88 // If |function| throws an exception, this function catches it and does not
rethrow. |
| 89 static void call(v8::Handle<v8::Function> /* function */, v8::Handle<v8::Obj
ect> receiver, v8::Handle<v8::Value> result, SynchronousMode /* mode */, v8::Iso
late*); |
| 47 }; | 90 }; |
| 48 | 91 |
| 49 } // namespace WebCore | 92 } // namespace WebCore |
| 50 | 93 |
| 51 #endif // V8PromiseCustom_h | 94 #endif // V8PromiseCustom_h |
| OLD | NEW |