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

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

Issue 345893002: Implement an infrastructure of Blink-in-JS Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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/PrivateScriptController.h ('k') | Source/bindings/v8/PrivateScriptController.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/PrivateScriptController.cpp
diff --git a/Source/bindings/v8/PrivateScriptController.cpp b/Source/bindings/v8/PrivateScriptController.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a835b66684aa88eb451631ea6b4866aca9fa2729
--- /dev/null
+++ b/Source/bindings/v8/PrivateScriptController.cpp
@@ -0,0 +1,60 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "bindings/v8/PrivateScriptController.h"
+
+#include "bindings/v8/V8Binding.h"
+#include "bindings/v8/V8PerContextData.h"
+#include "bindings/v8/V8ScriptRunner.h"
+#include "core/PrivateScriptSources.h"
+
+namespace WebCore {
+
+static v8::Handle<v8::Value> compilePrivateScript(v8::Isolate* isolate, String className)
+{
+ size_t index;
+ // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
+ // by make_private_script.py.
+ for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
+ if (className == kPrivateScriptSources[index].name)
+ break;
+ }
+ RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kPrivateScriptSources));
+ String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].source), kPrivateScriptSources[index].size);
+ return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source), isolate);
+}
+
+v8::Handle<v8::Value> PrivateScriptController::run(ScriptState* scriptState, String className, String functionName, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> argv[])
+{
+ ASSERT(scriptState->perContextData());
+ ASSERT(scriptState->executionContext());
+ v8::Isolate* isolate = scriptState->isolate();
+ v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compiledPrivateScript(className);
+ if (compiledClass.IsEmpty()) {
+ v8::Handle<v8::Value> installedClasses = scriptState->perContextData()->compiledPrivateScript("PrivateScriptController");
+ if (installedClasses.IsEmpty()) {
+ installedClasses = compilePrivateScript(isolate, "PrivateScriptController");
+ scriptState->perContextData()->setCompiledPrivateScript("PrivateScriptController", installedClasses);
+ }
+ RELEASE_ASSERT(!installedClasses.IsEmpty());
+ RELEASE_ASSERT(installedClasses->IsObject());
+
+ compilePrivateScript(isolate, className);
+
+ compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8String(isolate, className));
+ RELEASE_ASSERT(!compiledClass.IsEmpty());
+ RELEASE_ASSERT(compiledClass->IsObject());
+ scriptState->perContextData()->setCompiledPrivateScript(className, compiledClass);
+ }
+
+ v8::Handle<v8::Value> function = v8::Handle<v8::Object>::Cast(compiledClass)->Get(v8String(isolate, functionName));
+ RELEASE_ASSERT(!function.IsEmpty());
+ RELEASE_ASSERT(function->IsFunction());
+
+ v8::Handle<v8::Value> result = V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(function), scriptState->executionContext(), receiver, argc, argv, isolate);
+ return result;
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/bindings/v8/PrivateScriptController.h ('k') | Source/bindings/v8/PrivateScriptController.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698