mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 921366 - Fix output for throw false/0/null/undefined in Scratchpad; r=msucan
This commit is contained in:
parent
e27d57317b
commit
9af4e3e887
@ -351,7 +351,7 @@ var Scratchpad = {
|
||||
if (aResponse.error) {
|
||||
deferred.reject(aResponse);
|
||||
}
|
||||
else if (aResponse.exception) {
|
||||
else if (aResponse.exception !== null) {
|
||||
deferred.resolve([aString, aResponse]);
|
||||
}
|
||||
else {
|
||||
@ -609,7 +609,21 @@ var Scratchpad = {
|
||||
let deferred = promise.defer();
|
||||
|
||||
if (VariablesView.isPrimitive({ value: aError })) {
|
||||
deferred.resolve(aError);
|
||||
let type = aError.type;
|
||||
if (type == "undefined" ||
|
||||
type == "null" ||
|
||||
type == "Infinity" ||
|
||||
type == "-Infinity" ||
|
||||
type == "NaN" ||
|
||||
type == "-0") {
|
||||
deferred.resolve(type);
|
||||
}
|
||||
else if (type == "longString") {
|
||||
deferred.resolve(aError.initial + "\u2026");
|
||||
}
|
||||
else {
|
||||
deferred.resolve(aError);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let objectClient = new ObjectClient(this.debuggerClient, aError);
|
||||
|
@ -31,6 +31,7 @@ support-files = head.js
|
||||
# Disabled, as escodegen is being replaced - bug 930141
|
||||
# [browser_scratchpad_pprint-02.js]
|
||||
# [browser_scratchpad_pprint.js]
|
||||
[browser_scratchpad_throw_output.js]
|
||||
[browser_scratchpad_restore.js]
|
||||
[browser_scratchpad_tab_switch.js]
|
||||
[browser_scratchpad_ui.js]
|
||||
|
@ -0,0 +1,50 @@
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let temp = {};
|
||||
Cu.import("resource://gre/modules/devtools/dbg-server.jsm", temp);
|
||||
|
||||
function test()
|
||||
{
|
||||
waitForExplicitFinish();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
|
||||
openScratchpad(testThrowOutput);
|
||||
}, true);
|
||||
|
||||
content.location = "data:text/html;charset=utf8,<p>Test throw outputs in Scratchpad</p>";
|
||||
}
|
||||
|
||||
function testThrowOutput()
|
||||
{
|
||||
let scratchpad = gScratchpadWindow.Scratchpad, tests = [];
|
||||
|
||||
let falsyValues = ["false", "0", "-0", "null", "undefined", "Infinity",
|
||||
"-Infinity", "NaN"];
|
||||
falsyValues.forEach(function(value) {
|
||||
tests.push({
|
||||
method: "display",
|
||||
code: "throw " + value + ";",
|
||||
result: "throw " + value + ";\n/*\nException: " + value + "\n*/",
|
||||
label: "Correct exception message for '" + value + "' is shown"
|
||||
});
|
||||
});
|
||||
|
||||
let longString = Array(temp.DebuggerServer.LONG_STRING_LENGTH + 1).join("a"),
|
||||
shortedString = longString.substring(0,
|
||||
temp.DebuggerServer.LONG_STRING_INITIAL_LENGTH
|
||||
) + "\u2026";
|
||||
tests.push({
|
||||
method: "display",
|
||||
code: "throw '" + longString + "';",
|
||||
result: "throw '" + longString + "';\n/*\nException: " + shortedString + "\n*/",
|
||||
label: "Correct exception message for a longString is shown"
|
||||
});
|
||||
|
||||
runAsyncTests(scratchpad, tests).then(function() {
|
||||
finish();
|
||||
});
|
||||
}
|
@ -652,7 +652,7 @@ WebConsoleActor.prototype =
|
||||
let evalResult = evalInfo.result;
|
||||
let helperResult = evalInfo.helperResult;
|
||||
|
||||
let result, error, errorMessage;
|
||||
let result, errorMessage, errorGrip = null;
|
||||
if (evalResult) {
|
||||
if ("return" in evalResult) {
|
||||
result = evalResult.return;
|
||||
@ -661,7 +661,8 @@ WebConsoleActor.prototype =
|
||||
result = evalResult.yield;
|
||||
}
|
||||
else if ("throw" in evalResult) {
|
||||
error = evalResult.throw;
|
||||
let error = evalResult.throw;
|
||||
errorGrip = this.createValueGrip(error);
|
||||
let errorToString = evalInfo.window
|
||||
.evalInGlobalWithBindings("ex + ''", {ex: error});
|
||||
if (errorToString && typeof errorToString.return == "string") {
|
||||
@ -675,7 +676,7 @@ WebConsoleActor.prototype =
|
||||
input: input,
|
||||
result: this.createValueGrip(result),
|
||||
timestamp: timestamp,
|
||||
exception: error ? this.createValueGrip(error) : null,
|
||||
exception: errorGrip,
|
||||
exceptionMessage: errorMessage,
|
||||
helperResult: helperResult,
|
||||
};
|
||||
|
@ -20,3 +20,4 @@ support-files =
|
||||
[test_object_actor_native_getters.html]
|
||||
[test_object_actor_native_getters_lenient_this.html]
|
||||
[test_page_errors.html]
|
||||
[test_throw.html]
|
||||
|
75
toolkit/devtools/webconsole/test/test_throw.html
Normal file
75
toolkit/devtools/webconsole/test/test_throw.html
Normal file
@ -0,0 +1,75 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>Web Console throw tests</title>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript;version=1.8" src="common.js"></script>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
</head>
|
||||
<body>
|
||||
<p>Web Console throw tests</p>
|
||||
|
||||
<script class="testbody" type="text/javascript;version=1.8">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function startTest()
|
||||
{
|
||||
removeEventListener("load", startTest);
|
||||
attachConsole([], onAttach, true);
|
||||
}
|
||||
|
||||
function onAttach(aState, aResponse)
|
||||
{
|
||||
let tests = [];
|
||||
|
||||
let falsyValues = ["-0", "null", "undefined", "Infinity", "-Infinity", "NaN"];
|
||||
falsyValues.forEach(function(value) {
|
||||
tests.push(function() {
|
||||
aState.client.evaluateJS("throw " + value + ";", function(aResponse) {
|
||||
let type = aResponse.exception.type;
|
||||
is(type, value, "exception.type for throw " + value);
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
let identityTestValues = [false, 0];
|
||||
identityTestValues.forEach(function(value) {
|
||||
tests.push(function() {
|
||||
aState.client.evaluateJS("throw " + value + ";", function(aResponse) {
|
||||
let exception = aResponse.exception;
|
||||
ise(exception, value, "response.exception for throw " + value);
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
let longString = Array(DebuggerServer.LONG_STRING_LENGTH + 1).join("a"),
|
||||
shortedString = longString.substring(0,
|
||||
DebuggerServer.LONG_STRING_INITIAL_LENGTH
|
||||
);
|
||||
tests.push(function() {
|
||||
aState.client.evaluateJS("throw '" + longString + "';", function(aResponse) {
|
||||
is(aResponse.exception.initial, shortedString,
|
||||
"exception.initial for throw longString"
|
||||
);
|
||||
nextTest();
|
||||
});
|
||||
});
|
||||
|
||||
runTests(tests, endTest.bind(null, aState));
|
||||
}
|
||||
|
||||
function endTest(aState)
|
||||
{
|
||||
closeDebugger(aState, function() {
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
|
||||
addEventListener("load", startTest);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user