Chromium Code Reviews| Index: Source/bindings/v8/BlinkInJSController.cpp |
| diff --git a/Source/bindings/v8/BlinkInJSController.cpp b/Source/bindings/v8/BlinkInJSController.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22c968bd60f0cf200f8202076d73555b59fc629b |
| --- /dev/null |
| +++ b/Source/bindings/v8/BlinkInJSController.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/BlinkInJSController.h" |
| + |
| +#include "bindings/v8/V8Binding.h" |
| +#include "bindings/v8/V8PerIsolateData.h" |
| +#include "bindings/v8/V8ScriptRunner.h" |
| +#include "core/BlinkInJSSources.h" |
| + |
| +namespace WebCore { |
| + |
| +static v8::Handle<v8::Value> compileBlinkInJS(v8::Isolate* isolate, String className) |
|
abarth-chromium
2014/06/20 15:17:43
compilePrivateScript ?
|
| +{ |
| + size_t index; |
| + // |kBlinkInJSSources| is defined in V8BlinkInJSSources.h, which is auto-generated |
| + // by make_blink_in_js.py. |
| + for (index = 0; index < WTF_ARRAY_LENGTH(kBlinkInJSSources); index++) { |
|
abarth-chromium
2014/06/20 15:17:42
kPrivateScriptSources
|
| + if (className == kBlinkInJSSources[index].name) |
| + break; |
|
abarth-chromium
2014/06/20 15:17:43
If we end up with a lot of these, we can probably
|
| + } |
| + RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kBlinkInJSSources)); |
| + String source(reinterpret_cast<const char*>(kBlinkInJSSources[index].source), kBlinkInJSSources[index].size); |
| + return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source), isolate); |
| +} |
| + |
| +v8::Handle<v8::Value> BlinkInJSController::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)->compiledBlinkInJS(className); |
| + if (compiledClass.IsEmpty()) { |
| + v8::Handle<v8::Value> installedClasses = V8PerIsolateData::from(isolate)->compiledBlinkInJS("BlinkInJSController"); |
| + if (installedClasses.IsEmpty()) { |
| + installedClasses = compileBlinkInJS(isolate, "BlinkInJSController"); |
| + V8PerIsolateData::from(isolate)->setCompiledBlinkInJS("BlinkInJSController", installedClasses); |
| + } |
| + RELEASE_ASSERT(!installedClasses.IsEmpty()); |
| + RELEASE_ASSERT(installedClasses->IsObject()); |
| + |
| + compileBlinkInJS(isolate, className); |
| + |
| + compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8String(isolate, className)); |
| + RELEASE_ASSERT(!compiledClass.IsEmpty()); |
| + RELEASE_ASSERT(compiledClass->IsObject()); |
| + V8PerIsolateData::from(isolate)->setCompiledBlinkInJS(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 |