test_xrayed_iterator.js (1086B)
1 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 2 registerCleanupFunction(() => { 3 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 4 }); 5 6 function run_test() { 7 8 var toEval = [ 9 "var customIterator = {", 10 " _array: [6, 7, 8, 9]", 11 "};", 12 "customIterator[Symbol.iterator] = function* () {", 13 " for (var i = 0; i < this._array.length; ++i)", 14 " yield this._array[i];", 15 "};" 16 ].join('\n'); 17 18 function checkIterator(iterator) { 19 var control = [6, 7, 8, 9]; 20 var i = 0; 21 for (var item of iterator) { 22 Assert.equal(item, control[i]); 23 ++i; 24 } 25 } 26 27 // First, try in our own scope. 28 eval(toEval); 29 checkIterator(customIterator); 30 31 // Next, try a vanilla CCW. 32 var sbChrome = Cu.Sandbox(this); 33 Cu.evalInSandbox(toEval, sbChrome, '1.7'); 34 checkIterator(sbChrome.customIterator); 35 36 // Finally, try an Xray waiver. 37 var sbContent = Cu.Sandbox('http://www.example.com'); 38 Cu.evalInSandbox(toEval, sbContent, '1.7'); 39 checkIterator(Cu.waiveXrays(sbContent.customIterator)); 40 }