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 WrapperCallbackEnvironmentFieldIndex { |
| 43 WrapperCallbackEnvironmentPromiseIndex, |
| 44 WrapperCallbackEnvironmentPromiseResolverIndex, |
| 45 WrapperCallbackEnvironmentCallbackIndex, |
| 46 WrapperCallbackEnvironmentFieldCount, // This entry must always be at th
e bottom. |
| 47 }; |
| 48 |
| 49 enum PromiseAlgorithm { |
| 50 FulfillAlgorithm, |
| 51 ResolveAlgorithm, |
| 52 RejectAlgorithm, |
| 53 }; |
| 54 |
| 55 enum PromiseState { |
43 Pending, | 56 Pending, |
44 Fulfilled, | 57 Fulfilled, |
45 Rejected, | 58 Rejected, |
46 }; | 59 }; |
| 60 |
| 61 enum SynchronousMode { |
| 62 Synchronous, |
| 63 Asynchronous, |
| 64 }; |
| 65 |
| 66 // Create Promise and PromiseResolver instances and set them to |promise| an
d |resolver| respectively. |
| 67 static void createPromise(v8::Handle<v8::Object> creationContext, v8::Local<
v8::Object>* promise, v8::Local<v8::Object>* resolver, v8::Isolate*); |
| 68 |
| 69 // |resolver| must be a PromiseResolver instance. |
| 70 static void fulfillResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::
Value> result, SynchronousMode, v8::Isolate*); |
| 71 // |resolver| must be a PromiseResolver instance. |
| 72 static void resolveResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::
Value> result, SynchronousMode, v8::Isolate*); |
| 73 // |resolver| must be a PromiseResolver instance. |
| 74 static void rejectResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::V
alue> result, SynchronousMode, v8::Isolate*); |
| 75 |
| 76 // |promise| must be a Promise instance. |
| 77 // |fulfillCallback| and |rejectCallback| can be an empty function respectiv
ely. |
| 78 static void append(v8::Handle<v8::Object> promise, v8::Handle<v8::Function>
fulfillCallback, v8::Handle<v8::Function> rejectCallback, v8::Isolate*); |
| 79 |
| 80 // This function can take either Promise or PromiseResolver objects. |
| 81 // If the internal object of a PromiseResolver was set to null, this functio
n returns an empty object. |
| 82 static v8::Local<v8::Object> getInternal(v8::Handle<v8::Object> promiseOrPro
miseResolver); |
| 83 |
| 84 // Clear the Promise / PromiseResolver internal object with the given state
and result. |
| 85 // This function clears callbacks in the object. |
| 86 static void clearInternal(v8::Handle<v8::Object> internal, PromiseState, v8:
:Handle<v8::Value> result); |
| 87 |
| 88 // |internal| must be an Promise / PromiseResolver internal object. |
| 89 static PromiseState getState(v8::Handle<v8::Object> internal); |
| 90 // |internal| must be an Promise / PromiseResolver internal object. |
| 91 static void setState(v8::Handle<v8::Object> internal, PromiseState); |
| 92 |
| 93 // Call |function| synchronously or asynchronously, depending on |mode|. |
| 94 // If |function| throws an exception, this function catches it and does not
rethrow. |
| 95 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 }; | 96 }; |
48 | 97 |
49 } // namespace WebCore | 98 } // namespace WebCore |
50 | 99 |
51 #endif // V8PromiseCustom_h | 100 #endif // V8PromiseCustom_h |
OLD | NEW |