mirror of
https://github.com/tc39/test262.git
synced 2025-05-04 06:50:32 +02:00
61 lines
1.2 KiB
JavaScript
61 lines
1.2 KiB
JavaScript
function shouldBe(actual, expected) {
|
|
if (actual !== expected)
|
|
throw new Error('bad value: ' + actual);
|
|
}
|
|
|
|
function shouldThrow(func, errorMessage) {
|
|
var errorThrown = false;
|
|
var error = null;
|
|
try {
|
|
func();
|
|
} catch (e) {
|
|
errorThrown = true;
|
|
error = e;
|
|
}
|
|
if (!errorThrown)
|
|
throw new Error('not thrown');
|
|
if (String(error) !== errorMessage)
|
|
throw new Error(`bad error: ${String(error)}`);
|
|
}
|
|
|
|
shouldThrow(() => {
|
|
Function("@", { toString() { throw 42; } })
|
|
}, `42`);
|
|
|
|
var counter = 0;
|
|
class Parameter {
|
|
constructor(index)
|
|
{
|
|
this.index = index;
|
|
}
|
|
|
|
toString() {
|
|
shouldBe(this.index, counter);
|
|
counter++;
|
|
return `x${this.index}`;
|
|
}
|
|
};
|
|
|
|
class Body {
|
|
constructor(index)
|
|
{
|
|
this.index = index;
|
|
}
|
|
|
|
toString() {
|
|
shouldBe(this.index, counter);
|
|
counter++;
|
|
return `42`;
|
|
}
|
|
};
|
|
|
|
var parameters = [];
|
|
for (var i = 0; i < 50; ++i) {
|
|
parameters.push(new Parameter(parameters.length));
|
|
var args = parameters.slice();
|
|
args.push(new Body(args.length));
|
|
counter = 0;
|
|
Function.apply(this, args);
|
|
shouldBe(counter, args.length);
|
|
}
|