mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +02:00
* [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)
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
function shouldBe(actual, expected) {
|
|
if (actual !== expected)
|
|
throw new Error('bad value: ' + actual);
|
|
}
|
|
|
|
function shouldThrow(func, message) {
|
|
var error = null;
|
|
try {
|
|
func();
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
if (!error)
|
|
throw new Error("not thrown.");
|
|
if (String(error) !== message)
|
|
throw new Error("bad error: " + String(error));
|
|
}
|
|
|
|
function shouldBeArray(actual, expected) {
|
|
shouldBe(actual.length, expected.length);
|
|
for (var i = 0; i < expected.length; ++i) {
|
|
try {
|
|
shouldBe(actual[i], expected[i]);
|
|
} catch(e) {
|
|
print(JSON.stringify(actual));
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
shouldBe(Reflect.ownKeys.length, 1);
|
|
|
|
shouldThrow(() => {
|
|
Reflect.ownKeys("hello");
|
|
}, `TypeError: Reflect.ownKeys requires the first argument be an object`);
|
|
|
|
var cocoa = Symbol("Cocoa");
|
|
var cappuccino = Symbol("Cappuccino");
|
|
|
|
shouldBeArray(Reflect.ownKeys({}), []);
|
|
shouldBeArray(Reflect.ownKeys({42:42}), ['42']);
|
|
shouldBeArray(Reflect.ownKeys({0:0,1:1,2:2}), ['0','1','2']);
|
|
shouldBeArray(Reflect.ownKeys({0:0,1:1,2:2,hello:42}), ['0','1','2','hello']);
|
|
shouldBeArray(Reflect.ownKeys({hello:42,0:0,1:1,2:2,world:42}), ['0','1','2','hello','world']);
|
|
shouldBeArray(Reflect.ownKeys({[cocoa]:42,hello:42,0:0,1:1,2:2,world:42}), ['0','1','2','hello','world', cocoa]);
|
|
shouldBeArray(Reflect.ownKeys({[cocoa]:42,hello:42,0:0,1:1,2:2,[cappuccino]:42,world:42}), ['0','1','2','hello','world', cocoa, cappuccino]);
|