Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Unified Diff: Source/bindings/v8/ScriptPromise.cpp

Issue 181173002: ScriptPromise should check the constructor paraemter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/ScriptPromise.h ('k') | Source/bindings/v8/ScriptPromiseTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/ScriptPromise.cpp
diff --git a/Source/bindings/v8/ScriptPromise.cpp b/Source/bindings/v8/ScriptPromise.cpp
index c389c2aea94341b3c304139e24e8e2b5386eb329..17d03b2f8017820893c9a16f84dc657f18bd2ac8 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,12 @@ 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::createPending()
{
- if (value.hasNoValue())
- return;
- v8::Local<v8::Value> v8Value(value.v8Value());
- v8::Isolate* isolate = value.isolate();
- if (V8PromiseCustom::isPromise(v8Value, isolate)) {
- m_promise = value;
- return;
- }
- m_promise = ScriptValue(V8PromiseCustom::toPromise(v8Value, isolate), isolate);
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ ASSERT(isolate->InContext());
+ v8::Handle<v8::Object> promise = V8PromiseCustom::createPromise(v8::Object::New(isolate), isolate);
+ return ScriptPromise(promise, isolate);
}
ScriptPromise ScriptPromise::createPending(ExecutionContext* context)
@@ -71,12 +76,16 @@ ScriptPromise ScriptPromise::createPending(ExecutionContext* context)
return ScriptPromise(promise, isolate);
}
-ScriptPromise ScriptPromise::createPending()
+ScriptPromise ScriptPromise::cast(const ScriptValue& value)
{
- v8::Isolate* isolate = v8::Isolate::GetCurrent();
- ASSERT(isolate->InContext());
- v8::Handle<v8::Object> promise = V8PromiseCustom::createPromise(v8::Object::New(isolate), isolate);
- return ScriptPromise(promise, isolate);
+ if (value.hasNoValue())
+ return ScriptPromise();
+ v8::Local<v8::Value> v8Value(value.v8Value());
+ v8::Isolate* isolate = value.isolate();
+ if (V8PromiseCustom::isPromise(v8Value, isolate)) {
+ return ScriptPromise(v8Value, isolate);
+ }
+ return ScriptPromise(V8PromiseCustom::toPromise(v8Value, isolate), isolate);
}
} // namespace WebCore
« no previous file with comments | « Source/bindings/v8/ScriptPromise.h ('k') | Source/bindings/v8/ScriptPromiseTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698