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

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

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