Chromium Code Reviews| Index: Source/bindings/core/v8/PrivateScriptRunner.cpp |
| diff --git a/Source/bindings/core/v8/PrivateScriptRunner.cpp b/Source/bindings/core/v8/PrivateScriptRunner.cpp |
| index ff3a7bb32030cb2abad66cb4e5c4c3f7fb1538a8..edc62cbe4db38c2b1d0c9772f9417c2d82beaaaa 100644 |
| --- a/Source/bindings/core/v8/PrivateScriptRunner.cpp |
| +++ b/Source/bindings/core/v8/PrivateScriptRunner.cpp |
| @@ -18,24 +18,61 @@ |
| namespace blink { |
| -static v8::Handle<v8::Value> compilePrivateScript(v8::Isolate* isolate, String className) |
| +// FIXME: If we have X.js, XPartial-1.js and XPartial-2.js, currently all of the JS files |
| +// are compiled when any of the JS files is requested. Ideally we should avoid compiling |
| +// unrelated JS files. For example, if a method in XPartial-1.js is requested, we just |
| +// need to compile X.js and XPartial-1.js, and don't need to compile XPartial-2.js. |
| +static void compilePrivateScript(v8::Isolate* isolate, String className) |
| { |
| - size_t index; |
| + int compiledScriptCount = 0; |
| + // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated |
| + // by make_private_script.py. |
| #ifndef NDEBUG |
| - for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTesting); index++) { |
| - if (className == kPrivateScriptSourcesForTesting[index].name) |
| - break; |
| - } |
| - if (index != WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTesting)) { |
| - String source(reinterpret_cast<const char*>(kPrivateScriptSourcesForTesting[index].source), kPrivateScriptSourcesForTesting[index].size); |
| - return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source), isolate); |
| + for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTesting); index++) { |
| + if (className == kPrivateScriptSourcesForTesting[index].dependencyClassName) { |
| + v8::TryCatch block; |
|
Jens Widell
2014/08/09 14:52:25
We could unduplicate some code here; this block is
haraken
2014/08/11 01:18:30
Removed the duplication.
|
| + String source(reinterpret_cast<const char*>(kPrivateScriptSourcesForTesting[index].source), kPrivateScriptSourcesForTesting[index].size); |
| + V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source), isolate); |
| + if (block.HasCaught()) { |
| + WTF_LOG_ERROR("Private script error: Compile failed. (Class name = %s)\n", className.utf8().data()); |
| + if (!block.Message().IsEmpty()) |
| + WTF_LOG_ERROR("%s\n", toCoreString(block.Message()->Get()).utf8().data()); |
| + RELEASE_ASSERT_NOT_REACHED(); |
| + } |
| + compiledScriptCount++; |
| + } |
| } |
| #endif |
| + for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { |
| + if (className == kPrivateScriptSources[index].dependencyClassName) { |
| + v8::TryCatch block; |
| + String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].source), kPrivateScriptSources[index].size); |
| + V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source), isolate); |
| + if (block.HasCaught()) { |
| + WTF_LOG_ERROR("Private script error: Compile failed. (Class name = %s)\n", className.utf8().data()); |
| + if (!block.Message().IsEmpty()) |
| + WTF_LOG_ERROR("%s\n", toCoreString(block.Message()->Get()).utf8().data()); |
| + RELEASE_ASSERT_NOT_REACHED(); |
| + } |
| + compiledScriptCount++; |
| + } |
| + } |
| + |
| + if (!compiledScriptCount) { |
| + WTF_LOG_ERROR("Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data()); |
| + RELEASE_ASSERT_NOT_REACHED(); |
| + } |
| +} |
| + |
| +static v8::Handle<v8::Value> compilePrivateScriptRunner(v8::Isolate* isolate) |
| +{ |
| + String className = "PrivateScriptRunner"; |
| + size_t index; |
| // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated |
| // by make_private_script.py. |
| for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { |
| - if (className == kPrivateScriptSources[index].name) |
| + if (className == kPrivateScriptSources[index].className) |
| break; |
| } |
| if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) { |
| @@ -64,7 +101,7 @@ static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat |
| if (compiledClass.IsEmpty()) { |
| v8::Handle<v8::Value> installedClasses = scriptState->perContextData()->compiledPrivateScript("PrivateScriptRunner"); |
| if (installedClasses.IsEmpty()) { |
| - installedClasses = compilePrivateScript(isolate, "PrivateScriptRunner"); |
| + installedClasses = compilePrivateScriptRunner(isolate); |
| scriptState->perContextData()->setCompiledPrivateScript("PrivateScriptRunner", installedClasses); |
| } |
| RELEASE_ASSERT(!installedClasses.IsEmpty()); |