OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "bindings/v8/PrivateScriptRunner.h" | 6 #include "bindings/v8/PrivateScriptRunner.h" |
7 | 7 |
8 #include "bindings/v8/V8Binding.h" | 8 #include "bindings/v8/V8Binding.h" |
9 #include "bindings/v8/V8PerContextData.h" | 9 #include "bindings/v8/V8PerContextData.h" |
10 #include "bindings/v8/V8ScriptRunner.h" | 10 #include "bindings/v8/V8ScriptRunner.h" |
11 #include "core/PrivateScriptSources.h" | 11 #include "core/PrivateScriptSources.h" |
12 | 12 |
13 namespace WebCore { | 13 namespace WebCore { |
14 | 14 |
15 static v8::Handle<v8::Value> compilePrivateScript(v8::Isolate* isolate, String c
lassName) | 15 static v8::Handle<v8::Value> compilePrivateScript(v8::Isolate* isolate, String c
lassName) |
16 { | 16 { |
17 size_t index; | 17 size_t index; |
18 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is
auto-generated | 18 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is
auto-generated |
19 // by make_private_script.py. | 19 // by make_private_script.py. |
20 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { | 20 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { |
21 if (className == kPrivateScriptSources[index].name) | 21 if (className == kPrivateScriptSources[index].name) |
22 break; | 22 break; |
23 } | 23 } |
24 RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kPrivateScriptSources)); | 24 RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kPrivateScriptSources)); |
25 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou
rce), kPrivateScriptSources[index].size); | 25 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou
rce), kPrivateScriptSources[index].size); |
26 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source)
, isolate); | 26 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source)
, isolate); |
27 } | 27 } |
28 | 28 |
29 v8::Handle<v8::Value> PrivateScriptRunner::run(ScriptState* scriptState, String
className, String functionName, v8::Handle<v8::Value> receiver, int argc, v8::Ha
ndle<v8::Value> argv[]) | 29 static v8::Handle<v8::Value> propertyValue(ScriptState* scriptState, String clas
sName, String propertyName) |
30 { | 30 { |
31 ASSERT(scriptState->perContextData()); | 31 ASSERT(scriptState->perContextData()); |
32 ASSERT(scriptState->executionContext()); | 32 ASSERT(scriptState->executionContext()); |
33 v8::Isolate* isolate = scriptState->isolate(); | 33 v8::Isolate* isolate = scriptState->isolate(); |
34 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile
dPrivateScript(className); | 34 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile
dPrivateScript(className); |
35 if (compiledClass.IsEmpty()) { | 35 if (compiledClass.IsEmpty()) { |
36 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()->
compiledPrivateScript("PrivateScriptRunner"); | 36 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()->
compiledPrivateScript("PrivateScriptRunner"); |
37 if (installedClasses.IsEmpty()) { | 37 if (installedClasses.IsEmpty()) { |
38 installedClasses = compilePrivateScript(isolate, "PrivateScriptRunne
r"); | 38 installedClasses = compilePrivateScript(isolate, "PrivateScriptRunne
r"); |
39 scriptState->perContextData()->setCompiledPrivateScript("PrivateScri
ptRunner", installedClasses); | 39 scriptState->perContextData()->setCompiledPrivateScript("PrivateScri
ptRunner", installedClasses); |
40 } | 40 } |
41 RELEASE_ASSERT(!installedClasses.IsEmpty()); | 41 RELEASE_ASSERT(!installedClasses.IsEmpty()); |
42 RELEASE_ASSERT(installedClasses->IsObject()); | 42 RELEASE_ASSERT(installedClasses->IsObject()); |
43 | 43 |
44 compilePrivateScript(isolate, className); | 44 compilePrivateScript(isolate, className); |
45 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St
ring(isolate, className)); | 45 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St
ring(isolate, className)); |
46 RELEASE_ASSERT(!compiledClass.IsEmpty()); | 46 RELEASE_ASSERT(!compiledClass.IsEmpty()); |
47 RELEASE_ASSERT(compiledClass->IsObject()); | 47 RELEASE_ASSERT(compiledClass->IsObject()); |
48 scriptState->perContextData()->setCompiledPrivateScript(className, compi
ledClass); | 48 scriptState->perContextData()->setCompiledPrivateScript(className, compi
ledClass); |
49 } | 49 } |
| 50 return v8::Handle<v8::Object>::Cast(compiledClass)->Get(v8String(isolate, pr
opertyName)); |
| 51 } |
50 | 52 |
51 v8::Handle<v8::Value> function = v8::Handle<v8::Object>::Cast(compiledClass)
->Get(v8String(isolate, functionName)); | 53 v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState
, String className, String operationName, v8::Handle<v8::Value> holder, int argc
, v8::Handle<v8::Value> argv[]) |
52 RELEASE_ASSERT(!function.IsEmpty()); | 54 { |
53 RELEASE_ASSERT(function->IsFunction()); | 55 v8::Handle<v8::Value> operation = propertyValue(scriptState, className, oper
ationName); |
54 | 56 RELEASE_ASSERT(!operation.IsEmpty()); |
55 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(function)
, scriptState->executionContext(), receiver, argc, argv, isolate); | 57 RELEASE_ASSERT(operation->IsFunction()); |
| 58 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(operation
), scriptState->executionContext(), holder, argc, argv, scriptState->isolate()); |
56 } | 59 } |
57 | 60 |
58 } // namespace WebCore | 61 } // namespace WebCore |
OLD | NEW |