browser_webconsole_strict_mode_errors.js (1416B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Check that "use strict" JS errors generate errors, not warnings. 5 6 "use strict"; 7 8 add_task(async function () { 9 const hud = await openNewTabAndConsole( 10 "data:text/html;charset=utf8,<!DOCTYPE html>empty page" 11 ); 12 13 await loadScriptURI("'use strict';var arguments;"); 14 await waitForError( 15 hud, 16 "SyntaxError: 'arguments' can't be defined or assigned to in strict mode code" 17 ); 18 19 await loadScriptURI("'use strict';function f(a, a) {};"); 20 await waitForError(hud, "SyntaxError: duplicate formal argument a"); 21 22 await loadScriptURI("'use strict';var o = {get p() {}};o.p = 1;"); 23 await waitForError(hud, 'TypeError: setting getter-only property "p"'); 24 25 await loadScriptURI("'use strict';v = 1;"); 26 await waitForError( 27 hud, 28 "ReferenceError: assignment to undeclared variable v" 29 ); 30 }); 31 32 async function waitForError(hud, text) { 33 await waitFor(() => findErrorMessage(hud, text)); 34 ok(true, "Received expected error message"); 35 } 36 37 function loadScriptURI(script) { 38 // On e10s, the exception is triggered in child process 39 // and is ignored by test harness 40 if (!Services.appinfo.browserTabsRemoteAutostart) { 41 expectUncaughtException(); 42 } 43 const uri = 44 "data:text/html;charset=utf8,<!DOCTYPE html><script>" + 45 script + 46 "</script>"; 47 return navigateTo(uri); 48 }