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

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
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..5a63c4e0c168e4aa03aeb9391cb64fd6725d05be
--- /dev/null
+++ b/Source/bindings/v8/PrivateScriptController.cpp
@@ -0,0 +1,61 @@
+// 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/V8PerIsolateData.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(v8::Isolate* isolate, String className, String functionName, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> argv[])
+{
+ ExecutionContext* executionContext = currentExecutionContext(isolate);
+ if (!executionContext)
+ return v8::Handle<v8::Value>();
+
+ v8::Handle<v8::Value> compiledClass = V8PerIsolateData::from(isolate)->compiledPrivateScript(className);
+ if (compiledClass.IsEmpty()) {
+ v8::Handle<v8::Value> installedClasses = V8PerIsolateData::from(isolate)->compiledPrivateScript("PrivateScriptController");
+ if (installedClasses.IsEmpty()) {
+ installedClasses = compilePrivateScript(isolate, "PrivateScriptController");
+ V8PerIsolateData::from(isolate)->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());
+ V8PerIsolateData::from(isolate)->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), executionContext, receiver, argc, argv, isolate);
+ return result;
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698