| 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/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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 static void dumpJSError(String exceptionName, v8::Handle<v8::Message> message) | 37 static void dumpJSError(String exceptionName, v8::Handle<v8::Message> message) |
| 38 { | 38 { |
| 39 // FIXME: Set a ScriptOrigin of the private script and print a more informat
ive message. | 39 // FIXME: Set a ScriptOrigin of the private script and print a more informat
ive message. |
| 40 #ifndef NDEBUG | 40 #ifndef NDEBUG |
| 41 fprintf(stderr, "Private script throws an exception: %s\n", exceptionName.ut
f8().data()); | 41 fprintf(stderr, "Private script throws an exception: %s\n", exceptionName.ut
f8().data()); |
| 42 dumpV8Message(message); | 42 dumpV8Message(message); |
| 43 #endif | 43 #endif |
| 44 } | 44 } |
| 45 | 45 |
| 46 static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, St
ring className, const unsigned char* source, size_t size) | 46 static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, St
ring scriptClassName, const unsigned char* source, size_t size) |
| 47 { | 47 { |
| 48 v8::TryCatch block; | 48 v8::TryCatch block; |
| 49 String sourceString(reinterpret_cast<const char*>(source), size); | 49 String sourceString(reinterpret_cast<const char*>(source), size); |
| 50 String fileName = className + ".js"; | 50 String fileName = scriptClassName + ".js"; |
| 51 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isola
te, sourceString), fileName, TextPosition::minimumPosition(), 0, isolate, NotSha
rableCrossOrigin, V8CacheOptionsOff); | 51 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isola
te, sourceString), fileName, TextPosition::minimumPosition(), 0, isolate, NotSha
rableCrossOrigin, V8CacheOptionsOff); |
| 52 if (block.HasCaught()) { | 52 if (block.HasCaught()) { |
| 53 fprintf(stderr, "Private script error: Compile failed. (Class name = %s)
\n", className.utf8().data()); | 53 fprintf(stderr, "Private script error: Compile failed. (Class name = %s)
\n", scriptClassName.utf8().data()); |
| 54 dumpV8Message(block.Message()); | 54 dumpV8Message(block.Message()); |
| 55 RELEASE_ASSERT_NOT_REACHED(); | 55 RELEASE_ASSERT_NOT_REACHED(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledInternalScript(scr
ipt, isolate); | 58 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledInternalScript(scr
ipt, isolate); |
| 59 if (block.HasCaught()) { | 59 if (block.HasCaught()) { |
| 60 fprintf(stderr, "Private script error: installClass() failed. (Class nam
e = %s)\n", className.utf8().data()); | 60 fprintf(stderr, "Private script error: installClass() failed. (Class nam
e = %s)\n", scriptClassName.utf8().data()); |
| 61 dumpV8Message(block.Message()); | 61 dumpV8Message(block.Message()); |
| 62 RELEASE_ASSERT_NOT_REACHED(); | 62 RELEASE_ASSERT_NOT_REACHED(); |
| 63 } | 63 } |
| 64 return result; | 64 return result; |
| 65 } | 65 } |
| 66 | 66 |
| 67 // FIXME: If we have X.js, XPartial-1.js and XPartial-2.js, currently all of the
JS files | 67 // FIXME: If we have X.js, XPartial-1.js and XPartial-2.js, currently all of the
JS files |
| 68 // are compiled when any of the JS files is requested. Ideally we should avoid c
ompiling | 68 // are compiled when any of the JS files is requested. Ideally we should avoid c
ompiling |
| 69 // unrelated JS files. For example, if a method in XPartial-1.js is requested, w
e just | 69 // unrelated JS files. For example, if a method in XPartial-1.js is requested, w
e just |
| 70 // need to compile X.js and XPartial-1.js, and don't need to compile XPartial-2.
js. | 70 // need to compile X.js and XPartial-1.js, and don't need to compile XPartial-2.
js. |
| 71 static void installPrivateScript(v8::Isolate* isolate, String dependencyClassNam
e) | 71 static void installPrivateScript(v8::Isolate* isolate, String className) |
| 72 { | 72 { |
| 73 int compiledScriptCount = 0; | 73 int compiledScriptCount = 0; |
| 74 // |kPrivateScriptSourcesForTesting| is defined in V8PrivateScriptSources.h,
which is auto-generated | 74 // |kPrivateScriptSourcesForTesting| is defined in V8PrivateScriptSources.h,
which is auto-generated |
| 75 // by make_private_script_source.py. | 75 // by make_private_script_source.py. |
| 76 #ifndef NDEBUG | 76 #ifndef NDEBUG |
| 77 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTest
ing); index++) { | 77 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTest
ing); index++) { |
| 78 if (dependencyClassName == kPrivateScriptSourcesForTesting[index].depend
encyClassName) { | 78 if (className == kPrivateScriptSourcesForTesting[index].className) { |
| 79 compileAndRunPrivateScript(isolate, kPrivateScriptSourcesForTesting[
index].className, kPrivateScriptSourcesForTesting[index].source, kPrivateScriptS
ourcesForTesting[index].size); | 79 compileAndRunPrivateScript(isolate, kPrivateScriptSourcesForTesting[
index].scriptClassName, kPrivateScriptSourcesForTesting[index].source, kPrivateS
criptSourcesForTesting[index].size); |
| 80 compiledScriptCount++; | 80 compiledScriptCount++; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 #endif | 83 #endif |
| 84 | 84 |
| 85 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is
auto-generated | 85 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is
auto-generated |
| 86 // by make_private_script_source.py. | 86 // by make_private_script_source.py. |
| 87 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); inde
x++) { | 87 for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); inde
x++) { |
| 88 if (dependencyClassName == kPrivateScriptSources[index].dependencyClassN
ame) { | 88 if (className == kPrivateScriptSources[index].className) { |
| 89 compileAndRunPrivateScript(isolate, kPrivateScriptSources[index].cla
ssName, kPrivateScriptSources[index].source, kPrivateScriptSources[index].size); | 89 compileAndRunPrivateScript(isolate, kPrivateScriptSources[index].scr
iptClassName, kPrivateScriptSources[index].source, kPrivateScriptSources[index].
size); |
| 90 compiledScriptCount++; | 90 compiledScriptCount++; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 if (!compiledScriptCount) { | 94 if (!compiledScriptCount) { |
| 95 fprintf(stderr, "Private script error: Target source code was not found.
(Class name = %s)\n", dependencyClassName.utf8().data()); | 95 fprintf(stderr, "Private script error: Target source code was not found.
(Class name = %s)\n", className.utf8().data()); |
| 96 RELEASE_ASSERT_NOT_REACHED(); | 96 RELEASE_ASSERT_NOT_REACHED(); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 static v8::Handle<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate) | 100 static v8::Handle<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate) |
| 101 { | 101 { |
| 102 const String className = "PrivateScriptRunner"; | 102 const String className = "PrivateScriptRunner"; |
| 103 size_t index; | 103 size_t index; |
| 104 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is
auto-generated | 104 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is
auto-generated |
| 105 // by make_private_script_source.py. | 105 // by make_private_script_source.py. |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (exceptionName == "ReferenceError") { | 286 if (exceptionName == "ReferenceError") { |
| 287 exceptionState.throwDOMException(V8ReferenceError, messageString); | 287 exceptionState.throwDOMException(V8ReferenceError, messageString); |
| 288 exceptionState.throwIfNeeded(); | 288 exceptionState.throwIfNeeded(); |
| 289 dumpJSError(exceptionName, tryCatchMessage); | 289 dumpJSError(exceptionName, tryCatchMessage); |
| 290 return true; | 290 return true; |
| 291 } | 291 } |
| 292 return false; | 292 return false; |
| 293 } | 293 } |
| 294 | 294 |
| 295 } // namespace blink | 295 } // namespace blink |
| OLD | NEW |