test_objectgrips-25.js (3251B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test object with private properties (preview + enumPrivateProperties) 5 6 "use strict"; 7 8 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 9 registerCleanupFunction(() => { 10 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 11 }); 12 13 function evalCode(debuggee) { 14 debuggee.eval( 15 // These arguments are tested. 16 // eslint-disable-next-line no-unused-vars 17 function stopMe(obj) { 18 debugger; 19 }.toString() 20 ); 21 debuggee.eval(` 22 class MyClass { 23 constructor(name, password) { 24 this.name = name; 25 this.#password = password; 26 } 27 28 #password; 29 #salt = "sEcr3t"; 30 #getSaltedPassword() { 31 return this.#password + this.#salt; 32 } 33 } 34 35 stopMe(new MyClass("Susie", "p4$$w0rD")); 36 `); 37 } 38 39 add_task( 40 threadFrontTest(async ({ threadFront, debuggee }) => { 41 const packet = await executeOnNextTickAndWaitForPause( 42 () => evalCode(debuggee), 43 threadFront 44 ); 45 46 const [grip] = packet.frame.arguments; 47 48 let { privateProperties } = grip.preview; 49 strictEqual( 50 privateProperties.length, 51 2, 52 "There is 2 private properties in the grip preview" 53 ); 54 let [password, salt] = privateProperties; 55 56 strictEqual( 57 password.name, 58 "#password", 59 "Got expected name for #password private property in preview" 60 ); 61 deepEqual( 62 password.descriptor, 63 { 64 configurable: true, 65 enumerable: false, 66 writable: true, 67 value: "p4$$w0rD", 68 }, 69 "Got expected property descriptor for #password in preview" 70 ); 71 72 strictEqual( 73 salt.name, 74 "#salt", 75 "Got expected name for #salt private property in preview" 76 ); 77 deepEqual( 78 salt.descriptor, 79 { 80 configurable: true, 81 enumerable: false, 82 writable: true, 83 value: "sEcr3t", 84 }, 85 "Got expected property descriptor for #salt in preview" 86 ); 87 88 const objClient = threadFront.pauseGrip(grip); 89 const iterator = await objClient.enumPrivateProperties(); 90 ({ privateProperties } = await iterator.slice(0, iterator.count)); 91 92 strictEqual( 93 privateProperties.length, 94 2, 95 "enumPrivateProperties returned 2 private properties." 96 ); 97 [password, salt] = privateProperties; 98 99 strictEqual( 100 password.name, 101 "#password", 102 "Got expected name for #password private property via enumPrivateProperties" 103 ); 104 deepEqual( 105 password.descriptor, 106 { 107 configurable: true, 108 enumerable: false, 109 writable: true, 110 value: "p4$$w0rD", 111 }, 112 "Got expected property descriptor for #password via enumPrivateProperties" 113 ); 114 115 strictEqual( 116 salt.name, 117 "#salt", 118 "Got expected name for #salt private property via enumPrivateProperties" 119 ); 120 deepEqual( 121 salt.descriptor, 122 { 123 configurable: true, 124 enumerable: false, 125 writable: true, 126 value: "sEcr3t", 127 }, 128 "Got expected property descriptor for #salt via enumPrivateProperties" 129 ); 130 131 await threadFront.resume(); 132 }) 133 );