| 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 PromiseAlgorithm { |
| 43 FulfillAlgorithm, |
| 44 ResolveAlgorithm, |
| 45 RejectAlgorithm, |
| 46 }; |
| 47 |
| 42 enum PromiseState { | 48 enum PromiseState { |
| 43 Pending, | 49 Pending, |
| 44 Fulfilled, | 50 Fulfilled, |
| 45 Rejected, | 51 Rejected, |
| 52 PendingWithResolvedFlagSet, |
| 46 }; | 53 }; |
| 47 | 54 |
| 48 enum SynchronousMode { | 55 enum SynchronousMode { |
| 49 Synchronous, | 56 Synchronous, |
| 50 Asynchronous, | 57 Asynchronous, |
| 51 }; | 58 }; |
| 52 | 59 |
| 53 // Create Promise and PromiseResolver instances and set them to |promise| an
d |resolver| respectively. | 60 // 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*); | 61 static void createPromise(v8::Handle<v8::Object> creationContext, v8::Local<
v8::Object>* promise, v8::Local<v8::Object>* resolver, v8::Isolate*); |
| 55 | 62 |
| 56 // |resolver| must be a PromiseResolver instance. | 63 // |resolver| must be a PromiseResolver instance. |
| 57 static void fulfillResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::
Value> result, SynchronousMode, v8::Isolate*); | 64 static void fulfillResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::
Value> result, SynchronousMode, v8::Isolate*); |
| 58 // |resolver| must be a PromiseResolver instance. | 65 // |resolver| must be a PromiseResolver instance. |
| 66 static void resolveResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::
Value> result, SynchronousMode, v8::Isolate*); |
| 67 // |resolver| must be a PromiseResolver instance. |
| 59 static void rejectResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::V
alue> result, SynchronousMode, v8::Isolate*); | 68 static void rejectResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::V
alue> result, SynchronousMode, v8::Isolate*); |
| 60 | 69 |
| 61 // |promise| must be a Promise instance. | 70 // |promise| must be a Promise instance. |
| 62 // |fulfillCallback| and |rejectCallback| can be an empty function respectiv
ely. | 71 // |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*); | 72 static void append(v8::Handle<v8::Object> promise, v8::Handle<v8::Function>
fulfillCallback, v8::Handle<v8::Function> rejectCallback, v8::Isolate*); |
| 64 | 73 |
| 65 // This function can take either Promise or PromiseResolver objects. | 74 // This function can take either Promise or PromiseResolver objects. |
| 66 // This function cannot be called when the internal object is detached from
|promiseOrResolver|. | 75 // This function cannot be called when the internal object is detached from
|promiseOrResolver|. |
| 67 // Note that internal object can be detached only from PromiseResolver. | 76 // Note that internal object can be detached only from PromiseResolver. |
| 68 static v8::Local<v8::Object> getInternal(v8::Handle<v8::Object> promiseOrRes
olver); | 77 static v8::Local<v8::Object> getInternal(v8::Handle<v8::Object> promiseOrRes
olver); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 static void setState(v8::Handle<v8::Object> internal, PromiseState); | 94 static void setState(v8::Handle<v8::Object> internal, PromiseState); |
| 86 | 95 |
| 87 // Call |function| synchronously or asynchronously, depending on |mode|. | 96 // Call |function| synchronously or asynchronously, depending on |mode|. |
| 88 // If |function| throws an exception, this function catches it and does not
rethrow. | 97 // 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*); | 98 static void call(v8::Handle<v8::Function> /* function */, v8::Handle<v8::Obj
ect> receiver, v8::Handle<v8::Value> result, SynchronousMode /* mode */, v8::Iso
late*); |
| 90 }; | 99 }; |
| 91 | 100 |
| 92 } // namespace WebCore | 101 } // namespace WebCore |
| 93 | 102 |
| 94 #endif // V8PromiseCustom_h | 103 #endif // V8PromiseCustom_h |
| OLD | NEW |