Chromium Code Reviews| 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 // Create Promise and PromiseResolver instances and set them to |promise| an d |resolver| respectively. | |
| 62 static void createPromise(v8::Handle<v8::Object> creationContext, v8::Local< v8::Object>* promise, v8::Local<v8::Object>* resolver, v8::Isolate*); | |
| 63 | |
| 64 // |resolver| must be a PromiseResolver instance. | |
| 65 static void fulfillResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8:: Value> result, bool synchronous, v8::Isolate*); | |
|
abarth-chromium
2013/06/27 03:25:16
Should we use an enum rather than a bool for |sync
yhirano
2013/06/27 05:40:34
Done.
| |
| 66 // |resolver| must be a PromiseResolver instance. | |
| 67 static void resolveResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8:: Value> result, bool synchronous, v8::Isolate*); | |
| 68 // |resolver| must be a PromiseResolver instance. | |
| 69 static void rejectResolver(v8::Handle<v8::Object> resolver, v8::Handle<v8::V alue> result, bool synchronous, v8::Isolate*); | |
| 70 | |
| 71 // |promise| must be a Promise instance. | |
| 72 // |fulfillCallback| and |rejectCallback| can be an empty function respectiv ely. | |
| 73 static void append(v8::Handle<v8::Object> promise, v8::Handle<v8::Function> fulfillCallback, v8::Handle<v8::Function> rejectCallback, v8::Isolate*); | |
| 74 | |
| 75 // This function can take either Promise or PromiseResolver objects. | |
| 76 // If the internal object of a PromiseResolver was set to null, this functio n returns an empty object. | |
| 77 static v8::Local<v8::Object> getInternal(v8::Handle<v8::Object> promiseOrPro miseResolver); | |
| 78 | |
| 79 // Clear the Promise / PromiseResolver internal object with the given state and result. | |
| 80 // This function clears callbacks in the object. | |
| 81 static void clearInternal(v8::Handle<v8::Object> internal, PromiseState, v8: :Handle<v8::Value> result); | |
| 82 | |
| 83 // |internal| must be an Promise / PromiseResolver internal object. | |
| 84 static PromiseState getState(v8::Handle<v8::Object> internal); | |
| 85 // |internal| must be an Promise / PromiseResolver internal object. | |
| 86 static void setState(v8::Handle<v8::Object> internal, PromiseState); | |
| 87 | |
| 88 // Call |function| synchronously or asynchronously, depending on |synchronou s|. | |
| 89 // If |function| throws an exception, this function catches it and does not rethrow. | |
| 90 static void call(v8::Handle<v8::Function> /* function */, v8::Handle<v8::Obj ect> receiver, v8::Handle<v8::Value> result, bool synchronous, v8::Isolate*); | |
| 47 }; | 91 }; |
| 48 | 92 |
| 49 } // namespace WebCore | 93 } // namespace WebCore |
| 50 | 94 |
| 51 #endif // V8PromiseCustom_h | 95 #endif // V8PromiseCustom_h |
| OLD | NEW |