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

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

Issue 2564903002: ScriptController: Expose methods to compile a script and execute a compiled script. (Closed)
Patch Set: Created 4 years 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 d6d58c058eb92b026696323618b1204c090df3ac..a8ab942a5d98d7afe42822de60cf834b67e032c0 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"
@@ -93,6 +94,32 @@ void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) {
m_windowProxyManager->updateSecurityOrigin(securityOrigin);
}
+namespace {
+
+V8CacheOptions cacheOptions(const ScriptResource* resource,
+ const Settings* settings) {
+ V8CacheOptions v8CacheOptions(V8CacheOptionsDefault);
+ if (settings)
+ v8CacheOptions = settings->v8CacheOptions();
+ if (resource && !resource->response().cacheStorageCacheName().isNull()) {
+ switch (settings->v8CacheStrategiesForCacheStorage()) {
+ case V8CacheStrategiesForCacheStorage::None:
+ v8CacheOptions = V8CacheOptionsNone;
+ break;
+ case V8CacheStrategiesForCacheStorage::Normal:
+ v8CacheOptions = V8CacheOptionsCode;
+ break;
+ case V8CacheStrategiesForCacheStorage::Default:
+ case V8CacheStrategiesForCacheStorage::Aggressive:
+ v8CacheOptions = V8CacheOptionsAlways;
+ break;
+ }
+ }
+ return v8CacheOptions;
+}
+
+} // namespace
+
v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(
v8::Local<v8::Context> context,
const ScriptSourceCode& source,
@@ -105,24 +132,8 @@ v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(
v8::Local<v8::Value> result;
{
- V8CacheOptions v8CacheOptions(V8CacheOptionsDefault);
- if (frame()->settings())
- v8CacheOptions = frame()->settings()->v8CacheOptions();
- if (source.resource() &&
- !source.resource()->response().cacheStorageCacheName().isNull()) {
- switch (frame()->settings()->v8CacheStrategiesForCacheStorage()) {
- case V8CacheStrategiesForCacheStorage::None:
- v8CacheOptions = V8CacheOptionsNone;
- break;
- case V8CacheStrategiesForCacheStorage::Normal:
- v8CacheOptions = V8CacheOptionsCode;
- break;
- case V8CacheStrategiesForCacheStorage::Default:
- case V8CacheStrategiesForCacheStorage::Aggressive:
- v8CacheOptions = V8CacheOptionsAlways;
- break;
- }
- }
+ V8CacheOptions v8CacheOptions =
+ cacheOptions(source.resource(), frame()->settings());
// Isolate exceptions that occur when compiling and executing
// the code. These exceptions should not interfere with
@@ -150,6 +161,54 @@ 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());
+ return new CompiledScript(isolate(), script, source);
+}
+
+void ScriptController::executeScriptInMainWorld(
+ const CompiledScript& compiledScript) {
+ TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data",
+ InspectorEvaluateScriptEvent::data(
+ frame(), compiledScript.url().getString(),
+ compiledScript.startPosition()));
haraken 2016/12/12 00:53:57 Shall we introduce two trace events: "CompileScrip
jbroman 2016/12/13 15:53:21 I'm not opposed in principle, but these string con
+ InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(
+ frame()->document(), "scriptFirstStatement", false);
+
+ v8::HandleScope handleScope(isolate());
+ v8::TryCatch tryCatch(isolate());
+ tryCatch.SetVerbose(true);
+
+ v8::Local<v8::Value> result;
+ if (!v8Call(
+ V8ScriptRunner::runCompiledScript(
+ isolate(), compiledScript.script(isolate()), frame()->document()),
+ result, tryCatch))
+ return;
+
+ TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
+ "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
+ InspectorUpdateCountersEvent::data());
haraken 2016/12/12 00:53:57 I don't fully understand this trace event. Is it e
jbroman 2016/12/13 15:53:21 From what I can tell, it makes a note of the heap
+}
+
bool ScriptController::initializeMainWorld() {
if (m_windowProxyManager->mainWorldProxy()->isContextInitialized())
return false;

Powered by Google App Engine
This is Rietveld 408576698