| 1 |
// |jit-test| skip-if: !(getBuildConfiguration('debug')||getBuildConfiguration('fuzzing-defined')) |
| 2 |
|
| 3 |
function intact(name) { |
| 4 |
let state = getFuseState(); |
| 5 |
if (!(name in state)) { |
| 6 |
throw "No such fuse " + name; |
| 7 |
} |
| 8 |
return state[name].intact |
| 9 |
} |
| 10 |
|
| 11 |
function testRealmChange() { |
| 12 |
let g = newGlobal(); |
| 13 |
g.evaluate(intact.toString()) |
| 14 |
|
| 15 |
// Get a mutating function which will affect the symbol.iterator fuse. |
| 16 |
let rdel = g.evaluate("function del(o) { delete o.prototype[Symbol.iterator] };del") |
| 17 |
// Fuse is still intact. |
| 18 |
g.evaluate(`assertEq(intact("ArrayPrototypeIteratorFuse"), true)`); |
| 19 |
|
| 20 |
// setup a new global, |
| 21 |
let g2 = newGlobal(); |
| 22 |
g2.evaluate(intact.toString()) |
| 23 |
|
| 24 |
// register the popping function. |
| 25 |
g2.rdel = rdel; |
| 26 |
|
| 27 |
// Pop the array fuse in the new global. |
| 28 |
g2.evaluate(`rdel(Array)`); |
| 29 |
|
| 30 |
// The realm of the original array should have a fuse still intact |
| 31 |
g.evaluate(`assertEq(intact("ArrayPrototypeIteratorFuse"), true)`); |
| 32 |
|
| 33 |
// The realm of the array proto should no longer be intact. Oh dear. This is |
| 34 |
// interesting. We currently ask the cx for the array iterator proto, |
| 35 |
g2.evaluate(`assertEq(intact("ArrayPrototypeIteratorFuse"), false)`); |
| 36 |
} |
| 37 |
|
| 38 |
testRealmChange(); |
| 39 |
|
| 40 |
function testInNewGlobal(pre, post) { |
| 41 |
g = newGlobal(); |
| 42 |
g.evaluate(intact.toString()); |
| 43 |
g.evaluate(pre) |
| 44 |
g.evaluate("assertRealmFuseInvariants()"); |
| 45 |
g.evaluate(post); |
| 46 |
} |
| 47 |
|
| 48 |
testInNewGlobal("delete Array.prototype[Symbol.iterator]", `assertEq(intact("ArrayPrototypeIteratorFuse"), false)`) |
| 49 |
testInNewGlobal("([])[Symbol.iterator]().__proto__['return'] = () => 10;", `assertEq(intact("ArrayIteratorPrototypeHasNoReturnProperty"), false)`) |
| 50 |
testInNewGlobal("([])[Symbol.iterator]().__proto__.__proto__['return'] = () => 10;", `assertEq(intact("IteratorPrototypeHasNoReturnProperty"), false)`) |
| 51 |
testInNewGlobal("Object.prototype['return'] = () => 10;", `assertEq(intact("ObjectPrototypeHasNoReturnProperty"), false)`) |
| 52 |
testInNewGlobal(`assertEq(intact("ArrayIteratorPrototypeHasIteratorProto"), true); Object.setPrototypeOf(( ([])[Symbol.iterator]().__proto__ ), {a:10})`, `assertEq(intact("ArrayIteratorPrototypeHasIteratorProto"), false);`); |
| 53 |
testInNewGlobal(`assertEq(intact("IteratorPrototypeHasObjectProto"), true); Object.setPrototypeOf( ( ([])[Symbol.iterator]().__proto__.__proto__ ), {a:10})`, `assertEq(intact("IteratorPrototypeHasObjectProto"), false);`); |
| 54 |
|
| 55 |
testInNewGlobal(`assertEq(intact("hasSeenObjectEmulateUndefinedFuse"), true); createIsHTMLDDA()`, `assertEq(intact("hasSeenObjectEmulateUndefinedFuse"), false);`); |
| 56 |
testInNewGlobal(`assertEq(intact("hasSeenArrayExceedsInt32LengthFuse"), true); const x = []; x[2147483649] = 1`, `assertEq(intact("hasSeenArrayExceedsInt32LengthFuse"), false);`); |
| 57 |
|
| 58 |
// Runtime wide fuse. |
| 59 |
assertEq(intact("hasSeenObjectEmulateUndefinedFuse"), false); |
| 60 |
assertEq(intact("hasSeenArrayExceedsInt32LengthFuse"), false); |