test262/implementation-contributed/javascriptcore/stress/apply-second-argument-must-be-array-like.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

50 lines
1.2 KiB
JavaScript

//@ runDefault
function assert(x) {
if (!x)
throw Error("Bad");
}
function shouldThrow(expr) {
let testFunc = new Function(expr);
for (let i = 0; i < 10000; i++) {
let error;
try {
testFunc();
} catch (e) {
error = e;
}
assert(error);
}
}
function shouldNotThrow(expr) {
let testFunc = new Function(expr);
for (let i = 0; i < 10000; i++) {
let error;
try {
testFunc();
} catch (e) {
error = e;
}
assert(!error);
}
}
function foo() { }
shouldThrow("foo.apply(undefined, true)");
shouldThrow("foo.apply(undefined, false)");
shouldThrow("foo.apply(undefined, 100)");
shouldThrow("foo.apply(undefined, 123456789.12345)");
shouldThrow("foo.apply(undefined, 1.0/1.0)");
shouldThrow("foo.apply(undefined, 1.0/0)");
shouldThrow("foo.apply(undefined, 'hello')");
shouldThrow("foo.apply(undefined, Symbol())");
shouldNotThrow("foo.apply(undefined, undefined)");
shouldNotThrow("foo.apply(undefined, null)");
shouldNotThrow("foo.apply(undefined, {})");
shouldNotThrow("foo.apply(undefined, [])");
shouldNotThrow("foo.apply(undefined, function(){})");