| Index: Source/bindings/v8/custom/V8PromiseCustom.cpp
|
| diff --git a/Source/bindings/v8/custom/V8PromiseCustom.cpp b/Source/bindings/v8/custom/V8PromiseCustom.cpp
|
| index c9dbdb7848713d8117c1b0c5a1f32fbddec15353..c68c5cded9d05ea3f31ce1c6399c5212229430d0 100644
|
| --- a/Source/bindings/v8/custom/V8PromiseCustom.cpp
|
| +++ b/Source/bindings/v8/custom/V8PromiseCustom.cpp
|
| @@ -32,7 +32,6 @@
|
| #include "bindings/v8/custom/V8PromiseCustom.h"
|
|
|
| #include "V8Promise.h"
|
| -#include "V8PromiseResolver.h"
|
| #include "bindings/v8/ScopedPersistent.h"
|
| #include "bindings/v8/ScriptFunctionCall.h"
|
| #include "bindings/v8/ScriptState.h"
|
| @@ -95,6 +94,13 @@ v8::Local<v8::ObjectTemplate> internalObjectTemplate(v8::Isolate* isolate)
|
| return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::InternalFieldCount, isolate);
|
| }
|
|
|
| +v8::Local<v8::ObjectTemplate> resolverObjectTemplate(v8::Isolate* isolate)
|
| +{
|
| + // This is only for getting a unique pointer which we can pass to privateTemplate.
|
| + static int privateTemplateUniqueKey = 0;
|
| + return cachedObjectTemplate(&privateTemplateUniqueKey, V8PromiseCustom::ResolverFieldCount, isolate);
|
| +}
|
| +
|
| class PromiseTask : public ScriptExecutionContext::Task {
|
| public:
|
| PromiseTask(v8::Handle<v8::Function> callback, v8::Handle<v8::Object> receiver, v8::Handle<v8::Value> result, v8::Isolate* isolate)
|
| @@ -287,6 +293,42 @@ v8::Local<v8::Object> promiseEveryEnvironment(v8::Handle<v8::Object> resolver, v
|
| return environment;
|
| }
|
|
|
| +void promiseResolve(const v8::FunctionCallbackInfo<v8::Value>& args)
|
| +{
|
| + v8::Local<v8::Object> resolver = args.Data().As<v8::Object>();
|
| + ASSERT(!resolver.IsEmpty());
|
| + if (V8PromiseCustom::isInternalDetached(resolver))
|
| + return;
|
| + v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(resolver);
|
| + if (V8PromiseCustom::getState(internal) != V8PromiseCustom::Pending)
|
| + return;
|
| + v8::Isolate* isolate = args.GetIsolate();
|
| + V8PromiseCustom::setState(internal, V8PromiseCustom::PendingWithResolvedFlagSet, isolate);
|
| +
|
| + v8::Local<v8::Value> result = v8::Undefined(isolate);
|
| + if (args.Length() > 0)
|
| + result = args[0];
|
| + V8PromiseCustom::resolveResolver(resolver, result, V8PromiseCustom::Asynchronous, isolate);
|
| +}
|
| +
|
| +void promiseReject(const v8::FunctionCallbackInfo<v8::Value>& args)
|
| +{
|
| + v8::Local<v8::Object> resolver = args.Data().As<v8::Object>();
|
| + ASSERT(!resolver.IsEmpty());
|
| + if (V8PromiseCustom::isInternalDetached(resolver))
|
| + return;
|
| + v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(resolver);
|
| + if (V8PromiseCustom::getState(internal) != V8PromiseCustom::Pending)
|
| + return;
|
| + v8::Isolate* isolate = args.GetIsolate();
|
| + V8PromiseCustom::setState(internal, V8PromiseCustom::PendingWithResolvedFlagSet, isolate);
|
| +
|
| + v8::Local<v8::Value> result = v8::Undefined(isolate);
|
| + if (args.Length() > 0)
|
| + result = args[0];
|
| + V8PromiseCustom::rejectResolver(resolver, result, V8PromiseCustom::Asynchronous, isolate);
|
| +}
|
| +
|
| } // namespace
|
|
|
| void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
|
| @@ -301,7 +343,8 @@ void V8Promise::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& arg
|
| v8::Local<v8::Object> promise, resolver;
|
| V8PromiseCustom::createPromise(args.Holder(), &promise, &resolver, isolate);
|
| v8::Handle<v8::Value> argv[] = {
|
| - resolver,
|
| + createClosure(promiseResolve, resolver),
|
| + createClosure(promiseReject, resolver)
|
| };
|
| v8::TryCatch trycatch;
|
| if (V8ScriptRunner::callFunction(init, getScriptExecutionContext(), promise, WTF_ARRAY_LENGTH(argv), argv, isolate).IsEmpty()) {
|
| @@ -489,9 +532,10 @@ void V8Promise::someMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args
|
| void V8PromiseCustom::createPromise(v8::Handle<v8::Object> creationContext, v8::Local<v8::Object>* promise, v8::Local<v8::Object>* resolver, v8::Isolate* isolate)
|
| {
|
| v8::Local<v8::ObjectTemplate> internalTemplate = internalObjectTemplate(isolate);
|
| + v8::Local<v8::ObjectTemplate> resolverTemplate = resolverObjectTemplate(isolate);
|
| v8::Local<v8::Object> internal = internalTemplate->NewInstance();
|
| + *resolver = resolverTemplate->NewInstance();
|
| *promise = V8DOMWrapper::createWrapper(creationContext, &V8Promise::info, 0, isolate);
|
| - *resolver = V8DOMWrapper::createWrapper(creationContext, &V8PromiseResolver::info, 0, isolate);
|
|
|
| clearInternal(internal, V8PromiseCustom::Pending, v8::Undefined(isolate), isolate);
|
|
|
|
|