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

Side by Side Diff: Source/bindings/v8/BlinkInJSController.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "bindings/v8/BlinkInJSController.h"
7
8 #include "bindings/v8/V8Binding.h"
9 #include "bindings/v8/V8PerIsolateData.h"
10 #include "bindings/v8/V8ScriptRunner.h"
11 #include "core/BlinkInJSSources.h"
12
13 namespace WebCore {
14
15 static v8::Handle<v8::Value> compileBlinkInJS(v8::Isolate* isolate, String class Name)
abarth-chromium 2014/06/20 15:17:43 compilePrivateScript ?
16 {
17 size_t index;
18 // |kBlinkInJSSources| is defined in V8BlinkInJSSources.h, which is auto-gen erated
19 // by make_blink_in_js.py.
20 for (index = 0; index < WTF_ARRAY_LENGTH(kBlinkInJSSources); index++) {
abarth-chromium 2014/06/20 15:17:42 kPrivateScriptSources
21 if (className == kBlinkInJSSources[index].name)
22 break;
abarth-chromium 2014/06/20 15:17:43 If we end up with a lot of these, we can probably
23 }
24 RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kBlinkInJSSources));
25 String source(reinterpret_cast<const char*>(kBlinkInJSSources[index].source) , kBlinkInJSSources[index].size);
26 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source) , isolate);
27 }
28
29 v8::Handle<v8::Value> BlinkInJSController::run(v8::Isolate* isolate, String clas sName, String functionName, v8::Handle<v8::Value> receiver, int argc, v8::Handle <v8::Value> argv[])
30 {
31 ExecutionContext* executionContext = currentExecutionContext(isolate);
32 if (!executionContext)
33 return v8::Handle<v8::Value>();
34
35 v8::Handle<v8::Value> compiledClass = V8PerIsolateData::from(isolate)->compi ledBlinkInJS(className);
36 if (compiledClass.IsEmpty()) {
37 v8::Handle<v8::Value> installedClasses = V8PerIsolateData::from(isolate) ->compiledBlinkInJS("BlinkInJSController");
38 if (installedClasses.IsEmpty()) {
39 installedClasses = compileBlinkInJS(isolate, "BlinkInJSController");
40 V8PerIsolateData::from(isolate)->setCompiledBlinkInJS("BlinkInJSCont roller", installedClasses);
41 }
42 RELEASE_ASSERT(!installedClasses.IsEmpty());
43 RELEASE_ASSERT(installedClasses->IsObject());
44
45 compileBlinkInJS(isolate, className);
46
47 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St ring(isolate, className));
48 RELEASE_ASSERT(!compiledClass.IsEmpty());
49 RELEASE_ASSERT(compiledClass->IsObject());
50 V8PerIsolateData::from(isolate)->setCompiledBlinkInJS(className, compile dClass);
51 }
52
53 v8::Handle<v8::Value> function = v8::Handle<v8::Object>::Cast(compiledClass) ->Get(v8String(isolate, functionName));
54 RELEASE_ASSERT(!function.IsEmpty());
55 RELEASE_ASSERT(function->IsFunction());
56
57 v8::Handle<v8::Value> result = V8ScriptRunner::callFunction(v8::Handle<v8::F unction>::Cast(function), executionContext, receiver, argc, argv, isolate);
58 return result;
59 }
60
61 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698