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

Side by Side Diff: Source/bindings/core/v8/PrivateScriptRunner.cpp

Issue 457483002: Blink-in-JS: Support partial interfaces in private scripts Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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
« no previous file with comments | « Source/bindings/core/idl.gypi ('k') | Source/bindings/core/v8/PrivateScriptRunner.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/core/v8/PrivateScriptRunner.h" 6 #include "bindings/core/v8/PrivateScriptRunner.h"
7 7
8 #include "bindings/core/v8/DOMWrapperWorld.h" 8 #include "bindings/core/v8/DOMWrapperWorld.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
11 #include "bindings/core/v8/V8PerContextData.h" 11 #include "bindings/core/v8/V8PerContextData.h"
12 #include "bindings/core/v8/V8ScriptRunner.h" 12 #include "bindings/core/v8/V8ScriptRunner.h"
13 #include "core/PrivateScriptSources.h" 13 #include "core/PrivateScriptSources.h"
14 #ifndef NDEBUG 14 #ifndef NDEBUG
15 #include "core/PrivateScriptSourcesForTesting.h" 15 #include "core/PrivateScriptSourcesForTesting.h"
16 #endif 16 #endif
17 #include "core/dom/ExceptionCode.h" 17 #include "core/dom/ExceptionCode.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 static v8::Handle<v8::Value> compilePrivateScript(v8::Isolate* isolate, String c lassName) 21 static void compilePrivateScript(v8::Isolate* isolate, String className)
22 { 22 {
23 size_t index; 23 int compiledScriptCount = 0;
24 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
25 // by make_private_script.py.
24 #ifndef NDEBUG 26 #ifndef NDEBUG
25 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTesting); i ndex++) { 27 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTest ing); index++) {
26 if (className == kPrivateScriptSourcesForTesting[index].name) 28 if (className == kPrivateScriptSourcesForTesting[index].dependencyClassN ame) {
27 break; 29 v8::TryCatch block;
28 } 30 String source(reinterpret_cast<const char*>(kPrivateScriptSourcesFor Testing[index].source), kPrivateScriptSourcesForTesting[index].size);
29 if (index != WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTesting)) { 31 V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source ), isolate);
30 String source(reinterpret_cast<const char*>(kPrivateScriptSourcesForTest ing[index].source), kPrivateScriptSourcesForTesting[index].size); 32 if (block.HasCaught()) {
31 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, sou rce), isolate); 33 WTF_LOG_ERROR("Private script error: Compile failed. (Class name = %s)\n", className.utf8().data());
34 if (!block.Message().IsEmpty())
35 WTF_LOG_ERROR("%s\n", toCoreString(block.Message()->Get()).u tf8().data());
36 RELEASE_ASSERT_NOT_REACHED();
37 }
38 compiledScriptCount++;
39 }
32 } 40 }
33 #endif 41 #endif
34 42
43 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); inde x++) {
44 if (className == kPrivateScriptSources[index].dependencyClassName) {
45 v8::TryCatch block;
46 String source(reinterpret_cast<const char*>(kPrivateScriptSources[in dex].source), kPrivateScriptSources[index].size);
47 V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source ), isolate);
48 if (block.HasCaught()) {
49 WTF_LOG_ERROR("Private script error: Compile failed. (Class name = %s)\n", className.utf8().data());
50 if (!block.Message().IsEmpty())
51 WTF_LOG_ERROR("%s\n", toCoreString(block.Message()->Get()).u tf8().data());
52 RELEASE_ASSERT_NOT_REACHED();
53 }
54 compiledScriptCount++;
55 }
56 }
57
58 if (!compiledScriptCount) {
59 WTF_LOG_ERROR("Private script error: Target source code was not found. ( Class name = %s)\n", className.utf8().data());
60 RELEASE_ASSERT_NOT_REACHED();
61 }
62 }
63
64 static v8::Handle<v8::Value> compilePrivateScriptRunner(v8::Isolate* isolate, St ring className)
65 {
66 size_t index;
35 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated 67 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
36 // by make_private_script.py. 68 // by make_private_script.py.
37 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { 69 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
38 if (className == kPrivateScriptSources[index].name) 70 if (className == kPrivateScriptSources[index].className)
39 break; 71 break;
40 } 72 }
41 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) { 73 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) {
42 WTF_LOG_ERROR("Private script error: Target source code was not found. ( Class name = %s)\n", className.utf8().data()); 74 WTF_LOG_ERROR("Private script error: Target source code was not found. ( Class name = %s)\n", className.utf8().data());
43 RELEASE_ASSERT_NOT_REACHED(); 75 RELEASE_ASSERT_NOT_REACHED();
44 } 76 }
45 77
46 v8::TryCatch block; 78 v8::TryCatch block;
47 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size); 79 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size);
48 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(v 8String(isolate, source), isolate); 80 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(v 8String(isolate, source), isolate);
49 if (block.HasCaught()) { 81 if (block.HasCaught()) {
50 WTF_LOG_ERROR("Private script error: Compile failed. (Class name = %s)\n ", className.utf8().data()); 82 WTF_LOG_ERROR("Private script error: Compile failed. (Class name = %s)\n ", className.utf8().data());
51 if (!block.Message().IsEmpty()) 83 if (!block.Message().IsEmpty())
52 WTF_LOG_ERROR("%s\n", toCoreString(block.Message()->Get()).utf8().da ta()); 84 WTF_LOG_ERROR("%s\n", toCoreString(block.Message()->Get()).utf8().da ta());
53 RELEASE_ASSERT_NOT_REACHED(); 85 RELEASE_ASSERT_NOT_REACHED();
54 } 86 }
55 return result; 87 return result;
56 } 88 }
57 89
58 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className) 90 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className)
59 { 91 {
60 ASSERT(scriptState->perContextData()); 92 ASSERT(scriptState->perContextData());
61 ASSERT(scriptState->executionContext()); 93 ASSERT(scriptState->executionContext());
62 v8::Isolate* isolate = scriptState->isolate(); 94 v8::Isolate* isolate = scriptState->isolate();
63 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className); 95 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className);
64 if (compiledClass.IsEmpty()) { 96 if (compiledClass.IsEmpty()) {
65 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner"); 97 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner");
66 if (installedClasses.IsEmpty()) { 98 if (installedClasses.IsEmpty()) {
67 installedClasses = compilePrivateScript(isolate, "PrivateScriptRunne r"); 99 installedClasses = compilePrivateScriptRunner(isolate, "PrivateScrip tRunner");
68 scriptState->perContextData()->setCompiledPrivateScript("PrivateScri ptRunner", installedClasses); 100 scriptState->perContextData()->setCompiledPrivateScript("PrivateScri ptRunner", installedClasses);
69 } 101 }
70 RELEASE_ASSERT(!installedClasses.IsEmpty()); 102 RELEASE_ASSERT(!installedClasses.IsEmpty());
71 RELEASE_ASSERT(installedClasses->IsObject()); 103 RELEASE_ASSERT(installedClasses->IsObject());
72 104
73 compilePrivateScript(isolate, className); 105 compilePrivateScript(isolate, className);
74 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St ring(isolate, className)); 106 compiledClass = v8::Handle<v8::Object>::Cast(installedClasses)->Get(v8St ring(isolate, className));
75 RELEASE_ASSERT(!compiledClass.IsEmpty()); 107 RELEASE_ASSERT(!compiledClass.IsEmpty());
76 RELEASE_ASSERT(compiledClass->IsObject()); 108 RELEASE_ASSERT(compiledClass->IsObject());
77 scriptState->perContextData()->setCompiledPrivateScript(className, compi ledClass); 109 scriptState->perContextData()->setCompiledPrivateScript(className, compi ledClass);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, " message")); 259 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, " message"));
228 RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); 260 RELEASE_ASSERT(!message.IsEmpty() && message->IsString());
229 exceptionState.throwDOMException(V8ReferenceError, toCoreString(v8::Hand le<v8::String>::Cast(message))); 261 exceptionState.throwDOMException(V8ReferenceError, toCoreString(v8::Hand le<v8::String>::Cast(message)));
230 exceptionState.throwIfNeeded(); 262 exceptionState.throwIfNeeded();
231 return true; 263 return true;
232 } 264 }
233 return false; 265 return false;
234 } 266 }
235 267
236 } // namespace blink 268 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/idl.gypi ('k') | Source/bindings/core/v8/PrivateScriptRunner.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698