Add Debugger.ExceptionDetails to protocol. Use ExceptionDetails for pass error...

Add Debugger.ExceptionDetails to protocol. Use ExceptionDetails for pass error when exception in snippet (run or compile).

Console show the position of exception when exception happens in snippet.

BUG=346013

Review URL: https://codereview.chromium.org/290633009

git-svn-id: svn://svn.chromium.org/blink/trunk@175794 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e77aba7e
...@@ -11,10 +11,19 @@ Script result: 3 ...@@ -11,10 +11,19 @@ Script result: 3
Running: testRunError Running: testRunError
Compiling script Compiling script
Running script Running script
Script run error: Uncaught ReferenceError: c is not defined exceptionDetails:
Uncaught ReferenceError: c is not defined
line: 1, column: 15
exceptionDetails stack trace:
url: test.js
function:
line: 1
Running: testCompileError Running: testCompileError
Compiling script Compiling script
Script compile error: Uncaught SyntaxError: Unexpected token } exceptionDetails:
Uncaught SyntaxError: Unexpected token }
line: 1, column: 0
no stack trace attached to exceptionDetails
Debugger was disabled. Debugger was disabled.
...@@ -5,6 +5,25 @@ ...@@ -5,6 +5,25 @@
<script> <script>
var test = function() var test = function()
{ {
function printExceptionDetails(exceptionDetails)
{
InspectorTest.addResult("exceptionDetails:")
InspectorTest.addResult(" " + exceptionDetails.text);
InspectorTest.addResult(" line: " + exceptionDetails.line + ", column: " + exceptionDetails.column);
var stack = exceptionDetails.stackTrace;
if (!stack) {
InspectorTest.addResult(" no stack trace attached to exceptionDetails");
} else {
InspectorTest.addResult(" exceptionDetails stack trace:");
for (var i = 0; i < stack.length && i < 100; ++i) {
InspectorTest.addResult(" url: " + stack[i].url);
InspectorTest.addResult(" function: " + stack[i].functionName);
InspectorTest.addResult(" line: " + stack[i].lineNumber);
}
}
}
InspectorTest.runDebuggerTestSuite([ InspectorTest.runDebuggerTestSuite([
function testSuccessfulCompileAndRun(next) function testSuccessfulCompileAndRun(next)
{ {
...@@ -12,18 +31,18 @@ var test = function() ...@@ -12,18 +31,18 @@ var test = function()
InspectorTest.addResult("Compiling script"); InspectorTest.addResult("Compiling script");
DebuggerAgent.compileScript(expression, "test.js", compileCallback.bind(this)); DebuggerAgent.compileScript(expression, "test.js", compileCallback.bind(this));
function compileCallback(error, scriptId, syntaxErrorMessage) function compileCallback(error, scriptId, exceptionDetails)
{ {
InspectorTest.assertTrue(!error); InspectorTest.assertTrue(!error);
InspectorTest.assertTrue(!syntaxErrorMessage); InspectorTest.assertTrue(!exceptionDetails);
InspectorTest.assertTrue(!!scriptId); InspectorTest.assertTrue(!!scriptId);
var contextId = undefined;
InspectorTest.addResult("Running script"); InspectorTest.addResult("Running script");
DebuggerAgent.runScript(scriptId, contextId, "console", false, runCallback.bind(this)); DebuggerAgent.runScript(scriptId, undefined, "console", false, runCallback.bind(this));
} }
function runCallback(error, result, wasThrown) function runCallback(error, result, exceptionDetails)
{ {
var wasThrown = !!exceptionDetails;
InspectorTest.assertTrue(!error); InspectorTest.assertTrue(!error);
InspectorTest.assertTrue(!wasThrown); InspectorTest.assertTrue(!wasThrown);
InspectorTest.addResult("Script result: " + result.value); InspectorTest.addResult("Script result: " + result.value);
...@@ -37,21 +56,21 @@ var test = function() ...@@ -37,21 +56,21 @@ var test = function()
InspectorTest.addResult("Compiling script"); InspectorTest.addResult("Compiling script");
DebuggerAgent.compileScript(expression, "test.js", compileCallback.bind(this)); DebuggerAgent.compileScript(expression, "test.js", compileCallback.bind(this));
function compileCallback(error, scriptId, syntaxErrorMessage) function compileCallback(error, scriptId, exceptionDetails)
{ {
InspectorTest.assertTrue(!error); InspectorTest.assertTrue(!error);
InspectorTest.assertTrue(!syntaxErrorMessage); InspectorTest.assertTrue(!exceptionDetails);
InspectorTest.assertTrue(!!scriptId); InspectorTest.assertTrue(!!scriptId);
var contextId = undefined;
InspectorTest.addResult("Running script"); InspectorTest.addResult("Running script");
DebuggerAgent.runScript(scriptId, contextId, "console", false, runCallback.bind(this)); DebuggerAgent.runScript(scriptId, undefined, "console", false, runCallback.bind(this));
} }
function runCallback(error, result, wasThrown) function runCallback(error, result, exceptionDetails)
{ {
var wasThrown = !!exceptionDetails;
InspectorTest.assertTrue(!error); InspectorTest.assertTrue(!error);
InspectorTest.assertTrue(wasThrown); InspectorTest.assertTrue(wasThrown);
InspectorTest.addResult("Script run error: " + result.description); printExceptionDetails(exceptionDetails);
next(); next();
} }
}, },
...@@ -60,13 +79,15 @@ var test = function() ...@@ -60,13 +79,15 @@ var test = function()
{ {
var expression = "}"; var expression = "}";
InspectorTest.addResult("Compiling script"); InspectorTest.addResult("Compiling script");
DebuggerAgent.compileScript(expression, "test.js", compileCallback.bind(this)); var contextId = undefined;
DebuggerAgent.compileScript(expression, "test.js", contextId, compileCallback.bind(this));
function compileCallback(error, scriptId, syntaxErrorMessage) function compileCallback(error, scriptId, exceptionDetails)
{ {
InspectorTest.assertTrue(!error); InspectorTest.assertTrue(!error);
InspectorTest.assertTrue(!!exceptionDetails);
InspectorTest.assertTrue(!scriptId); InspectorTest.assertTrue(!scriptId);
InspectorTest.addResult("Script compile error: " + syntaxErrorMessage); printExceptionDetails(exceptionDetails);
next(); next();
} }
} }
......
...@@ -165,11 +165,11 @@ void PageScriptDebugServer::setClientMessageLoop(PassOwnPtr<ClientMessageLoop> c ...@@ -165,11 +165,11 @@ void PageScriptDebugServer::setClientMessageLoop(PassOwnPtr<ClientMessageLoop> c
m_clientMessageLoop = clientMessageLoop; m_clientMessageLoop = clientMessageLoop;
} }
void PageScriptDebugServer::compileScript(ScriptState* scriptState, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage) void PageScriptDebugServer::compileScript(ScriptState* scriptState, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace)
{ {
ExecutionContext* executionContext = scriptState->executionContext(); ExecutionContext* executionContext = scriptState->executionContext();
RefPtr<LocalFrame> protect = toDocument(executionContext)->frame(); RefPtr<LocalFrame> protect = toDocument(executionContext)->frame();
ScriptDebugServer::compileScript(scriptState, expression, sourceURL, scriptId, exceptionMessage); ScriptDebugServer::compileScript(scriptState, expression, sourceURL, scriptId, exceptionDetailsText, lineNumber, columnNumber, stackTrace);
if (!scriptId->isNull()) if (!scriptId->isNull())
m_compiledScriptURLs.set(*scriptId, sourceURL); m_compiledScriptURLs.set(*scriptId, sourceURL);
} }
...@@ -180,7 +180,7 @@ void PageScriptDebugServer::clearCompiledScripts() ...@@ -180,7 +180,7 @@ void PageScriptDebugServer::clearCompiledScripts()
m_compiledScriptURLs.clear(); m_compiledScriptURLs.clear();
} }
void PageScriptDebugServer::runScript(ScriptState* scriptState, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage) void PageScriptDebugServer::runScript(ScriptState* scriptState, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace)
{ {
String sourceURL = m_compiledScriptURLs.take(scriptId); String sourceURL = m_compiledScriptURLs.take(scriptId);
...@@ -194,7 +194,7 @@ void PageScriptDebugServer::runScript(ScriptState* scriptState, const String& sc ...@@ -194,7 +194,7 @@ void PageScriptDebugServer::runScript(ScriptState* scriptState, const String& sc
cookie = InspectorInstrumentation::willEvaluateScript(frame, sourceURL, TextPosition::minimumPosition().m_line.oneBasedInt()); cookie = InspectorInstrumentation::willEvaluateScript(frame, sourceURL, TextPosition::minimumPosition().m_line.oneBasedInt());
RefPtr<LocalFrame> protect = frame; RefPtr<LocalFrame> protect = frame;
ScriptDebugServer::runScript(scriptState, scriptId, result, wasThrown, exceptionMessage); ScriptDebugServer::runScript(scriptState, scriptId, result, wasThrown, exceptionDetailsText, lineNumber, columnNumber, stackTrace);
if (frame) if (frame)
InspectorInstrumentation::didEvaluateScript(cookie); InspectorInstrumentation::didEvaluateScript(cookie);
......
...@@ -64,9 +64,9 @@ public: ...@@ -64,9 +64,9 @@ public:
}; };
void setClientMessageLoop(PassOwnPtr<ClientMessageLoop>); void setClientMessageLoop(PassOwnPtr<ClientMessageLoop>);
virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage) OVERRIDE; virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace) OVERRIDE;
virtual void clearCompiledScripts() OVERRIDE; virtual void clearCompiledScripts() OVERRIDE;
virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage) OVERRIDE; virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace) OVERRIDE;
virtual void setPreprocessorSource(const String&) OVERRIDE; virtual void setPreprocessorSource(const String&) OVERRIDE;
virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) OVERRIDE; virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) OVERRIDE;
virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&) OVERRIDE; virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&) OVERRIDE;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "bindings/core/v8/V8JavaScriptCallFrame.h" #include "bindings/core/v8/V8JavaScriptCallFrame.h"
#include "bindings/v8/ScopedPersistent.h" #include "bindings/v8/ScopedPersistent.h"
#include "bindings/v8/ScriptCallStackFactory.h"
#include "bindings/v8/ScriptController.h" #include "bindings/v8/ScriptController.h"
#include "bindings/v8/ScriptSourceCode.h" #include "bindings/v8/ScriptSourceCode.h"
#include "bindings/v8/ScriptValue.h" #include "bindings/v8/ScriptValue.h"
...@@ -568,7 +569,7 @@ bool ScriptDebugServer::isPaused() ...@@ -568,7 +569,7 @@ bool ScriptDebugServer::isPaused()
return m_pausedScriptState; return m_pausedScriptState;
} }
void ScriptDebugServer::compileScript(ScriptState* scriptState, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage) void ScriptDebugServer::compileScript(ScriptState* scriptState, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace)
{ {
if (scriptState->contextIsEmpty()) if (scriptState->contextIsEmpty())
return; return;
...@@ -579,8 +580,12 @@ void ScriptDebugServer::compileScript(ScriptState* scriptState, const String& ex ...@@ -579,8 +580,12 @@ void ScriptDebugServer::compileScript(ScriptState* scriptState, const String& ex
v8::Local<v8::Script> script = V8ScriptRunner::compileScript(source, sourceURL, TextPosition(), 0, m_isolate); v8::Local<v8::Script> script = V8ScriptRunner::compileScript(source, sourceURL, TextPosition(), 0, m_isolate);
if (tryCatch.HasCaught()) { if (tryCatch.HasCaught()) {
v8::Local<v8::Message> message = tryCatch.Message(); v8::Local<v8::Message> message = tryCatch.Message();
if (!message.IsEmpty()) if (!message.IsEmpty()) {
*exceptionMessage = toCoreStringWithUndefinedOrNullCheck(message->Get()); *exceptionDetailsText = toCoreStringWithUndefinedOrNullCheck(message->Get());
*lineNumber = message->GetLineNumber();
*columnNumber = message->GetStartColumn();
*stackTrace = createScriptCallStack(message->GetStackTrace(), message->GetStackTrace()->GetFrameCount(), m_isolate);
}
return; return;
} }
if (script.IsEmpty()) if (script.IsEmpty())
...@@ -595,7 +600,7 @@ void ScriptDebugServer::clearCompiledScripts() ...@@ -595,7 +600,7 @@ void ScriptDebugServer::clearCompiledScripts()
m_compiledScripts.clear(); m_compiledScripts.clear();
} }
void ScriptDebugServer::runScript(ScriptState* scriptState, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage) void ScriptDebugServer::runScript(ScriptState* scriptState, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace)
{ {
if (!m_compiledScripts.contains(scriptId)) if (!m_compiledScripts.contains(scriptId))
return; return;
...@@ -616,8 +621,12 @@ void ScriptDebugServer::runScript(ScriptState* scriptState, const String& script ...@@ -616,8 +621,12 @@ void ScriptDebugServer::runScript(ScriptState* scriptState, const String& script
*wasThrown = true; *wasThrown = true;
*result = ScriptValue(scriptState, tryCatch.Exception()); *result = ScriptValue(scriptState, tryCatch.Exception());
v8::Local<v8::Message> message = tryCatch.Message(); v8::Local<v8::Message> message = tryCatch.Message();
if (!message.IsEmpty()) if (!message.IsEmpty()) {
*exceptionMessage = toCoreStringWithUndefinedOrNullCheck(message->Get()); *exceptionDetailsText = toCoreStringWithUndefinedOrNullCheck(message->Get());
*lineNumber = message->GetLineNumber();
*columnNumber = message->GetStartColumn();
*stackTrace = createScriptCallStack(message->GetStackTrace(), message->GetStackTrace()->GetFrameCount(), m_isolate);
}
} else { } else {
*result = ScriptValue(scriptState, value); *result = ScriptValue(scriptState, value);
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "InspectorBackendDispatcher.h" #include "InspectorBackendDispatcher.h"
#include "bindings/v8/ScopedPersistent.h" #include "bindings/v8/ScopedPersistent.h"
#include "core/inspector/ScriptBreakpoint.h" #include "core/inspector/ScriptBreakpoint.h"
#include "core/inspector/ScriptCallStack.h"
#include "core/inspector/ScriptDebugListener.h" #include "core/inspector/ScriptDebugListener.h"
#include "wtf/HashMap.h" #include "wtf/HashMap.h"
#include "wtf/Noncopyable.h" #include "wtf/Noncopyable.h"
...@@ -99,9 +100,9 @@ public: ...@@ -99,9 +100,9 @@ public:
v8::Handle<v8::Value> setFunctionVariableValue(v8::Handle<v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Handle<v8::Value> newValue); v8::Handle<v8::Value> setFunctionVariableValue(v8::Handle<v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Handle<v8::Value> newValue);
v8::Local<v8::Value> callDebuggerMethod(const char* functionName, int argc, v8::Handle<v8::Value> argv[]); v8::Local<v8::Value> callDebuggerMethod(const char* functionName, int argc, v8::Handle<v8::Value> argv[]);
virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage); virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace);
virtual void clearCompiledScripts(); virtual void clearCompiledScripts();
virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage); virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace);
virtual void setPreprocessorSource(const String&) { } virtual void setPreprocessorSource(const String&) { }
virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) { } virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) { }
virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&); virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&);
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
using WebCore::TypeBuilder::Array; using WebCore::TypeBuilder::Array;
using WebCore::TypeBuilder::Debugger::BreakpointId; using WebCore::TypeBuilder::Debugger::BreakpointId;
using WebCore::TypeBuilder::Debugger::CallFrame; using WebCore::TypeBuilder::Debugger::CallFrame;
using WebCore::TypeBuilder::Debugger::ExceptionDetails;
using WebCore::TypeBuilder::Debugger::FunctionDetails; using WebCore::TypeBuilder::Debugger::FunctionDetails;
using WebCore::TypeBuilder::Debugger::ScriptId; using WebCore::TypeBuilder::Debugger::ScriptId;
using WebCore::TypeBuilder::Debugger::StackTrace; using WebCore::TypeBuilder::Debugger::StackTrace;
...@@ -888,7 +889,7 @@ void InspectorDebuggerAgent::evaluateOnCallFrame(ErrorString* errorString, const ...@@ -888,7 +889,7 @@ void InspectorDebuggerAgent::evaluateOnCallFrame(ErrorString* errorString, const
} }
} }
void InspectorDebuggerAgent::compileScript(ErrorString* errorString, const String& expression, const String& sourceURL, const int* executionContextId, TypeBuilder::OptOutput<ScriptId>* scriptId, TypeBuilder::OptOutput<String>* syntaxErrorMessage) void InspectorDebuggerAgent::compileScript(ErrorString* errorString, const String& expression, const String& sourceURL, const int* executionContextId, TypeBuilder::OptOutput<ScriptId>* scriptId, RefPtr<ExceptionDetails>& exceptionDetails)
{ {
InjectedScript injectedScript = injectedScriptForEval(errorString, executionContextId); InjectedScript injectedScript = injectedScriptForEval(errorString, executionContextId);
if (injectedScript.isEmpty()) { if (injectedScript.isEmpty()) {
...@@ -897,17 +898,27 @@ void InspectorDebuggerAgent::compileScript(ErrorString* errorString, const Strin ...@@ -897,17 +898,27 @@ void InspectorDebuggerAgent::compileScript(ErrorString* errorString, const Strin
} }
String scriptIdValue; String scriptIdValue;
String exceptionMessage; String exceptionDetailsText;
scriptDebugServer().compileScript(injectedScript.scriptState(), expression, sourceURL, &scriptIdValue, &exceptionMessage); int lineNumberValue = 0;
if (!scriptIdValue && !exceptionMessage) { int columnNumberValue = 0;
RefPtr<ScriptCallStack> stackTraceValue;
scriptDebugServer().compileScript(injectedScript.scriptState(), expression, sourceURL, &scriptIdValue, &exceptionDetailsText, &lineNumberValue, &columnNumberValue, &stackTraceValue);
if (!scriptIdValue && !exceptionDetailsText) {
*errorString = "Script compilation failed"; *errorString = "Script compilation failed";
return; return;
} }
*syntaxErrorMessage = exceptionMessage;
*scriptId = scriptIdValue; *scriptId = scriptIdValue;
if (!scriptIdValue.isEmpty())
return;
exceptionDetails = ExceptionDetails::create().setText(exceptionDetailsText);
exceptionDetails->setLine(lineNumberValue);
exceptionDetails->setColumn(columnNumberValue);
if (stackTraceValue && stackTraceValue->size() > 0)
exceptionDetails->setStackTrace(stackTraceValue->buildInspectorArray());
} }
void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId& scriptId, const int* executionContextId, const String* const objectGroup, const bool* const doNotPauseOnExceptionsAndMuteConsole, RefPtr<RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown) void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId& scriptId, const int* executionContextId, const String* const objectGroup, const bool* const doNotPauseOnExceptionsAndMuteConsole, RefPtr<RemoteObject>& result, RefPtr<ExceptionDetails>& exceptionDetails)
{ {
InjectedScript injectedScript = injectedScriptForEval(errorString, executionContextId); InjectedScript injectedScript = injectedScriptForEval(errorString, executionContextId);
if (injectedScript.isEmpty()) { if (injectedScript.isEmpty()) {
...@@ -924,16 +935,23 @@ void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId& ...@@ -924,16 +935,23 @@ void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId&
ScriptValue value; ScriptValue value;
bool wasThrownValue; bool wasThrownValue;
String exceptionMessage; String exceptionDetailsText;
scriptDebugServer().runScript(injectedScript.scriptState(), scriptId, &value, &wasThrownValue, &exceptionMessage); int lineNumberValue = 0;
*wasThrown = wasThrownValue; int columnNumberValue = 0;
RefPtr<ScriptCallStack> stackTraceValue;
scriptDebugServer().runScript(injectedScript.scriptState(), scriptId, &value, &wasThrownValue, &exceptionDetailsText, &lineNumberValue, &columnNumberValue, &stackTraceValue);
if (value.isEmpty()) { if (value.isEmpty()) {
*errorString = "Script execution failed"; *errorString = "Script execution failed";
return; return;
} }
result = injectedScript.wrapObject(value, objectGroup ? *objectGroup : ""); result = injectedScript.wrapObject(value, objectGroup ? *objectGroup : "");
if (wasThrownValue) if (wasThrownValue) {
result->setDescription(exceptionMessage); exceptionDetails = ExceptionDetails::create().setText(exceptionDetailsText);
exceptionDetails->setLine(lineNumberValue);
exceptionDetails->setColumn(columnNumberValue);
if (stackTraceValue && stackTraceValue->size() > 0)
exceptionDetails->setStackTrace(stackTraceValue->buildInspectorArray());
}
if (doNotPauseOnExceptionsAndMuteConsole && *doNotPauseOnExceptionsAndMuteConsole) { if (doNotPauseOnExceptionsAndMuteConsole && *doNotPauseOnExceptionsAndMuteConsole) {
unmuteConsole(); unmuteConsole();
......
...@@ -132,8 +132,8 @@ public: ...@@ -132,8 +132,8 @@ public:
const bool* generatePreview, const bool* generatePreview,
RefPtr<TypeBuilder::Runtime::RemoteObject>& result, RefPtr<TypeBuilder::Runtime::RemoteObject>& result,
TypeBuilder::OptOutput<bool>* wasThrown) OVERRIDE FINAL; TypeBuilder::OptOutput<bool>* wasThrown) OVERRIDE FINAL;
virtual void compileScript(ErrorString*, const String& expression, const String& sourceURL, const int* executionContextId, TypeBuilder::OptOutput<TypeBuilder::Debugger::ScriptId>*, TypeBuilder::OptOutput<String>* syntaxErrorMessage) OVERRIDE; virtual void compileScript(ErrorString*, const String& expression, const String& sourceURL, const int* executionContextId, TypeBuilder::OptOutput<TypeBuilder::Debugger::ScriptId>*, RefPtr<TypeBuilder::Debugger::ExceptionDetails>&) OVERRIDE;
virtual void runScript(ErrorString*, const TypeBuilder::Debugger::ScriptId&, const int* executionContextId, const String* objectGroup, const bool* doNotPauseOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown) OVERRIDE; virtual void runScript(ErrorString*, const TypeBuilder::Debugger::ScriptId&, const int* executionContextId, const String* objectGroup, const bool* doNotPauseOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>&) OVERRIDE;
virtual void setOverlayMessage(ErrorString*, const String*) OVERRIDE; virtual void setOverlayMessage(ErrorString*, const String*) OVERRIDE;
virtual void setVariableValue(ErrorString*, int in_scopeNumber, const String& in_variableName, const RefPtr<JSONObject>& in_newValue, const String* in_callFrame, const String* in_functionObjectId) OVERRIDE FINAL; virtual void setVariableValue(ErrorString*, int in_scopeNumber, const String& in_variableName, const RefPtr<JSONObject>& in_newValue, const String* in_callFrame, const String* in_functionObjectId) OVERRIDE FINAL;
virtual void skipStackFrames(ErrorString*, const String* pattern) OVERRIDE FINAL; virtual void skipStackFrames(ErrorString*, const String* pattern) OVERRIDE FINAL;
......
...@@ -245,11 +245,11 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -245,11 +245,11 @@ WebInspector.ScriptSnippetModel.prototype = {
/** /**
* @param {!WebInspector.Target} target * @param {!WebInspector.Target} target
* @param {?string} error * @param {?string} error
* @param {string=} scriptId * @param {!DebuggerAgent.ScriptId=} scriptId
* @param {string=} syntaxErrorMessage * @param {?DebuggerAgent.ExceptionDetails=} exceptionDetails
* @this {WebInspector.ScriptSnippetModel} * @this {WebInspector.ScriptSnippetModel}
*/ */
function compileCallback(target, error, scriptId, syntaxErrorMessage) function compileCallback(target, error, scriptId, exceptionDetails)
{ {
if (!uiSourceCode || this._mappingForTarget.get(target).evaluationIndex(uiSourceCode) !== evaluationIndex) if (!uiSourceCode || this._mappingForTarget.get(target).evaluationIndex(uiSourceCode) !== evaluationIndex)
return; return;
...@@ -260,27 +260,23 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -260,27 +260,23 @@ WebInspector.ScriptSnippetModel.prototype = {
} }
if (!scriptId) { if (!scriptId) {
var consoleMessage = new WebInspector.ConsoleMessage( this._printRunOrCompileScriptResultFailure(target, exceptionDetails, evaluationUrl);
target,
WebInspector.ConsoleMessage.MessageSource.JS,
WebInspector.ConsoleMessage.MessageLevel.Error,
syntaxErrorMessage || "");
target.consoleModel.addMessage(consoleMessage);
return; return;
} }
var breakpointLocations = this._removeBreakpoints(uiSourceCode); var breakpointLocations = this._removeBreakpoints(uiSourceCode);
this._restoreBreakpoints(uiSourceCode, breakpointLocations); this._restoreBreakpoints(uiSourceCode, breakpointLocations);
this._runScript(scriptId, executionContext); this._runScript(scriptId, executionContext, evaluationUrl);
} }
}, },
/** /**
* @param {!DebuggerAgent.ScriptId} scriptId * @param {!DebuggerAgent.ScriptId} scriptId
* @param {!WebInspector.ExecutionContext} executionContext * @param {!WebInspector.ExecutionContext} executionContext
* @param {?string=} sourceURL
*/ */
_runScript: function(scriptId, executionContext) _runScript: function(scriptId, executionContext, sourceURL)
{ {
var target = executionContext.target(); var target = executionContext.target();
target.debuggerAgent().runScript(scriptId, executionContext.id, "console", false, runCallback.bind(this, target)); target.debuggerAgent().runScript(scriptId, executionContext.id, "console", false, runCallback.bind(this, target));
...@@ -289,39 +285,65 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -289,39 +285,65 @@ WebInspector.ScriptSnippetModel.prototype = {
* @param {!WebInspector.Target} target * @param {!WebInspector.Target} target
* @param {?string} error * @param {?string} error
* @param {?RuntimeAgent.RemoteObject} result * @param {?RuntimeAgent.RemoteObject} result
* @param {boolean=} wasThrown * @param {?DebuggerAgent.ExceptionDetails=} exceptionDetails
* @this {WebInspector.ScriptSnippetModel} * @this {WebInspector.ScriptSnippetModel}
*/ */
function runCallback(target, error, result, wasThrown) function runCallback(target, error, result, exceptionDetails)
{ {
if (error) { if (error) {
console.error(error); console.error(error);
return; return;
} }
this._printRunScriptResult(target, result, wasThrown); if (!exceptionDetails)
this._printRunScriptResult(target, result, sourceURL);
else
this._printRunOrCompileScriptResultFailure(target, exceptionDetails, sourceURL);
} }
}, },
/** /**
* @param {!WebInspector.Target} target * @param {!WebInspector.Target} target
* @param {?RuntimeAgent.RemoteObject} result * @param {?RuntimeAgent.RemoteObject} result
* @param {boolean=} wasThrown * @param {?string=} sourceURL
*/ */
_printRunScriptResult: function(target, result, wasThrown) _printRunScriptResult: function(target, result, sourceURL)
{ {
var level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log); var consoleMessage = new WebInspector.ConsoleMessage(
var message = new WebInspector.ConsoleMessage(target, target,
WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageSource.JS,
level, WebInspector.ConsoleMessage.MessageLevel.Log,
"", "",
undefined, undefined,
sourceURL,
undefined, undefined,
undefined, undefined,
undefined, undefined,
[result],
undefined);
target.consoleModel.addMessage(consoleMessage);
},
/**
* @param {!WebInspector.Target} target
* @param {?DebuggerAgent.ExceptionDetails=} exceptionDetails
* @param {?string=} sourceURL
*/
_printRunOrCompileScriptResultFailure: function(target, exceptionDetails, sourceURL)
{
var consoleMessage = new WebInspector.ConsoleMessage(
target,
exceptionDetails.source,
WebInspector.ConsoleMessage.MessageLevel.Error,
exceptionDetails.text,
undefined,
sourceURL,
exceptionDetails.line,
exceptionDetails.column,
undefined,
undefined, undefined,
[result]); exceptionDetails.stackTrace);
target.consoleModel.addMessage(message); target.consoleModel.addMessage(consoleMessage);
}, },
/** /**
......
...@@ -2958,6 +2958,18 @@ ...@@ -2958,6 +2958,18 @@
], ],
"description": "Scope description." "description": "Scope description."
}, },
{
"id": "ExceptionDetails",
"type": "object",
"description": "Detailed information on exception (or error) that was thrown during script compilation or execution.",
"properties": [
{ "name": "text", "type": "string", "description": "Exception text." },
{ "name": "url", "type": "string", "optional": true, "description": "URL of the message origin." },
{ "name": "line", "type": "integer", "optional": true, "description": "Line number in the resource that generated this message." },
{ "name": "column", "type": "integer", "optional": true, "description": "Column number in the resource that generated this message." },
{ "name": "stackTrace", "$ref": "Console.StackTrace", "optional": true, "description": "JavaScript stack trace for assertions and error messages." }
]
},
{ {
"id": "SetScriptSourceError", "id": "SetScriptSourceError",
"type": "object", "type": "object",
...@@ -3173,7 +3185,7 @@ ...@@ -3173,7 +3185,7 @@
], ],
"returns": [ "returns": [
{ "name": "scriptId", "$ref": "ScriptId", "optional": true, "description": "Id of the script." }, { "name": "scriptId", "$ref": "ScriptId", "optional": true, "description": "Id of the script." },
{ "name": "syntaxErrorMessage", "type": "string", "optional": true, "description": "Syntax error message if compilation failed." } { "name": "exceptionDetails", "$ref": "ExceptionDetails", "optional": true, "description": "Exception details."}
], ],
"description": "Compiles expression." "description": "Compiles expression."
}, },
...@@ -3188,7 +3200,7 @@ ...@@ -3188,7 +3200,7 @@
], ],
"returns": [ "returns": [
{ "name": "result", "$ref": "Runtime.RemoteObject", "description": "Run result." }, { "name": "result", "$ref": "Runtime.RemoteObject", "description": "Run result." },
{ "name": "wasThrown", "type": "boolean", "optional": true, "description": "True if the result was thrown during the script run." } { "name": "exceptionDetails", "$ref": "ExceptionDetails", "optional": true, "description": "Exception details."}
], ],
"description": "Runs script with given id in a given context." "description": "Runs script with given id in a given context."
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment