mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 22:40:28 +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)
66 lines
1.7 KiB
JavaScript
66 lines
1.7 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));
|
|
}
|
|
|
|
shouldBe(Reflect.has.length, 2);
|
|
|
|
shouldThrow(() => {
|
|
Reflect.has("hello", 42);
|
|
}, `TypeError: Reflect.has requires the first argument be an object`);
|
|
|
|
var object = { hello: 42 };
|
|
shouldBe(Reflect.has(object, 'hello'), true);
|
|
shouldBe(Reflect.has(object, 'world'), false);
|
|
shouldBe(Reflect.has(object, 'prototype'), false);
|
|
shouldBe(Reflect.has(object, '__proto__'), true);
|
|
shouldBe(Reflect.has(object, 'hasOwnProperty'), true);
|
|
shouldBe(Reflect.deleteProperty(object, 'hello'), true);
|
|
shouldBe(Reflect.has(object, 'hello'), false);
|
|
|
|
shouldBe(Reflect.has([], 'length'), true);
|
|
shouldBe(Reflect.has([0,1,2], 0), true);
|
|
shouldBe(Reflect.has([0,1,2], 200), false);
|
|
|
|
var object = {
|
|
[Symbol.iterator]: 42
|
|
};
|
|
shouldBe(Reflect.has(object, Symbol.iterator), true);
|
|
shouldBe(Reflect.has(object, Symbol.unscopables), false);
|
|
shouldBe(Reflect.deleteProperty(object, Symbol.iterator), true);
|
|
shouldBe(Reflect.has(object, Symbol.iterator), false);
|
|
|
|
var toPropertyKey = {
|
|
toString() {
|
|
throw new Error('toString called.');
|
|
}
|
|
};
|
|
|
|
shouldThrow(() => {
|
|
Reflect.has("hello", toPropertyKey);
|
|
}, `TypeError: Reflect.has requires the first argument be an object`);
|
|
|
|
shouldThrow(() => {
|
|
Reflect.has({}, toPropertyKey);
|
|
}, `Error: toString called.`);
|
|
|
|
var toPropertyKey = {
|
|
toString() {
|
|
return 'ok';
|
|
}
|
|
};
|
|
shouldBe(Reflect.has({ 'ok': 42 }, toPropertyKey), true);
|