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

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 25ab765d450d4595d088671842d32cee4806f3d7..1b44e9369b1a352adff5e9634fb3a5bab5779957 100644
--- a/Source/bindings/core/v8/PrivateScriptRunner.cpp
+++ b/Source/bindings/core/v8/PrivateScriptRunner.cpp
@@ -20,41 +20,68 @@ namespace blink {
#define LOG_ERROR_ALWAYS(...) WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, __VA_ARGS__)
-static v8::Handle<v8::Value> compilePrivateScript(v8::Isolate* isolate, String className)
+static v8::Handle<v8::Value> compileAndRunInternalScript(v8::Isolate* isolate, String className, const unsigned char* source, size_t size)
{
- size_t index;
-#ifndef NDEBUG
- for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTesting); index++) {
- if (className == kPrivateScriptSourcesForTesting[index].name)
- break;
+ v8::TryCatch block;
+ String sourceString(reinterpret_cast<const char*>(source), size);
+ v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, sourceString), isolate);
+ if (block.HasCaught()) {
+ LOG_ERROR_ALWAYS("Private script error: Compile failed. (Class name = %s)\n", className.utf8().data());
+ if (!block.Message().IsEmpty())
+ LOG_ERROR_ALWAYS("%s\n", toCoreString(block.Message()->Get()).utf8().data());
+ RELEASE_ASSERT_NOT_REACHED();
}
- 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);
+ return result;
+}
+
+// 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)
+{
+ int compiledScriptCount = 0;
+ // |kPrivateScriptSourcesForTesting| is defined in V8PrivateScriptSources.h, which is auto-generated
+ // by make_private_script_source.py.
+#ifndef NDEBUG
+ for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSourcesForTesting); index++) {
+ if (className == kPrivateScriptSourcesForTesting[index].dependencyClassName) {
+ compileAndRunInternalScript(isolate, className, kPrivateScriptSourcesForTesting[index].source, kPrivateScriptSourcesForTesting[index].size);
+ compiledScriptCount++;
+ }
}
#endif
// |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)
- break;
+ // by make_private_script_source.py.
+ for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
+ if (className == kPrivateScriptSources[index].dependencyClassName) {
+ compileAndRunInternalScript(isolate, className, kPrivateScriptSources[index].source, kPrivateScriptSources[index].size);
+ compiledScriptCount++;
+ }
}
- if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) {
+
+ if (!compiledScriptCount) {
LOG_ERROR_ALWAYS("Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data());
RELEASE_ASSERT_NOT_REACHED();
}
+}
- v8::TryCatch block;
- String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].source), kPrivateScriptSources[index].size);
- v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source), isolate);
- if (block.HasCaught()) {
- LOG_ERROR_ALWAYS("Private script error: Compile failed. (Class name = %s)\n", className.utf8().data());
- if (!block.Message().IsEmpty())
- LOG_ERROR_ALWAYS("%s\n", toCoreString(block.Message()->Get()).utf8().data());
+static v8::Handle<v8::Value> compilePrivateScriptRunner(v8::Isolate* isolate)
+{
+ const String className = "PrivateScriptRunner";
+ size_t index;
+ // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
+ // by make_private_script_source.py.
+ for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
+ if (className == kPrivateScriptSources[index].className)
+ break;
+ }
+ if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) {
+ LOG_ERROR_ALWAYS("Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data());
RELEASE_ASSERT_NOT_REACHED();
}
- return result;
+ return compileAndRunInternalScript(isolate, className, kPrivateScriptSources[index].source, kPrivateScriptSources[index].size);
}
static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptState, String className)
@@ -66,7 +93,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