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

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: respond to review 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/ScriptDebugServer.cpp
diff --git a/Source/bindings/v8/ScriptDebugServer.cpp b/Source/bindings/v8/ScriptDebugServer.cpp
index 9db872fddba0a263113d99b0131a65b1c6d76b61..da4934de38b1d571caf56855aef713d45df205b6 100644
--- a/Source/bindings/v8/ScriptDebugServer.cpp
+++ b/Source/bindings/v8/ScriptDebugServer.cpp
@@ -34,6 +34,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/V8ScriptRunner.h"
@@ -66,64 +67,6 @@ v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN
return V8ScriptRunner::callInternalFunction(function, debuggerScript, 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;
- v8::Context::Scope contextScope(context);
-
- 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);
- 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 = m_utilityContext.newLocal(m_isolate);
- 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::Handle<v8::Value> resultValue = V8ScriptRunner::callInternalFunction(m_preprocessorFunction.newLocal(m_isolate), context->Global(), WTF_ARRAY_LENGTH(argv), argv, m_isolate);
-
- if (!resultValue.IsEmpty() && 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)
@@ -365,12 +308,38 @@ 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::preprocessEval(v8::Handle<v8::Context> eventContext, v8::Handle<v8::Object> eventData)
{
- m_scriptPreprocessor.clear();
- if (!preprocessorBody.isEmpty())
- m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(preprocessorBody, m_isolate));
+ ScriptController* controller = scriptController(eventContext);
+ if (!controller)
+ return;
+
+ // Don't examine event unless we are preprocessing Web page code.
+ if (!controller->hasScriptPreprocessor() || controller->isPreprocessingScript())
+ return;
+
+ v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
+ v8::Context::Scope contextScope(debugContext);
+
+ // <script> tag source and attribute value source are preprocessed before we enter V8.
+ // Avoid preprocessing any internal scripts by processing only eval source in this V8 event handler.
+ v8::Handle<v8::Value> argvEventData[] = { eventData };
+ String typeInfo = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptCompilationTypeInfo", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
+ if (!typeInfo.startsWith("eval"))
+ return;
+
+ // The name and source are in the JS event data.
+ String scriptName = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptName", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
+ String script = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptSource", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
+ String patchedScript = controller->preprocess(script, scriptName);
abarth-chromium 2013/07/09 23:14:10 |controller| might be pointing to an object that h
johnjbarton 2013/07/10 23:24:23 We can't compute the ScriptController within the d
+
+ v8::Handle<v8::Value> argv2[] = { eventData, v8String(patchedScript, debugContext->GetIsolate()) };
abarth-chromium 2013/07/09 23:14:10 argv2 -> Please use a more descriptive name fo
johnjbarton 2013/07/10 23:24:23 Done.
+ callDebuggerMethod("setScriptSource", WTF_ARRAY_LENGTH(argv2), argv2);
}
ScriptValue ScriptDebugServer::currentCallFrame()
@@ -408,7 +377,6 @@ static ScriptDebugServer* toScriptDebugServer(v8::Handle<v8::Value> data)
void ScriptDebugServer::breakProgramCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
ASSERT(2 == args.Length());
-
ScriptDebugServer* thisPtr = toScriptDebugServer(args.Data());
v8::Handle<v8::Value> exception;
v8::Handle<v8::Array> hitBreakpoints;
@@ -472,34 +440,13 @@ void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
ScriptDebugListener* listener = getDebugListenerForContext(eventContext);
if (listener) {
- v8::HandleScope scope(m_isolate);
- v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
- v8::Handle<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isolate);
if (event == v8::BeforeCompile) {
-
- if (!m_scriptPreprocessor)
- return;
-
- OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release());
- v8::Context::Scope contextScope(debugContext);
- v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::New("getScriptSource")));
- v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> script = V8ScriptRunner::callInternalFunction(getScriptSourceFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate);
-
- v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::New("getScriptName")));
- v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> scriptName = V8ScriptRunner::callInternalFunction(getScriptNameFunction, debuggerScript, WTF_ARRAY_LENGTH(argv1), argv1, m_isolate);
- v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::New("setScriptSource")));
- String patchedScript = preprocessor->preprocessSourceCode(toWebCoreStringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(scriptName));
-
- v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8String(patchedScript, m_isolate) };
- V8ScriptRunner::callInternalFunction(setScriptSourceFunction, debuggerScript, WTF_ARRAY_LENGTH(argv2), argv2, m_isolate);
- m_scriptPreprocessor = preprocessor.release();
+ preprocessEval(eventContext, eventDetails.GetEventData());
} else if (event == v8::AfterCompile) {
v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
- v8::Handle<v8::Function> getAfterCompileScript = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::NewSymbol("getAfterCompileScript")));
+ v8::Handle<v8::Function> getAfterCompileScript = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileScript")));
v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(getAfterCompileScript, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate);
+ v8::Handle<v8::Value> value = V8ScriptRunner::callInternalFunction(getAfterCompileScript, m_debuggerScript.get(), WTF_ARRAY_LENGTH(argv), argv, m_isolate);
ASSERT(value->IsObject());
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
dispatchDidParseSource(listener, object);
@@ -514,9 +461,9 @@ void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
v8::Handle<v8::Value> exception = V8ScriptRunner::callInternalFunction(v8::Handle<v8::Function>::Cast(exceptionGetterValue), eventData, 0, 0, m_isolate);
handleProgramBreak(eventDetails, exception, v8::Handle<v8::Array>());
} else if (event == v8::Break) {
- v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8::String::NewSymbol("getBreakpointNumbers")));
+ v8::Handle<v8::Function> getBreakpointNumbersFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getBreakpointNumbers")));
v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
- v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalFunction(getBreakpointNumbersFunction, debuggerScript, WTF_ARRAY_LENGTH(argv), argv, m_isolate);
+ v8::Handle<v8::Value> hitBreakpoints = V8ScriptRunner::callInternalFunction(getBreakpointNumbersFunction, m_debuggerScript.get(), WTF_ARRAY_LENGTH(argv), argv, m_isolate);
ASSERT(hitBreakpoints->IsArray());
handleProgramBreak(eventDetails, v8::Handle<v8::Value>(), hitBreakpoints.As<v8::Array>());

Powered by Google App Engine
This is Rietveld 408576698