Chromium Code Reviews| Index: Source/bindings/v8/ScriptDebugServer.cpp |
| diff --git a/Source/bindings/v8/ScriptDebugServer.cpp b/Source/bindings/v8/ScriptDebugServer.cpp |
| index 9db872fddba0a263113d99b0131a65b1c6d76b61..5d21a0ed59200a963094717c0193b6f5fe465441 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,39 @@ 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)); |
| + // Extract the controller before we enter the debugContext. |
|
abarth-chromium
2013/07/08 23:57:08
This comment doesn't add anything to the code and
johnjbarton
2013/07/09 22:44:54
Done.
|
| + ScriptController* controller = scriptController(eventContext); |
| + if (!controller) |
| + return; |
| + |
| + // Don't examine event unless we are preprocessing Wegb page code. |
| + if (!controller->hasScriptPreprocessor() || controller->isScriptPreprocessing()) |
| + 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", 1, argvEventData)); |
|
abarth-chromium
2013/07/08 23:57:08
1 -> WTF_ARRAY_LENGTH(argv)
johnjbarton
2013/07/09 22:44:54
Done.
|
| + if (!typeInfo.startsWith("eval")) |
| + return; |
| + |
| + // The name and source are in the JS event data. |
| + String scriptName = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptName", 1, argvEventData)); |
| + String script = toWebCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptSource", 1, argvEventData)); |
| + String patchedScript = controller->preprocess(script, scriptName); |
| + |
| + v8::Handle<v8::Value> argv2[] = { eventData, v8String(patchedScript, debugContext->GetIsolate()) }; |
| + callDebuggerMethod("setScriptSource", 2, argv2); |
| } |
| ScriptValue ScriptDebugServer::currentCallFrame() |
| @@ -408,7 +378,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 +441,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 +462,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>()); |