test_javascript_object_actors.js (2591B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 7 registerCleanupFunction(() => { 8 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 9 }); 10 11 const { JSObjectsTestUtils, CONTEXTS } = ChromeUtils.importESModule( 12 "resource://testing-common/JSObjectsTestUtils.sys.mjs" 13 ); 14 JSObjectsTestUtils.init(this); 15 16 const EXPECTED_VALUES_FILE = "test_javascript_object_actors.snapshot.mjs"; 17 18 /** 19 * This test will run `test` function twice. 20 * Once replicating a page debugging, and a second time replicating a worker debugging environment 21 */ 22 add_task( 23 threadFrontTest( 24 async function test({ threadFront, debuggee, _isWorkerServer }) { 25 await JSObjectsTestUtils.runTest( 26 EXPECTED_VALUES_FILE, 27 async function ({ context, expression }) { 28 // Only support basic JS Values 29 if (context != CONTEXTS.JS) { 30 return undefined; 31 } 32 33 // Create the function that the privileged code will call to pause 34 // from executeOnNextTickAndWaitForPause callback 35 debuggee.eval(`function stopMe(arg) { debugger; }`); 36 37 const packet = await executeOnNextTickAndWaitForPause(async () => { 38 let value; 39 try { 40 value = debuggee.eval(expression); 41 } catch (e) { 42 value = e; 43 } 44 45 // Catch all async rejection to avoid unecessary error reports 46 if (value instanceof debuggee.Promise) { 47 // eslint-disable-next-line max-nested-callbacks 48 value.catch(function () {}); 49 } 50 51 debuggee.stopMe(value); 52 }, threadFront); 53 54 const firstArg = packet.frame.arguments[0]; 55 56 await threadFront.resume(); 57 58 // Avoid storing any actor ID as it may not be super stable 59 stripActorIDs(firstArg); 60 61 return firstArg; 62 } 63 ); // End of runTest 64 }, 65 66 // Use a content principal to better reflect evaluating into a web page, 67 // but also to ensure seeing the stack trace of exception only within the sandbox 68 // and especially not see the test harness ones, which are privileged. 69 { principal: "https://example.org" } 70 ) // End of threadFrontTest 71 ); 72 73 function stripActorIDs(obj) { 74 for (const name in obj) { 75 if (name == "actor") { 76 obj[name] = "<actor-id>"; 77 } 78 if (typeof obj[name] == "object") { 79 stripActorIDs(obj[name]); 80 } 81 } 82 }