test262/implementation-contributed/javascriptcore/stress/to-number-throws-correct-exception.js
test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

122 lines
3.1 KiB
JavaScript

function test(op) {
let test = `
function runTest(iters) {
let shouldThrow = false;
let a = {
valueOf() {
if (shouldThrow)
throw "a";
return 0;
}
};
let {proxy: b, revoke} = Proxy.revocable({}, {
get: function(target, prop) {
if (prop === "valueOf") {
if (shouldThrow)
throw new Error("Should not be here!");
return function() {
return 0;
}
}
}
});
function f(a, b) {
return a ${op} b;
}
noInline(f);
for (let i = 0; i < iters; i++) {
f(a, b);
}
shouldThrow = true;
let validException = false;
let exception = null;
revoke();
try {
f(a, b);
} catch(e) {
validException = e === "a";
exception = e;
}
if (!validException)
throw new Error("Bad operation: " + exception.toString() + " with iters: " + iters);
}
runTest(2);
runTest(10);
runTest(50);
runTest(1000);
runTest(10000);
`;
eval(test);
}
let ops = [
"+"
, "-"
, "*"
, "**"
, "/"
, "%"
, "&"
, "|"
, "^"
, ">>"
, ">>>"
, "<<"
];
for (let op of ops)
test(op);
function test2(op) {
function runTest(iters) {
let test = `
let shouldThrow = false;
let a = {
valueOf() {
if (shouldThrow)
throw "a";
return 0;
}
};
let {proxy: b, revoke} = Proxy.revocable({}, {
get: function(target, prop) {
if (prop === "valueOf") {
if (shouldThrow)
throw new Error("Should not be here!");
return function() {
return 0;
}
}
}
});
function f(a, b) {
return a ${op} b;
}
noInline(f);
for (let i = 0; i < ${iters}; i++) {
f(a, b);
}
shouldThrow = true;
let validException = false;
let exception = null;
revoke();
try {
f(a, b);
} catch(e) {
validException = e === "a";
exception = e;
}
if (!validException)
throw new Error("Bad operation: " + exception.toString() + " with iters: " + ${iters});
`;
eval(Math.random() + ";" + test);
}
runTest(2);
runTest(10);
runTest(50);
runTest(1000);
runTest(10000);
}
for (let op of ops)
test2(op);