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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp

Issue 2695713015: WIP: Reland CompiledScript, prototype compiling in a separate task.
Patch Set: allow compile to fail, disallow restreaming (hack) Created 3 years, 9 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
Index: third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp
index 130ecb68c3a0089f925b54f7e04be113803ff126..7bf42cbdd8387a15fb4689634a07e799fee57b98 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp
@@ -32,6 +32,7 @@
#include "bindings/core/v8/ScriptController.h"
+#include "bindings/core/v8/CompiledScript.h"
#include "bindings/core/v8/ScriptSourceCode.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/V8Binding.h"
@@ -157,6 +158,67 @@ v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(
return result;
}
+CompiledScript* ScriptController::compileScriptInMainWorld(
+ const ScriptSourceCode& source,
+ AccessControlStatus accessControlStatus) {
+ V8CacheOptions v8CacheOptions =
+ cacheOptions(source.resource(), frame()->settings());
+
+ v8::HandleScope handleScope(isolate());
+ v8::TryCatch tryCatch(isolate());
+ tryCatch.SetVerbose(true);
+
+ v8::Local<v8::Script> script;
+ if (!v8Call(V8ScriptRunner::compileScript(
+ source, isolate(), accessControlStatus, v8CacheOptions),
+ script, tryCatch)) {
+ return nullptr;
+ }
+
+ TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
+ "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
+ InspectorUpdateCountersEvent::data());
+ DCHECK_EQ(currentExecutionContext(isolate()), frame()->document());
+ return new CompiledScript(frame()->document(), script, source);
+}
+
+void ScriptController::executeScriptInMainWorld(
+ const CompiledScript& compiledScript) {
+ Document* document = frame()->document();
+
+ TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data",
+ InspectorEvaluateScriptEvent::data(
+ frame(), compiledScript.url().getString(),
+ compiledScript.startPosition()));
+
+ v8::HandleScope handleScope(isolate());
+ ScriptState::Scope scope(ScriptState::forMainWorld(frame()));
+ v8::TryCatch tryCatch(isolate());
+ tryCatch.SetVerbose(true);
+
+ v8::Local<v8::Script> script = compiledScript.getScript(document);
+ if (script.IsEmpty()) {
+ CHECK(false) << "Don't do this for now";
+ // TODO(jbroman): accessControlStatus
+ AccessControlStatus accessControlStatus = NotSharableCrossOrigin;
+ CompiledScript* recompiledScript = compileScriptInMainWorld(
+ compiledScript.sourceCode(), accessControlStatus);
+ // TODO(jbroman): is this so?
+ DCHECK(recompiledScript);
+ script = recompiledScript->getScript(document);
+ }
+
+ DCHECK(!script.IsEmpty());
+ v8::Local<v8::Value> result;
+ if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, document),
+ result, tryCatch))
+ return;
+
+ TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
+ "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
+ InspectorUpdateCountersEvent::data());
+}
+
LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) {
LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world);
windowProxy->initializeIfNeeded();

Powered by Google App Engine
This is Rietveld 408576698