| 1 |
setJitCompilerOption("ion.warmup.trigger", 4); |
| 2 |
|
| 3 |
function testBasic() { |
| 4 |
var f = function() { |
| 5 |
var result = "abc".match("b"); |
| 6 |
assertEq(result.length, 1); |
| 7 |
assertEq(result.index, 1); |
| 8 |
assertEq(result[0], "b"); |
| 9 |
}; |
| 10 |
for (var i = 0; i < 40; i++) { |
| 11 |
f(); |
| 12 |
} |
| 13 |
} |
| 14 |
testBasic(); |
| 15 |
|
| 16 |
function testMod(apply, unapply) { |
| 17 |
var f = function(applied) { |
| 18 |
var result = "abc".match("b"); |
| 19 |
assertEq(result.length, 1); |
| 20 |
if (applied) { |
| 21 |
assertEq(result[0], "mod"); |
| 22 |
} else { |
| 23 |
assertEq(result.index, 1); |
| 24 |
assertEq(result[0], "b"); |
| 25 |
} |
| 26 |
}; |
| 27 |
var applied = false; |
| 28 |
for (var i = 0; i < 120; i++) { |
| 29 |
f(applied); |
| 30 |
if (i == 40) { |
| 31 |
apply(); |
| 32 |
applied = true; |
| 33 |
} |
| 34 |
if (i == 80) { |
| 35 |
unapply(); |
| 36 |
applied = false; |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
testMod(() => { |
| 41 |
String.prototype[Symbol.match] = () => ["mod"]; |
| 42 |
}, () => { |
| 43 |
delete String.prototype[Symbol.match]; |
| 44 |
}); |
| 45 |
testMod(() => { |
| 46 |
Object.prototype[Symbol.match] = () => ["mod"]; |
| 47 |
}, () => { |
| 48 |
delete Object.prototype[Symbol.match]; |
| 49 |
}); |
| 50 |
|
| 51 |
testMod(() => { |
| 52 |
Object.setPrototypeOf(String.prototype, { |
| 53 |
[Symbol.match]: () => ["mod"] |
| 54 |
}); |
| 55 |
}, () => { |
| 56 |
Object.setPrototypeOf(String.prototype, Object.prototype); |
| 57 |
}); |
| 58 |
|
| 59 |
var orig_exec = RegExp.prototype.exec; |
| 60 |
testMod(() => { |
| 61 |
RegExp.prototype.exec = () => ["mod"]; |
| 62 |
}, () => { |
| 63 |
RegExp.prototype.exec = orig_exec; |
| 64 |
}); |
| 65 |
|
| 66 |
var orig_match = RegExp.prototype[Symbol.match]; |
| 67 |
testMod(() => { |
| 68 |
RegExp.prototype[Symbol.match] = () => ["mod"]; |
| 69 |
}, () => { |
| 70 |
RegExp.prototype[Symbol.match] = orig_match; |
| 71 |
}); |