test_objectgrips-18.js (5661B)
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 add_task( 12 threadFrontTest(async ({ threadFront, debuggee }) => { 13 const packet = await executeOnNextTickAndWaitForPause( 14 eval_code, 15 threadFront 16 ); 17 18 const [grip] = packet.frame.arguments; 19 20 const objectFront = threadFront.pauseGrip(grip); 21 22 // Checks the result of enumProperties. 23 let response = await objectFront.enumProperties({}); 24 await check_enum_properties(response); 25 26 // Checks the result of enumSymbols. 27 response = await objectFront.enumSymbols(); 28 await check_enum_symbols(response); 29 30 await threadFront.resume(); 31 32 function eval_code() { 33 debuggee.eval( 34 // These arguments are tested. 35 // eslint-disable-next-line no-unused-vars 36 function stopMe(arg1) { 37 debugger; 38 }.toString() 39 ); 40 41 debuggee.eval(` 42 var obj = Array.from({length: 10}) 43 .reduce((res, _, i) => { 44 res["property_" + i + "_key"] = "property_" + i + "_value"; 45 res[Symbol("symbol_" + i)] = "symbol_" + i + "_value"; 46 return res; 47 }, {}); 48 49 obj[Symbol()] = "first unnamed symbol"; 50 obj[Symbol()] = "second unnamed symbol"; 51 obj[Symbol.iterator] = function* () { 52 yield 1; 53 yield 2; 54 }; 55 56 stopMe(obj); 57 `); 58 } 59 60 async function check_enum_properties(iterator) { 61 equal(iterator.count, 10, "iterator.count has the expected value"); 62 63 info("Check iterator.slice response for all properties"); 64 let sliceResponse = await iterator.slice(0, iterator.count); 65 ok( 66 sliceResponse && 67 Object.getOwnPropertyNames(sliceResponse).includes("ownProperties"), 68 "The response object has an ownProperties property" 69 ); 70 71 let { ownProperties } = sliceResponse; 72 let names = Object.keys(ownProperties); 73 equal( 74 names.length, 75 iterator.count, 76 "The response has the expected number of properties" 77 ); 78 for (let i = 0; i < names.length; i++) { 79 const name = names[i]; 80 equal(name, `property_${i}_key`); 81 equal(ownProperties[name].value, `property_${i}_value`); 82 } 83 84 info("Check iterator.all response"); 85 const allResponse = await iterator.all(); 86 deepEqual( 87 allResponse, 88 sliceResponse, 89 "iterator.all response has the expected data" 90 ); 91 92 info("Check iterator response for 2 properties only"); 93 sliceResponse = await iterator.slice(2, 2); 94 ok( 95 sliceResponse && 96 Object.getOwnPropertyNames(sliceResponse).includes("ownProperties"), 97 "The response object has an ownProperties property" 98 ); 99 100 ownProperties = sliceResponse.ownProperties; 101 names = Object.keys(ownProperties); 102 equal( 103 names.length, 104 2, 105 "The response has the expected number of properties" 106 ); 107 equal(names[0], `property_2_key`); 108 equal(names[1], `property_3_key`); 109 equal(ownProperties[names[0]].value, `property_2_value`); 110 equal(ownProperties[names[1]].value, `property_3_value`); 111 } 112 113 async function check_enum_symbols(iterator) { 114 equal(iterator.count, 13, "iterator.count has the expected value"); 115 116 info("Check iterator.slice response for all symbols"); 117 let sliceResponse = await iterator.slice(0, iterator.count); 118 ok( 119 sliceResponse && 120 Object.getOwnPropertyNames(sliceResponse).includes("ownSymbols"), 121 "The response object has an ownSymbols property" 122 ); 123 124 let { ownSymbols } = sliceResponse; 125 equal( 126 ownSymbols.length, 127 iterator.count, 128 "The response has the expected number of symbols" 129 ); 130 for (let i = 0; i < 10; i++) { 131 const symbol = ownSymbols[i]; 132 equal(symbol.name, `Symbol(symbol_${i})`); 133 equal(symbol.descriptor.value, `symbol_${i}_value`); 134 } 135 const firstUnnamedSymbol = ownSymbols[10]; 136 equal(firstUnnamedSymbol.name, "Symbol()"); 137 equal(firstUnnamedSymbol.descriptor.value, "first unnamed symbol"); 138 139 const secondUnnamedSymbol = ownSymbols[11]; 140 equal(secondUnnamedSymbol.name, "Symbol()"); 141 equal(secondUnnamedSymbol.descriptor.value, "second unnamed symbol"); 142 143 const iteratorSymbol = ownSymbols[12]; 144 equal(iteratorSymbol.name, "Symbol(Symbol.iterator)"); 145 equal(iteratorSymbol.descriptor.value.getGrip().class, "Function"); 146 147 info("Check iterator.all response"); 148 const allResponse = await iterator.all(); 149 deepEqual( 150 allResponse, 151 sliceResponse, 152 "iterator.all response has the expected data" 153 ); 154 155 info("Check iterator response for 2 symbols only"); 156 sliceResponse = await iterator.slice(9, 2); 157 ok( 158 sliceResponse && 159 Object.getOwnPropertyNames(sliceResponse).includes("ownSymbols"), 160 "The response object has an ownSymbols property" 161 ); 162 163 ownSymbols = sliceResponse.ownSymbols; 164 equal( 165 ownSymbols.length, 166 2, 167 "The response has the expected number of symbols" 168 ); 169 equal(ownSymbols[0].name, "Symbol(symbol_9)"); 170 equal(ownSymbols[0].descriptor.value, "symbol_9_value"); 171 equal(ownSymbols[1].name, "Symbol()"); 172 equal(ownSymbols[1].descriptor.value, "first unnamed symbol"); 173 } 174 }) 175 );