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