browser_script_command_execute_throw.js (2140B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Testing evaluating thowing expressions 7 const { 8 DevToolsServer, 9 } = require("resource://devtools/server/devtools-server.js"); 10 11 add_task(async () => { 12 const tab = await addTab(`data:text/html;charset=utf-8,Test throw`); 13 const commands = await CommandsFactory.forTab(tab); 14 await commands.targetCommand.startListening(); 15 16 const falsyValues = [ 17 "-0", 18 "null", 19 "undefined", 20 "Infinity", 21 "-Infinity", 22 "NaN", 23 ]; 24 for (const value of falsyValues) { 25 const response = await commands.scriptCommand.execute(`throw ${value};`); 26 is( 27 response.exception.type, 28 value, 29 `Got the expected value for response.exception.type when throwing "${value}"` 30 ); 31 } 32 33 const identityTestValues = [false, 0]; 34 for (const value of identityTestValues) { 35 const response = await commands.scriptCommand.execute(`throw ${value};`); 36 is( 37 response.exception, 38 value, 39 `Got the expected value for response.exception when throwing "${value}"` 40 ); 41 } 42 43 const symbolTestValues = [ 44 ["Symbol.iterator", "Symbol(Symbol.iterator)"], 45 ["Symbol('foo')", "Symbol(foo)"], 46 ["Symbol()", "Symbol()"], 47 ]; 48 for (const [expr, message] of symbolTestValues) { 49 const response = await commands.scriptCommand.execute(`throw ${expr};`); 50 is( 51 response.exceptionMessage, 52 message, 53 `Got the expected value for response.exceptionMessage when throwing "${expr}"` 54 ); 55 } 56 57 const longString = Array(DevToolsServer.LONG_STRING_LENGTH + 1).join("a"), 58 shortedString = longString.substring( 59 0, 60 DevToolsServer.LONG_STRING_INITIAL_LENGTH 61 ); 62 const response = await commands.scriptCommand.execute( 63 "throw '" + longString + "';" 64 ); 65 is( 66 response.exception.initial, 67 shortedString, 68 "Got the expected value for exception.initial when throwing a longString" 69 ); 70 is( 71 response.exceptionMessage.initial, 72 shortedString, 73 "Got the expected value for exceptionMessage.initial when throwing a longString" 74 ); 75 });