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

Unified Diff: Source/bindings/core/v8/PrivateScriptRunner.cpp

Issue 454773002: Blink-in-JS: Support private scripts in partial interfaces (PrivateScriptRunner part) (Closed) 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/core/idl.gypi ('k') | Source/bindings/core/v8/PrivateScriptRunner.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« 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