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

Unified Diff: Source/bindings/v8/ScriptDebugServer.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: Partial response to review Created 7 years, 6 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/ScriptDebugServer.cpp
diff --git a/Source/bindings/v8/ScriptDebugServer.cpp b/Source/bindings/v8/ScriptDebugServer.cpp
index 9a3ab63027c6d50fbc79e181d212746436f78d65..b9d571d5806a29f5e49ac012d6aa6a498017d41d 100644
--- a/Source/bindings/v8/ScriptDebugServer.cpp
+++ b/Source/bindings/v8/ScriptDebugServer.cpp
@@ -35,6 +35,7 @@
#include "DebuggerScriptSource.h"
#include "V8JavaScriptCallFrame.h"
#include "bindings/v8/ScopedPersistent.h"
+#include "bindings/v8/ScriptController.h"
#include "bindings/v8/ScriptObject.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/V8RecursionScope.h"
@@ -66,70 +67,6 @@ v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN
return V8ScriptRunner::callInternalFunction(function, v8::Context::GetCurrent(), m_debuggerScript.get(), argc, argv, m_isolate);
}
-class ScriptDebugServer::ScriptPreprocessor {
- WTF_MAKE_NONCOPYABLE(ScriptPreprocessor);
-public:
- ScriptPreprocessor(const String& preprocessorScript, v8::Isolate* isolate)
- : m_isolate(isolate)
- {
- v8::HandleScope scope(m_isolate);
-
- v8::Local<v8::Context> context = v8::Context::New(m_isolate);
- if (context.IsEmpty())
- return;
-
- String wrappedScript = "(" + preprocessorScript + ")";
- v8::Handle<v8::String> preprocessor = v8::String::New(wrappedScript.utf8().data(), wrappedScript.utf8().length());
-
- v8::Local<v8::Value> preprocessorFunction = V8ScriptRunner::compileAndRunInternalScript(preprocessor, m_isolate, context);
- if (preprocessorFunction.IsEmpty() || !preprocessorFunction->IsFunction())
- return;
-
- m_utilityContext.set(isolate, context);
- m_preprocessorFunction.set(isolate, v8::Handle<v8::Function>::Cast(preprocessorFunction));
- }
-
- String preprocessSourceCode(const String& sourceCode, const String& sourceName)
- {
- v8::HandleScope handleScope(m_isolate);
-
- if (m_preprocessorFunction.isEmpty())
- return sourceCode;
-
- v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_utilityContext.get());
- v8::Context::Scope contextScope(context);
-
- v8::Handle<v8::String> sourceCodeString = v8::String::New(sourceCode.utf8().data(), sourceCode.utf8().length());
-
- v8::Handle<v8::String> sourceNameString = v8::String::New(sourceName.utf8().data(), sourceName.utf8().length());
- v8::Handle<v8::Value> argv[] = { sourceCodeString, sourceNameString };
-
- v8::TryCatch tryCatch;
- V8RecursionScope::MicrotaskSuppression recursionScope;
- v8::Handle<v8::Value> resultValue = m_preprocessorFunction.newLocal(m_isolate)->Call(context->Global(), 2, argv);
-
- if (tryCatch.HasCaught())
- return sourceCode;
-
- if (resultValue->IsString()) {
- v8::String::Utf8Value utf8Value(resultValue);
- return String::fromUTF8(*utf8Value, utf8Value.length());
- }
-
- return sourceCode;
- }
-
- ~ScriptPreprocessor()
- {
- }
-
-private:
- ScopedPersistent<v8::Context> m_utilityContext;
- String m_preprocessorBody;
- ScopedPersistent<v8::Function> m_preprocessorFunction;
- v8::Isolate* m_isolate;
-};
-
ScriptDebugServer::ScriptDebugServer(v8::Isolate* isolate)
: m_pauseOnExceptionsState(DontPauseOnExceptions)
, m_breakpointsActivated(true)
@@ -337,12 +274,31 @@ void ScriptDebugServer::updateCallStack(ScriptValue* callFrame)
*callFrame = currentCallFrame();
}
+ScriptController* ScriptDebugServer::scriptController(v8::Handle<v8::Context> context)
+{
+ return 0;
+}
-void ScriptDebugServer::setScriptPreprocessor(const String& preprocessorBody)
+void ScriptDebugServer::preprocess(v8::Handle<v8::Context> eventContext, v8::Handle<v8::Object> eventData)
{
- m_scriptPreprocessor.clear();
- if (!preprocessorBody.isEmpty())
- m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(preprocessorBody, m_isolate));
+ v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
+ v8::Context::Scope contextScope(debugContext);
+
+ v8::Handle<v8::Value> argvEventData[] = { eventData };
+ String typeInfo = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptCompilationTypeInfo", 1, argvEventData));
+ if (!typeInfo.startsWith("eval"))
+ return;
+
+ String scriptName = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptName", 1, argvEventData));
+ String script = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptSource", 1, argvEventData));
+ ScriptController* controller = scriptController(eventContext);
+ if (!controller)
+ return;
+
+ String patchedScript = controller->preprocess(script, scriptName);
+
+ v8::Handle<v8::Value> argv2[] = { eventData, v8String(patchedScript, debugContext->GetIsolate()) };
+ callDebuggerMethod("setScriptSource", 2, argv2);
}
ScriptValue ScriptDebugServer::currentCallFrame()
@@ -431,27 +387,7 @@ void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
if (listener) {
v8::HandleScope scope;
if (event == v8::BeforeCompile) {
-
- if (!m_scriptPreprocessor)
- return;
-
- OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release());
- v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
- v8::Context::Scope contextScope(debugContext);
- v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptSource")));
- v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> script = getScriptSourceFunction->Call(m_debuggerScript.get(), 1, argv);
-
- v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptName")));
- v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_debuggerScript.get(), 1, argv1);
-
- v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource")));
- String patchedScript = preprocessor->preprocessSourceCode(toWebCoreStringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(scriptName));
-
- v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8String(patchedScript, debugContext->GetIsolate()) };
- setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2);
- m_scriptPreprocessor = preprocessor.release();
+ preprocess(eventContext, eventDetails.GetEventData());
} else if (event == v8::AfterCompile) {
v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileScript")));

Powered by Google App Engine
This is Rietveld 408576698