| 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace WebCore { | 32 namespace WebCore { |
| 33 | 33 |
| 34 class V8PromiseCustom { | 34 class V8PromiseCustom { |
| 35 public: | 35 public: |
| 36 enum InternalFieldIndex { | 36 enum InternalFieldIndex { |
| 37 InternalStateIndex, | 37 InternalStateIndex, |
| 38 InternalResultIndex, | 38 InternalResultIndex, |
| 39 InternalFulfillCallbackIndex, | 39 InternalFulfillCallbackIndex, |
| 40 InternalRejectCallbackIndex, | 40 InternalRejectCallbackIndex, |
| 41 InternalDerivedPromiseIndex, |
| 41 InternalFieldCount, // This entry must always be at the bottom. | 42 InternalFieldCount, // This entry must always be at the bottom. |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 enum WrapperCallbackEnvironmentFieldIndex { | |
| 45 WrapperCallbackEnvironmentPromiseIndex, | |
| 46 WrapperCallbackEnvironmentCallbackIndex, | |
| 47 WrapperCallbackEnvironmentFieldCount, // This entry must always be at th
e bottom. | |
| 48 }; | |
| 49 | |
| 50 enum PromiseAllEnvironmentFieldIndex { | 45 enum PromiseAllEnvironmentFieldIndex { |
| 51 PromiseAllEnvironmentPromiseIndex, | 46 PromiseAllEnvironmentPromiseIndex, |
| 52 PromiseAllEnvironmentCountdownIndex, | 47 PromiseAllEnvironmentCountdownIndex, |
| 53 PromiseAllEnvironmentIndexIndex, | 48 PromiseAllEnvironmentIndexIndex, |
| 54 PromiseAllEnvironmentResultsIndex, | 49 PromiseAllEnvironmentResultsIndex, |
| 55 PromiseAllEnvironmentFieldCount, // This entry must always be at the bot
tom. | 50 PromiseAllEnvironmentFieldCount, // This entry must always be at the bot
tom. |
| 56 }; | 51 }; |
| 57 | 52 |
| 58 enum PrimitiveWrapperFieldIndex { | 53 enum PrimitiveWrapperFieldIndex { |
| 59 PrimitiveWrapperPrimitiveIndex, | 54 PrimitiveWrapperPrimitiveIndex, |
| 60 PrimitiveWrapperFieldCount, // This entry must always be at the bottom. | 55 PrimitiveWrapperFieldCount, // This entry must always be at the bottom. |
| 61 }; | 56 }; |
| 62 | 57 |
| 63 enum PromiseState { | 58 enum PromiseState { |
| 64 Pending, | 59 Pending, |
| 65 Fulfilled, | 60 Fulfilled, |
| 66 Rejected, | 61 Rejected, |
| 67 Following, | 62 Following, |
| 68 }; | 63 }; |
| 69 | 64 |
| 70 enum SynchronousMode { | |
| 71 Synchronous, | |
| 72 Asynchronous, | |
| 73 }; | |
| 74 | |
| 75 static v8::Local<v8::Object> createPromise(v8::Handle<v8::Object> creationCo
ntext, v8::Isolate*); | 65 static v8::Local<v8::Object> createPromise(v8::Handle<v8::Object> creationCo
ntext, v8::Isolate*); |
| 76 | 66 |
| 77 // |promise| must be a Promise instance. | 67 // |promise| must be a Promise instance. |
| 78 static void fulfill(v8::Handle<v8::Object> promise, v8::Handle<v8::Value> re
sult, SynchronousMode, v8::Isolate*); | |
| 79 // |promise| must be a Promise instance. | |
| 80 static void resolve(v8::Handle<v8::Object> promise, v8::Handle<v8::Value> re
sult, SynchronousMode, v8::Isolate*); | |
| 81 // |promise| must be a Promise instance. | |
| 82 static void reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Value> res
ult, SynchronousMode, v8::Isolate*); | |
| 83 | |
| 84 // |promise| must be a Promise instance. | |
| 85 // |fulfillCallback| and |rejectCallback| can be an empty function respectiv
ely. | |
| 86 static void append(v8::Handle<v8::Object> promise, v8::Handle<v8::Function>
fulfillCallback, v8::Handle<v8::Function> rejectCallback, v8::Isolate*); | |
| 87 | |
| 88 // |promise| must be a Promise instance. | |
| 89 static v8::Local<v8::Object> getInternal(v8::Handle<v8::Object> promise); | 68 static v8::Local<v8::Object> getInternal(v8::Handle<v8::Object> promise); |
| 90 | 69 |
| 91 // |internal| must be a Promise internal object. | 70 // |internal| must be a Promise internal object. |
| 92 // Clear the Promise internal object with the given state and result. | 71 static PromiseState getState(v8::Handle<v8::Object> internal); |
| 93 // This function clears callbacks in the object. | |
| 94 static void clearInternal(v8::Handle<v8::Object> internal, PromiseState, v8:
:Handle<v8::Value> result, v8::Isolate*); | |
| 95 | 72 |
| 96 // |internal| must be a Promise internal object. | 73 // |internal| must be a Promise internal object. |
| 97 static PromiseState getState(v8::Handle<v8::Object> internal); | 74 // Set a |promise|'s state and result that correspond to the state. |
| 98 // |internal| must be a Promise internal object. | 75 static void setState(v8::Handle<v8::Object> internal, PromiseState, v8::Hand
le<v8::Value>, v8::Isolate*); |
| 99 static void setState(v8::Handle<v8::Object> internal, PromiseState, v8::Isol
ate*); | |
| 100 | 76 |
| 101 // Call |function| synchronously or asynchronously, depending on |mode|. | 77 // Return true if |maybePromise| is a Promise instance. |
| 102 // If |function| throws an exception, this function catches it and does not
rethrow. | |
| 103 static void call(v8::Handle<v8::Function> /* function */, v8::Handle<v8::Obj
ect> receiver, v8::Handle<v8::Value> result, SynchronousMode /* mode */, v8::Iso
late*); | |
| 104 | |
| 105 // Return true if |maybePromise| is a Promise object. | |
| 106 static bool isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate*); | 78 static bool isPromise(v8::Handle<v8::Value> maybePromise, v8::Isolate*); |
| 107 | 79 |
| 108 // Coerces |maybePromise| to a Promise object. | 80 // Coerces |maybePromise| to a Promise instance. |
| 109 static v8::Local<v8::Object> toPromise(v8::Handle<v8::Value> maybePromise, v
8::Isolate*); | 81 static v8::Local<v8::Object> toPromise(v8::Handle<v8::Value> maybePromise, v
8::Isolate*); |
| 82 |
| 83 // |promise| must be a Promise instance. |
| 84 static void resolve(v8::Handle<v8::Object> promise, v8::Handle<v8::Value> re
sult, v8::Isolate*); |
| 85 |
| 86 // |promise| must be a Promise instance. |
| 87 static void reject(v8::Handle<v8::Object> promise, v8::Handle<v8::Value> res
ult, v8::Isolate*); |
| 88 |
| 89 // |promise| must be a Promise instance. |
| 90 // |onFulfilled| and |onRejected| can be an empty value respectively. |
| 91 // Appends |onFulfilled| and/or |onRejected| handlers to |promise|. |
| 92 static v8::Local<v8::Object> then(v8::Handle<v8::Object> promise, v8::Handle
<v8::Function> onFulfilled, v8::Handle<v8::Function> onRejected, v8::Isolate*); |
| 93 |
| 94 // |promise| must be a Promise instance. |
| 95 // Set a |promise|'s value and propagate it to derived promises. |
| 96 static void setValue(v8::Handle<v8::Object> promise, v8::Handle<v8::Value>,
v8::Isolate*); |
| 97 |
| 98 // |promise| must be a Promise instance. |
| 99 // Set a |promise|'s failure reason and propagate it to derived promises. |
| 100 static void setReason(v8::Handle<v8::Object> promise, v8::Handle<v8::Value>,
v8::Isolate*); |
| 101 |
| 102 // |promise| must be a Promise instance. |
| 103 // Propagate a |promise|'s value or reason to all of its derived promies. |
| 104 static void propagateToDerived(v8::Handle<v8::Object> promise, v8::Isolate*)
; |
| 105 |
| 106 // |derivedPromise| and |originator| must be a Promise instance. |
| 107 // |onFulfilled| and |onRejected| can be an empty value respectively. |
| 108 // Propagate |originator|'s state to |derivedPromise|. |
| 109 static void updateDerived(v8::Handle<v8::Object> derivedPromise, v8::Handle<
v8::Function> onFulfilled, v8::Handle<v8::Function> onRejected, v8::Handle<v8::O
bject> originator, v8::Isolate*); |
| 110 |
| 111 // |derivedPromise| must be a Promise instance. |
| 112 // Propagate a value to |derivedPromise|. |
| 113 static void updateDerivedFromValue(v8::Handle<v8::Object> derivedPromise, v8
::Handle<v8::Function> onFulfilled, v8::Handle<v8::Value>, v8::Isolate*); |
| 114 |
| 115 // |derivedPromise| must be a Promise instance. |
| 116 // Propagate a failure reason to |derivedPromise|. |
| 117 static void updateDerivedFromReason(v8::Handle<v8::Object> derivedPromise, v
8::Handle<v8::Function> onRejected, v8::Handle<v8::Value>, v8::Isolate*); |
| 118 |
| 119 // |derivedPromise| and |promise| must be a Promise instance. |
| 120 // |onFulfilled| and |onRejected| can be an empty value respectively. |
| 121 // Propagate |promise|'s state to |derivedPromise|. |
| 122 static void updateDerivedFromPromise(v8::Handle<v8::Object> derivedPromise,
v8::Handle<v8::Function> onFulfilled, v8::Handle<v8::Function> onRejected, v8::H
andle<v8::Object> promise, v8::Isolate*); |
| 123 |
| 124 // Returns a Promise instance that will be fulfilled or rejected by |
| 125 // |thenable|'s result. |
| 126 static v8::Local<v8::Object> coerceThenable(v8::Handle<v8::Object> thenable,
v8::Handle<v8::Function> then, v8::Isolate*); |
| 127 |
| 128 // |promise| must be a Promise instance. |
| 129 // Applies a transformation to an argument and use it to update derived |
| 130 // promies. |
| 131 static void callHandler(v8::Handle<v8::Object> promise, v8::Handle<v8::Funct
ion> handler, v8::Handle<v8::Value> argument, v8::Isolate*); |
| 110 }; | 132 }; |
| 111 | 133 |
| 112 } // namespace WebCore | 134 } // namespace WebCore |
| 113 | 135 |
| 114 #endif // V8PromiseCustom_h | 136 #endif // V8PromiseCustom_h |
| OLD | NEW |