Crash if you type "debugger" in the console and continue
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 May 2016 19:01:40 +0000 (19:01 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 May 2016 19:01:40 +0000 (19:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156924
<rdar://problem/25884189>

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-05-05
Reviewed by Mark Lam.

Source/JavaScriptCore:

* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::evaluateOnCallFrame):
Bail with an error when we are not paused.

* inspector/agents/InspectorRuntimeAgent.cpp:
(Inspector::InspectorRuntimeAgent::callFunctionOn):
(Inspector::InspectorRuntimeAgent::getProperties):
(Inspector::InspectorRuntimeAgent::getDisplayableProperties):
(Inspector::InspectorRuntimeAgent::getCollectionEntries):
(Inspector::InspectorRuntimeAgent::saveResult):
Update poor error message.

Source/WebInspectorUI:

* UserInterface/Test/InspectorProtocol.js:
(InspectorProtocol.sendCommand):
Simplify sending a command with no parameters.

LayoutTests:

* inspector/debugger/evaluateOnCallFrame-errors-expected.txt: Added.
* inspector/debugger/evaluateOnCallFrame-errors.html: Added.
* inspector/protocol/backend-dispatcher-argument-errors-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200467 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/debugger/evaluateOnCallFrame-errors-expected.txt [new file with mode: 0644]
LayoutTests/inspector/debugger/evaluateOnCallFrame-errors.html [new file with mode: 0644]
LayoutTests/inspector/protocol/backend-dispatcher-argument-errors-expected.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp
Source/JavaScriptCore/inspector/agents/InspectorRuntimeAgent.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Test/InspectorProtocol.js

index c48c2df..def7c85 100644 (file)
@@ -1,3 +1,15 @@
+2016-05-05  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Crash if you type "debugger" in the console and continue
+        https://bugs.webkit.org/show_bug.cgi?id=156924
+        <rdar://problem/25884189>
+
+        Reviewed by Mark Lam.
+
+        * inspector/debugger/evaluateOnCallFrame-errors-expected.txt: Added.
+        * inspector/debugger/evaluateOnCallFrame-errors.html: Added.
+        * inspector/protocol/backend-dispatcher-argument-errors-expected.txt:
+
 2016-05-04  Simon Fraser  <simon.fraser@apple.com>
 
         Comments on wired.com are blurry
diff --git a/LayoutTests/inspector/debugger/evaluateOnCallFrame-errors-expected.txt b/LayoutTests/inspector/debugger/evaluateOnCallFrame-errors-expected.txt
new file mode 100644 (file)
index 0000000..a85e252
--- /dev/null
@@ -0,0 +1,14 @@
+Calling Debugger.evaluateOnCallFrame protocol error cases.
+
+
+== Running test suite: Debugger.evaluateOnCallFrame.errors
+-- Running test case: EvaluateOnCallFrameNotPaused
+PASS: Paused
+PASS: Resumed
+PASS: Should be an error: Not paused
+
+-- Running test case: EvaluateOnCallFrameBadCallFrameIdentifier
+PASS: Paused
+PASS: Should be an error: Could not find InjectedScript for callFrameId
+PASS: Resumed
+
diff --git a/LayoutTests/inspector/debugger/evaluateOnCallFrame-errors.html b/LayoutTests/inspector/debugger/evaluateOnCallFrame-errors.html
new file mode 100644 (file)
index 0000000..98f5660
--- /dev/null
@@ -0,0 +1,70 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
+<script>
+function triggerPause() {
+    debugger;
+}
+
+function test()
+{
+    InspectorProtocol.sendCommand("Debugger.enable");
+    InspectorProtocol.sendCommand("Debugger.setBreakpointsActive", {active: true});
+
+    let suite = ProtocolTest.createAsyncSuite("Debugger.evaluateOnCallFrame.errors");
+
+    suite.addTestCase({
+        name: "EvaluateOnCallFrameNotPaused",
+        description: "Triggering evaluate on call frame when not paused should issue an error.",
+        test: (resolve, reject) => {
+            ProtocolTest.evaluateInPage("triggerPause()");
+
+            let callFrameIdentifier;
+
+            InspectorProtocol.eventHandler["Debugger.paused"] = (messageObject) => {
+                ProtocolTest.pass("Paused");
+                InspectorProtocol.sendCommand("Debugger.resume");
+                callFrameIdentifier = messageObject.params.callFrames[0].callFrameId;
+            };
+
+            InspectorProtocol.eventHandler["Debugger.resumed"] = (messageObject) => {
+                ProtocolTest.pass("Resumed");
+                InspectorProtocol.sendCommand("Debugger.evaluateOnCallFrame", {callFrameId: callFrameIdentifier, expression: "this"}, (messageObject) => {
+                    ProtocolTest.expectThat(messageObject.error, `Should be an error: ${messageObject.error ? messageObject.error.message : ""}`);
+                    resolve();
+                });
+            };
+        }
+    });
+
+    suite.addTestCase({
+        name: "EvaluateOnCallFrameBadCallFrameIdentifier",
+        description: "Triggering evaluate on call frame with a bad call frame identifier should issue an error.",
+        test: (resolve, reject) => {
+            ProtocolTest.evaluateInPage("triggerPause()");
+
+            InspectorProtocol.eventHandler["Debugger.paused"] = (messageObject) => {
+                ProtocolTest.pass("Paused");
+
+                InspectorProtocol.sendCommand("Debugger.evaluateOnCallFrame", {callFrameId: "BAD-CALL-FRAME-ID", expression: "this"}, (messageObject) => {
+                    ProtocolTest.expectThat(messageObject.error, `Should be an error: ${messageObject.error ? messageObject.error.message : ""}`);
+                    InspectorProtocol.sendCommand("Debugger.resume");
+                });
+            };
+
+            InspectorProtocol.eventHandler["Debugger.resumed"] = (messageObject) => {
+                ProtocolTest.pass("Resumed");
+                resolve();
+            };
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Calling Debugger.evaluateOnCallFrame protocol error cases.</p>
+</body>
+</html>
index 7510371..a48c277 100644 (file)
@@ -55,6 +55,6 @@ Sending message: {"id":123,"method":"Runtime.getProperties","params":{"objectId"
 PASS: the backend should send a protocol error when receiving an invalid message.
 PASS: the reported error should be "ServerError" (-32000)
 Actual error code: -32000
-Actual error message: Inspected frame has gone
-Actual error data: [{"code":-32000,"message":"Inspected frame has gone"}]
+Actual error message: Could not find InjectedScript for objectId
+Actual error data: [{"code":-32000,"message":"Could not find InjectedScript for objectId"}]
 
index c98aace..06b4dce 100644 (file)
@@ -1,3 +1,23 @@
+2016-05-05  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Crash if you type "debugger" in the console and continue
+        https://bugs.webkit.org/show_bug.cgi?id=156924
+        <rdar://problem/25884189>
+
+        Reviewed by Mark Lam.
+
+        * inspector/agents/InspectorDebuggerAgent.cpp:
+        (Inspector::InspectorDebuggerAgent::evaluateOnCallFrame):
+        Bail with an error when we are not paused.
+
+        * inspector/agents/InspectorRuntimeAgent.cpp:
+        (Inspector::InspectorRuntimeAgent::callFunctionOn):
+        (Inspector::InspectorRuntimeAgent::getProperties):
+        (Inspector::InspectorRuntimeAgent::getDisplayableProperties):
+        (Inspector::InspectorRuntimeAgent::getCollectionEntries):
+        (Inspector::InspectorRuntimeAgent::saveResult):
+        Update poor error message.
+
 2016-05-05  Keith Miller  <keith_miller@apple.com>
 
         Add support for delete by value to the DFG
index 618222c..73cfb6f 100644 (file)
@@ -565,9 +565,14 @@ void InspectorDebuggerAgent::setPauseOnExceptions(ErrorString& errorString, cons
 
 void InspectorDebuggerAgent::evaluateOnCallFrame(ErrorString& errorString, const String& callFrameId, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptionsAndMuteConsole, const bool* const returnByValue, const bool* generatePreview, const bool* saveResult, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result, Inspector::Protocol::OptOutput<bool>* wasThrown, Inspector::Protocol::OptOutput<int>* savedResultIndex)
 {
+    if (m_currentCallStack.hasNoValue()) {
+        errorString = ASCIILiteral("Not paused");
+        return;
+    }
+
     InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(callFrameId);
     if (injectedScript.hasNoValue()) {
-        errorString = ASCIILiteral("Inspected frame has gone");
+        errorString = ASCIILiteral("Could not find InjectedScript for callFrameId");
         return;
     }
 
index 81d03bd..5b22544 100644 (file)
@@ -137,7 +137,7 @@ void InspectorRuntimeAgent::callFunctionOn(ErrorString& errorString, const Strin
 {
     InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);
     if (injectedScript.hasNoValue()) {
-        errorString = ASCIILiteral("Inspected frame has gone");
+        errorString = ASCIILiteral("Could not find InjectedScript for objectId");
         return;
     }
 
@@ -163,7 +163,7 @@ void InspectorRuntimeAgent::getProperties(ErrorString& errorString, const String
 {
     InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);
     if (injectedScript.hasNoValue()) {
-        errorString = ASCIILiteral("Inspected frame has gone");
+        errorString = ASCIILiteral("Could not find InjectedScript for objectId");
         return;
     }
 
@@ -181,7 +181,7 @@ void InspectorRuntimeAgent::getDisplayableProperties(ErrorString& errorString, c
 {
     InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);
     if (injectedScript.hasNoValue()) {
-        errorString = ASCIILiteral("Inspected frame has gone");
+        errorString = ASCIILiteral("Could not find InjectedScript for objectId");
         return;
     }
 
@@ -199,7 +199,7 @@ void InspectorRuntimeAgent::getCollectionEntries(ErrorString& errorString, const
 {
     InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);
     if (injectedScript.hasNoValue()) {
-        errorString = ASCIILiteral("Inspected frame has gone");
+        errorString = ASCIILiteral("Could not find InjectedScript for objectId");
         return;
     }
 
@@ -217,7 +217,7 @@ void InspectorRuntimeAgent::saveResult(ErrorString& errorString, const Inspector
     if (callArgument.getString(ASCIILiteral("objectId"), objectId)) {
         injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);
         if (injectedScript.hasNoValue()) {
-            errorString = ASCIILiteral("Inspected frame has gone");
+            errorString = ASCIILiteral("Could not find InjectedScript for objectId");
             return;
         }
     } else {
index 3280217..6bd574e 100644 (file)
@@ -1,3 +1,15 @@
+2016-05-05  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Crash if you type "debugger" in the console and continue
+        https://bugs.webkit.org/show_bug.cgi?id=156924
+        <rdar://problem/25884189>
+
+        Reviewed by Mark Lam.
+
+        * UserInterface/Test/InspectorProtocol.js:
+        (InspectorProtocol.sendCommand):
+        Simplify sending a command with no parameters.
+
 2016-05-04  Nikita Vasilyev  <nvasilyev@apple.com>
 
         REGRESSION (r200401): Web Inspector: TypeError: undefined is not an object (evaluating 'messageElement.classList')
index 108d77f..bd5582b 100644 (file)
@@ -36,6 +36,8 @@ InspectorProtocol.sendCommand = function(methodOrObject, params, handler)
     let method = methodOrObject;
     if (typeof methodOrObject === "object")
         ({method, params, handler} = methodOrObject);
+    else if (!params)
+        params = {};
 
     this._dispatchTable[++this._requestId] = handler;
     let messageObject = {method, params, id: this._requestId};