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

Unified Diff: Source/bindings/v8/ScriptController.cpp

Issue 13575004: Apply script preprocessor to Web page scripts only. (Closed) Base URL: https://chromium.googlesource.com/external/WebKit_trimmed.git@master
Patch Set: respond to haraken comment #35 Created 7 years, 5 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: Source/bindings/v8/ScriptController.cpp
diff --git a/Source/bindings/v8/ScriptController.cpp b/Source/bindings/v8/ScriptController.cpp
index 2af23acf31070007d73d28b16445f2ec849cb717..2fcd742daaeb41fe083a667581270f13709e1a29 100644
--- a/Source/bindings/v8/ScriptController.cpp
+++ b/Source/bindings/v8/ScriptController.cpp
@@ -38,6 +38,7 @@
#include "bindings/v8/BindingSecurity.h"
#include "bindings/v8/NPV8Object.h"
#include "bindings/v8/ScriptCallStackFactory.h"
+#include "bindings/v8/ScriptPreprocessor.h"
#include "bindings/v8/ScriptSourceCode.h"
#include "bindings/v8/ScriptValue.h"
#include "bindings/v8/V8Binding.h"
@@ -515,6 +516,7 @@ void ScriptController::clearWindowShell()
for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_isolatedWorlds.end(); ++iter)
iter->value->clearForNavigation();
V8GCController::hintForCollectGarbage();
+ clearScriptPreprocessor();
HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindowShell", (currentTime() - start) * 1000, 0, 10000, 50);
}
@@ -646,7 +648,7 @@ bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url)
if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangePending())
return true;
-
+
// DocumentWriter::replaceDocument can cause the DocumentLoader to get deref'ed and possible destroyed,
// so protect it with a RefPtr.
if (RefPtr<DocumentLoader> loader = m_frame->document()->loader())
@@ -665,9 +667,12 @@ ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s
if (v8Context.IsEmpty())
return ScriptValue();
+ String processedString = preprocess(sourceCode.source(), sourceURL);
+ ScriptSourceCode processedSourceCode(processedString, sourceCode.url(), sourceCode.startPosition());
+
v8::Context::Scope scope(v8Context);
RefPtr<Frame> protect(m_frame);
- v8::Local<v8::Value> object = compileAndRunScript(sourceCode);
+ v8::Local<v8::Value> object = compileAndRunScript(processedSourceCode);
m_sourceURL = savedSourceURL;
@@ -711,4 +716,39 @@ void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
}
}
+void ScriptController::setScriptPreprocessor(const String& preprocessorBody)
+{
+ // We delay the creation of the preprocess until just before the first JS from the
+ // Web page to ensure that the debugger's console initialization code has completed.
+ m_preprocessorSource = preprocessorBody;
+}
+
+void ScriptController::clearScriptPreprocessor()
+{
+ m_scriptPreprocessor.clear();
+ m_preprocessorSource = String();
+}
+
+// Source to Source processing iff debugger enabled and it has loaded a preprocessor.
+String ScriptController::preprocess(const String& scriptSource, const String& scriptName)
haraken 2013/07/12 00:13:19 Just to confirm: preprocess() does nothing when a
abarth-chromium 2013/07/12 00:25:16 Yeah, m_preprocessorSource will be null.
+{
+ if (m_preprocessorSource.isEmpty())
+ return scriptSource;
+
+ if (!m_frame->page())
+ return scriptSource;
+
+ if (!m_scriptPreprocessor)
+ m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(m_preprocessorSource, this, m_frame->page()->console()));
+
+ return m_scriptPreprocessor->preprocessSourceCode(scriptSource, scriptName);
+}
+
+void ScriptController::preprocessEval(ScriptDebugServer* debugServer, v8::Handle<v8::Object> eventData)
+{
+ if (!m_scriptPreprocessor.get())
+ return;
+ m_scriptPreprocessor->preprocessEval(debugServer, eventData);
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698