diff options
Diffstat (limited to 'devtools/client/webconsole/test/browser/browser_webconsole_strict_mode_errors.js')
-rw-r--r-- | devtools/client/webconsole/test/browser/browser_webconsole_strict_mode_errors.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_strict_mode_errors.js b/devtools/client/webconsole/test/browser/browser_webconsole_strict_mode_errors.js new file mode 100644 index 0000000000..0894f4f6df --- /dev/null +++ b/devtools/client/webconsole/test/browser/browser_webconsole_strict_mode_errors.js @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Check that "use strict" JS errors generate errors, not warnings. + +"use strict"; + +add_task(async function () { + const hud = await openNewTabAndConsole( + "data:text/html;charset=utf8,<!DOCTYPE html>empty page" + ); + + await loadScriptURI("'use strict';var arguments;"); + await waitForError( + hud, + "SyntaxError: 'arguments' can't be defined or assigned to in strict mode code" + ); + + await loadScriptURI("'use strict';function f(a, a) {};"); + await waitForError(hud, "SyntaxError: duplicate formal argument a"); + + await loadScriptURI("'use strict';var o = {get p() {}};o.p = 1;"); + await waitForError(hud, 'TypeError: setting getter-only property "p"'); + + await loadScriptURI("'use strict';v = 1;"); + await waitForError( + hud, + "ReferenceError: assignment to undeclared variable v" + ); +}); + +async function waitForError(hud, text) { + await waitFor(() => findErrorMessage(hud, text)); + ok(true, "Received expected error message"); +} + +function loadScriptURI(script) { + // On e10s, the exception is triggered in child process + // and is ignored by test harness + if (!Services.appinfo.browserTabsRemoteAutostart) { + expectUncaughtException(); + } + const uri = + "data:text/html;charset=utf8,<!DOCTYPE html><script>" + + script + + "</script>"; + return navigateTo(uri); +} |