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

Unified Diff: Source/core/testing/Internals.cpp

Issue 22470008: Implement ScriptPromise and ScriptFunction (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Protect the ScriptFunction with a strong ref Created 7 years, 4 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
Index: Source/core/testing/Internals.cpp
diff --git a/Source/core/testing/Internals.cpp b/Source/core/testing/Internals.cpp
index 2d48ab6bd45c67331cad339499240f8995ed7520..da71c45f10390506f9b884cdb9b377de89d10a1a 100644
--- a/Source/core/testing/Internals.cpp
+++ b/Source/core/testing/Internals.cpp
@@ -39,6 +39,8 @@
#include "RuntimeEnabledFeatures.h"
#include "TypeConversions.h"
#include "bindings/v8/ExceptionState.h"
+#include "bindings/v8/ScriptFunction.h"
+#include "bindings/v8/ScriptPromise.h"
#include "bindings/v8/SerializedScriptValue.h"
#include "bindings/v8/V8ThrowException.h"
#include "core/animation/DocumentTimeline.h"
@@ -2079,4 +2081,28 @@ bool Internals::loseSharedGraphicsContext3D()
return true;
}
+class AddOneCallback : public ScriptFunction {
+public:
+ virtual ScriptValue call(ScriptValue value) OVERRIDE
+ {
+ v8::Local<v8::Value> v8Value = value.v8Value();
+ ASSERT(v8Value->IsNumber());
+ int intValue = v8Value.As<v8::Integer>()->Value();
+ ScriptValue result = ScriptValue(v8::Integer::New(intValue + 1));
+ return result;
+ }
+private:
+ virtual ~AddOneCallback() { }
+};
+
+ScriptValue Internals::addOneToPromise(ScriptValue promiseValue)
+{
+ ScriptPromise promise(promiseValue);
+
+ bool result = promise.then(adoptRef(new AddOneCallback()));
+ ASSERT(result);
+
+ return promise.ResultPromise();
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698