Index: Source/bindings/v8/ScriptPromiseResolver.cpp |
diff --git a/Source/bindings/v8/ScriptPromiseResolver.cpp b/Source/bindings/v8/ScriptPromiseResolver.cpp |
index 78824907e1136b5d2a72f72c337afb9446e7c0a6..80306c2590e0de9beb54da4f2fc895068dc5af5b 100644 |
--- a/Source/bindings/v8/ScriptPromiseResolver.cpp |
+++ b/Source/bindings/v8/ScriptPromiseResolver.cpp |
@@ -42,90 +42,53 @@ |
namespace WebCore { |
-ScriptPromiseResolver::ScriptPromiseResolver(v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
+ScriptPromiseResolver::ScriptPromiseResolver(ScriptPromise promise, v8::Isolate* isolate) |
: m_isolate(isolate) |
- , m_promiseForExposeDetached(false) |
- , m_promiseForResolveDetached(false) |
+ , m_promise(promise) |
{ |
ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
- v8::Local<v8::Object> promise = V8PromiseCustom::createPromise(creationContext, isolate); |
- m_promise = ScriptPromise(promise, isolate); |
} |
ScriptPromiseResolver::~ScriptPromiseResolver() |
{ |
- // We don't call "detach" here because it requires a caller |
+ // We don't call "reject" here because it requires a caller |
// to be in a v8 context. |
- detachPromiseForExpose(); |
- detachPromiseForResolve(); |
+ m_promise.clear(); |
} |
-void ScriptPromiseResolver::detachPromise() |
-{ |
- detachPromiseForExpose(); |
-} |
- |
-void ScriptPromiseResolver::detachPromiseForExpose() |
-{ |
- m_promiseForExposeDetached = true; |
- if (m_promiseForResolveDetached) |
- m_promise.clear(); |
-} |
- |
-void ScriptPromiseResolver::detachPromiseForResolve() |
-{ |
- m_promiseForResolveDetached = true; |
- if (m_promiseForExposeDetached) |
- m_promise.clear(); |
-} |
- |
-PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(ExecutionContext* context) |
+PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(ScriptPromise promise, ExecutionContext* context) |
{ |
ASSERT(v8::Context::InContext()); |
ASSERT(context); |
- return adoptRef(new ScriptPromiseResolver(toV8Context(context, DOMWrapperWorld::current())->Global(), toIsolate(context))); |
+ return adoptRef(new ScriptPromiseResolver(promise, toIsolate(context))); |
} |
-PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create() |
+PassRefPtr<ScriptPromiseResolver> ScriptPromiseResolver::create(ScriptPromise promise) |
{ |
ASSERT(v8::Context::InContext()); |
v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
- return adoptRef(new ScriptPromiseResolver(v8::Object::New(), isolate)); |
+ return adoptRef(new ScriptPromiseResolver(promise, isolate)); |
} |
bool ScriptPromiseResolver::isPending() const |
{ |
ASSERT(v8::Context::InContext()); |
- if (m_promiseForResolveDetached) |
+ if (m_promise.hasNoValue()) |
return false; |
- ASSERT(!m_promise.hasNoValue()); |
v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); |
v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); |
V8PromiseCustom::PromiseState state = V8PromiseCustom::getState(internal); |
return state == V8PromiseCustom::Pending; |
} |
-void ScriptPromiseResolver::detach() |
-{ |
- ASSERT(v8::Context::InContext()); |
- detachPromiseForExpose(); |
- reject(v8::Undefined(m_isolate)); |
- detachPromiseForResolve(); |
-} |
- |
-void ScriptPromiseResolver::fulfill(v8::Handle<v8::Value> value) |
-{ |
- resolve(value); |
-} |
- |
void ScriptPromiseResolver::resolve(v8::Handle<v8::Value> value) |
{ |
ASSERT(v8::Context::InContext()); |
if (!isPending()) |
return; |
V8PromiseCustom::resolve(m_promise.v8Value().As<v8::Object>(), value, m_isolate); |
- detachPromiseForResolve(); |
+ m_promise.clear(); |
} |
void ScriptPromiseResolver::reject(v8::Handle<v8::Value> value) |
@@ -134,12 +97,7 @@ void ScriptPromiseResolver::reject(v8::Handle<v8::Value> value) |
if (!isPending()) |
return; |
V8PromiseCustom::reject(m_promise.v8Value().As<v8::Object>(), value, m_isolate); |
- detachPromiseForResolve(); |
-} |
- |
-void ScriptPromiseResolver::fulfill(ScriptValue value) |
-{ |
- resolve(value); |
+ m_promise.clear(); |
} |
void ScriptPromiseResolver::resolve(ScriptValue value) |