forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some lingering POE + Exception bugs (firefox-devtools#4225)
- Loading branch information
1 parent
49371c3
commit 7aa646d
Showing
13 changed files
with
237 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
* http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
|
||
/** | ||
* test pausing on an errored watch expression | ||
* assert that you can: | ||
* 1. resume | ||
* 2. still evalutate expressions | ||
* 3. expand properties | ||
*/ | ||
|
||
const expressionSelectors = { | ||
input: "input.input-expression" | ||
}; | ||
|
||
function getLabel(dbg, index) { | ||
return findElement(dbg, "expressionNode", index).innerText; | ||
} | ||
|
||
function getValue(dbg, index) { | ||
return findElement(dbg, "expressionValue", index).innerText; | ||
} | ||
|
||
function assertEmptyValue(dbg, index) { | ||
const value = findElement(dbg, "expressionValue", index); | ||
if (value) { | ||
is(value.innerText, ""); | ||
return; | ||
} | ||
|
||
is(value, null); | ||
} | ||
|
||
function toggleExpression(dbg, index) { | ||
findElement(dbg, "expressionNode", index).click(); | ||
} | ||
|
||
async function addExpression(dbg, input) { | ||
info("Adding an expression"); | ||
findElementWithSelector(dbg, expressionSelectors.input).focus(); | ||
type(dbg, input); | ||
pressKey(dbg, "Enter"); | ||
|
||
await waitForDispatch(dbg, "EVALUATE_EXPRESSION"); | ||
} | ||
|
||
async function editExpression(dbg, input) { | ||
info("updating the expression"); | ||
dblClickElement(dbg, "expressionNode", 1); | ||
// Position cursor reliably at the end of the text. | ||
pressKey(dbg, "End"); | ||
type(dbg, input); | ||
pressKey(dbg, "Enter"); | ||
await waitForDispatch(dbg, "EVALUATE_EXPRESSION"); | ||
} | ||
|
||
/* | ||
* When we add a bad expression, we'll pause, | ||
* resume, and wait for the expression to finish being evaluated. | ||
*/ | ||
async function addBadExpression(dbg, input) { | ||
const paused = waitForPaused(dbg); | ||
const added = addExpression(dbg, input); | ||
|
||
await paused; | ||
ok(dbg.selectors.isEvaluatingExpression(dbg.getState())); | ||
await resume(dbg); | ||
await added; | ||
} | ||
|
||
add_task(async function() { | ||
const dbg = await initDebugger("doc-script-switching.html"); | ||
|
||
await togglePauseOnExceptions(dbg, true, false); | ||
|
||
// add a good expression, 2 bad expressions, and another good one | ||
await addExpression(dbg, "location"); | ||
await addBadExpression(dbg, "foo.bar"); | ||
await addBadExpression(dbg, "foo.batt"); | ||
await addExpression(dbg, "2"); | ||
|
||
// check the value of | ||
is(getValue(dbg, 2), "(unavailable)"); | ||
is(getValue(dbg, 3), "(unavailable)"); | ||
is(getValue(dbg, 4), 2); | ||
|
||
toggleExpression(dbg, 1); | ||
await waitForDispatch(dbg, "LOAD_OBJECT_PROPERTIES"); | ||
is(findAllElements(dbg, "expressionNodes").length, 20); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function getIndentation(lines) { | ||
const firstLine = lines[0]; | ||
const secondLine = lines[1]; | ||
const lastLine = lines[lines.length - 1]; | ||
|
||
const _getIndentation = line => line && line.match(/^\s*/)[0].length; | ||
|
||
const indentations = [ | ||
_getIndentation(firstLine), | ||
_getIndentation(secondLine), | ||
_getIndentation(lastLine) | ||
]; | ||
|
||
return Math.max(...indentations); | ||
} | ||
|
||
export function correctIndentation(text) { | ||
const lines = text.trim().split("\n"); | ||
const indentation = getIndentation(lines); | ||
const formattedLines = lines.map(_line => | ||
_line.replace(new RegExp(`^\\s{0,${indentation - 1}}`), "") | ||
); | ||
|
||
return formattedLines.join("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`expressions wrap exxpression should wrap an expression 1`] = ` | ||
"eval(\` | ||
try { | ||
foo | ||
} catch (e) { | ||
e | ||
} | ||
\`)" | ||
"try { | ||
foo | ||
} catch (e) { | ||
e | ||
}" | ||
`; | ||
|
||
exports[`expressions wrap exxpression should wrap expression with a comment 1`] = ` | ||
"eval(\` | ||
try { | ||
foo // yo yo | ||
} catch (e) { | ||
e | ||
} | ||
\`)" | ||
"try { | ||
foo // yo yo | ||
} catch (e) { | ||
e | ||
}" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`indentation mad indentation 1`] = ` | ||
"try { | ||
console.log(\\"yo\\") | ||
} catch (e) { | ||
console.log(\\"yo\\") | ||
}" | ||
`; | ||
|
||
exports[`indentation one function 1`] = ` | ||
"function foo() { | ||
console.log(\\"yo\\") | ||
}" | ||
`; | ||
|
||
exports[`indentation one line 1`] = `"foo"`; | ||
|
||
exports[`indentation simple 1`] = `"foo"`; | ||
|
||
exports[`indentation try catch 1`] = ` | ||
"try { | ||
console.log(\\"yo\\") | ||
} catch (e) { | ||
console.log(\\"yo\\") | ||
}" | ||
`; |
Oops, something went wrong.