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

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

Issue 569063002: Reland [blink-in-js] Migrate resources required for blink-in-js to grd - part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased patch Created 6 years, 3 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
« no previous file with comments | « no previous file | Source/build/scripts/make_private_script_source.py » ('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 #include "platform/PlatformResourceLoader.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 static void dumpV8Message(v8::Handle<v8::Message> message) 22 static void dumpV8Message(v8::Handle<v8::Message> message)
22 { 23 {
23 if (message.IsEmpty()) 24 if (message.IsEmpty())
24 return; 25 return;
25 26
26 // FIXME: GetScriptOrigin() and GetLineNumber() return empty handles 27 // FIXME: GetScriptOrigin() and GetLineNumber() return empty handles
27 // when they are called at the first time if V8 has a pending exception. 28 // when they are called at the first time if V8 has a pending exception.
28 // So we need to call twice to get a correct ScriptOrigin and line number. 29 // So we need to call twice to get a correct ScriptOrigin and line number.
29 // This is a bug of V8. 30 // This is a bug of V8.
30 message->GetScriptOrigin(); 31 message->GetScriptOrigin();
31 message->GetLineNumber(); 32 message->GetLineNumber();
32 33
33 v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName (); 34 v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName ();
34 String fileName = "Unknown JavaScript file"; 35 String fileName = "Unknown JavaScript file";
35 if (!resourceName.IsEmpty() && resourceName->IsString()) 36 if (!resourceName.IsEmpty() && resourceName->IsString())
36 fileName = toCoreString(v8::Handle<v8::String>::Cast(resourceName)); 37 fileName = toCoreString(v8::Handle<v8::String>::Cast(resourceName));
37 int lineNumber = message->GetLineNumber(); 38 int lineNumber = message->GetLineNumber();
38 v8::Handle<v8::String> errorMessage = message->Get(); 39 v8::Handle<v8::String> errorMessage = message->Get();
39 fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, to CoreString(errorMessage).utf8().data()); 40 fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, to CoreString(errorMessage).utf8().data());
40 } 41 }
41 42
42 static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, St ring scriptClassName, const unsigned char* source, size_t size) 43 static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, St ring scriptClassName, const char* source, size_t size)
43 { 44 {
44 v8::TryCatch block; 45 v8::TryCatch block;
45 String sourceString(reinterpret_cast<const char*>(source), size); 46 String sourceString(source, size);
46 String fileName = scriptClassName + ".js"; 47 String fileName = scriptClassName + ".js";
47 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isola te, sourceString), fileName, TextPosition::minimumPosition(), 0, isolate, NotSha rableCrossOrigin, V8CacheOptionsOff); 48 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isola te, sourceString), fileName, TextPosition::minimumPosition(), 0, isolate, NotSha rableCrossOrigin, V8CacheOptionsOff);
48 if (block.HasCaught()) { 49 if (block.HasCaught()) {
49 fprintf(stderr, "Private script error: Compile failed. (Class name = %s) \n", scriptClassName.utf8().data()); 50 fprintf(stderr, "Private script error: Compile failed. (Class name = %s) \n", scriptClassName.utf8().data());
50 dumpV8Message(block.Message()); 51 dumpV8Message(block.Message());
51 RELEASE_ASSERT_NOT_REACHED(); 52 RELEASE_ASSERT_NOT_REACHED();
52 } 53 }
53 54
54 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledInternalScript(scr ipt, isolate); 55 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledInternalScript(scr ipt, isolate);
55 if (block.HasCaught()) { 56 if (block.HasCaught()) {
(...skipping 19 matching lines...) Expand all
75 compileAndRunPrivateScript(isolate, kPrivateScriptSourcesForTesting[ index].scriptClassName, kPrivateScriptSourcesForTesting[index].source, kPrivateS criptSourcesForTesting[index].size); 76 compileAndRunPrivateScript(isolate, kPrivateScriptSourcesForTesting[ index].scriptClassName, kPrivateScriptSourcesForTesting[index].source, kPrivateS criptSourcesForTesting[index].size);
76 compiledScriptCount++; 77 compiledScriptCount++;
77 } 78 }
78 } 79 }
79 #endif 80 #endif
80 81
81 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated 82 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
82 // by make_private_script_source.py. 83 // by make_private_script_source.py.
83 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); inde x++) { 84 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); inde x++) {
84 if (className == kPrivateScriptSources[index].className) { 85 if (className == kPrivateScriptSources[index].className) {
85 compileAndRunPrivateScript(isolate, kPrivateScriptSources[index].scr iptClassName, kPrivateScriptSources[index].source, kPrivateScriptSources[index]. size); 86 String resourceData = loadResourceAsASCIIString(kPrivateScriptSource s[index].resourceFile);
87 compileAndRunPrivateScript(isolate, kPrivateScriptSources[index].scr iptClassName, resourceData.utf8().data(), resourceData.length());
86 compiledScriptCount++; 88 compiledScriptCount++;
87 } 89 }
88 } 90 }
89 91
90 if (!compiledScriptCount) { 92 if (!compiledScriptCount) {
91 fprintf(stderr, "Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data()); 93 fprintf(stderr, "Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data());
92 RELEASE_ASSERT_NOT_REACHED(); 94 RELEASE_ASSERT_NOT_REACHED();
93 } 95 }
94 } 96 }
95 97
96 static v8::Handle<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate) 98 static v8::Handle<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate)
97 { 99 {
98 const String className = "PrivateScriptRunner"; 100 const String className = "PrivateScriptRunner";
99 size_t index; 101 size_t index;
100 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated 102 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
101 // by make_private_script_source.py. 103 // by make_private_script_source.py.
102 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { 104 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
103 if (className == kPrivateScriptSources[index].className) 105 if (className == kPrivateScriptSources[index].className)
104 break; 106 break;
105 } 107 }
106 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) { 108 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) {
107 fprintf(stderr, "Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data()); 109 fprintf(stderr, "Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data());
108 RELEASE_ASSERT_NOT_REACHED(); 110 RELEASE_ASSERT_NOT_REACHED();
109 } 111 }
110 return compileAndRunPrivateScript(isolate, className, kPrivateScriptSources[ index].source, kPrivateScriptSources[index].size); 112 String resourceData = loadResourceAsASCIIString(kPrivateScriptSources[index] .resourceFile);
113 return compileAndRunPrivateScript(isolate, className, resourceData.utf8().da ta(), resourceData.length());
111 } 114 }
112 115
113 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className) 116 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className)
114 { 117 {
115 ASSERT(scriptState->perContextData()); 118 ASSERT(scriptState->perContextData());
116 ASSERT(scriptState->executionContext()); 119 ASSERT(scriptState->executionContext());
117 v8::Isolate* isolate = scriptState->isolate(); 120 v8::Isolate* isolate = scriptState->isolate();
118 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className); 121 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className);
119 if (compiledClass.IsEmpty()) { 122 if (compiledClass.IsEmpty()) {
120 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner"); 123 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner");
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 exceptionState.throwIfNeeded(); 266 exceptionState.throwIfNeeded();
264 return; 267 return;
265 } 268 }
266 269
267 fprintf(stderr, "Private script error: %s was thrown.\n", exceptionName.utf8 ().data()); 270 fprintf(stderr, "Private script error: %s was thrown.\n", exceptionName.utf8 ().data());
268 dumpV8Message(tryCatchMessage); 271 dumpV8Message(tryCatchMessage);
269 RELEASE_ASSERT_NOT_REACHED(); 272 RELEASE_ASSERT_NOT_REACHED();
270 } 273 }
271 274
272 } // namespace blink 275 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/build/scripts/make_private_script_source.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698