Chromium Code Reviews| Index: Source/bindings/v8/ScriptPromise.cpp |
| diff --git a/Source/bindings/v8/ScriptPromise.cpp b/Source/bindings/v8/ScriptPromise.cpp |
| index c389c2aea94341b3c304139e24e8e2b5386eb329..812ecb4106d78b7ecf60daa1b6683b370431343b 100644 |
| --- a/Source/bindings/v8/ScriptPromise.cpp |
| +++ b/Source/bindings/v8/ScriptPromise.cpp |
| @@ -39,6 +39,16 @@ |
| namespace WebCore { |
| +ScriptPromise::ScriptPromise(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
| +{ |
| + if (value.IsEmpty() || !V8PromiseCustom::isPromise(value, isolate)) { |
| + m_promise = ScriptValue(v8::Handle<v8::Value>(), isolate); |
| + V8ThrowException::throwTypeError("the given value is not a Promise", isolate); |
| + return; |
| + } |
| + m_promise = ScriptValue(value, isolate); |
| +} |
| + |
| ScriptPromise ScriptPromise::then(PassOwnPtr<ScriptFunction> onFulfilled, PassOwnPtr<ScriptFunction> onRejected) |
| { |
| if (m_promise.hasNoValue() || !m_promise.isObject()) |
| @@ -47,17 +57,16 @@ ScriptPromise ScriptPromise::then(PassOwnPtr<ScriptFunction> onFulfilled, PassOw |
| return ScriptPromise(V8PromiseCustom::then(promise, adoptByGarbageCollector(onFulfilled), adoptByGarbageCollector(onRejected), isolate()), isolate()); |
| } |
| -ScriptPromise::ScriptPromise(const ScriptValue& value) |
| +ScriptPromise ScriptPromise::cast(const ScriptValue& value) |
|
kinuko
2014/02/26 07:53:21
nit: can we match the order in .h and in .cpp? (th
yhirano
2014/02/26 09:29:57
Done.
|
| { |
| if (value.hasNoValue()) |
| - return; |
| + return ScriptPromise(); |
| v8::Local<v8::Value> v8Value(value.v8Value()); |
| v8::Isolate* isolate = value.isolate(); |
| if (V8PromiseCustom::isPromise(v8Value, isolate)) { |
| - m_promise = value; |
| - return; |
| + return ScriptPromise(v8Value, isolate); |
| } |
| - m_promise = ScriptValue(V8PromiseCustom::toPromise(v8Value, isolate), isolate); |
| + return ScriptPromise(V8PromiseCustom::toPromise(v8Value, isolate), isolate); |
| } |
| ScriptPromise ScriptPromise::createPending(ExecutionContext* context) |