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

Side by Side 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 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/PrivateScriptController.h"
7
8 #include "bindings/v8/V8Binding.h"
9 #include "bindings/v8/V8PerContextData.h"
10 #include "bindings/v8/V8ScriptRunner.h"
11 #include "core/PrivateScriptSources.h"
12
13 namespace WebCore {
14
15 static v8::Handle<v8::Value> compilePrivateScript(v8::Isolate* isolate, String c lassName)
16 {
17 size_t index;
18 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
19 // by make_private_script.py.
20 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
21 if (className == kPrivateScriptSources[index].name)
22 break;
23 }
24 RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kPrivateScriptSources));
25 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size);
26 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source) , isolate);
27 }
28
29 v8::Handle<v8::Value> PrivateScriptController::run(ScriptState* scriptState, Str ing className, String functionName, v8::Handle<v8::Value> receiver, int argc, v8 ::Handle<v8::Value> argv[])
30 {
31 ASSERT(scriptState->perContextData());
32 ASSERT(scriptState->executionContext());
33 v8::Isolate* isolate = scriptState->isolate();
34 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className);
35 if (compiledClass.IsEmpty()) {
36 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptController");
37 if (installedClasses.IsEmpty()) {
38 installedClasses = compilePrivateScript(isolate, "PrivateScriptContr oller");
39 scriptState->perContextData()->setCompiledPrivateScript("PrivateScri ptController", installedClasses);
40 }
41 RELEASE_ASSERT(!installedClasses.IsEmpty());
42 RELEASE_ASSERT(installedClasses->IsObject());
43
44 compilePrivateScript(isolate, className);
45
46 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St ring(isolate, className));
47 RELEASE_ASSERT(!compiledClass.IsEmpty());
48 RELEASE_ASSERT(compiledClass->IsObject());
49 scriptState->perContextData()->setCompiledPrivateScript(className, compi ledClass);
50 }
51
52 v8::Handle<v8::Value> function = v8::Handle<v8::Object>::Cast(compiledClass) ->Get(v8String(isolate, functionName));
53 RELEASE_ASSERT(!function.IsEmpty());
54 RELEASE_ASSERT(function->IsFunction());
55
56 v8::Handle<v8::Value> result = V8ScriptRunner::callFunction(v8::Handle<v8::F unction>::Cast(function), scriptState->executionContext(), receiver, argc, argv, isolate);
57 return result;
58 }
59
60 } // namespace WebCore
OLDNEW
« 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