LibJS: Implement most of the Reflect object

This commit is contained in:
Linus Groh 2020-05-01 11:06:27 +01:00 committed by Andreas Kling
parent 1ba2e6768d
commit 79b829637e
Notes: sideshowbarker 2024-07-19 07:08:14 +09:00
22 changed files with 877 additions and 54 deletions

View file

@ -0,0 +1,54 @@
load("test-common.js");
try {
assert(Reflect.construct.length === 2);
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
assertThrowsError(() => {
Reflect.construct(value);
}, {
error: TypeError,
message: "First argument of Reflect.construct() must be a function"
});
assertThrowsError(() => {
Reflect.construct(() => {}, value);
}, {
error: TypeError,
message: "Arguments list must be an object"
});
assertThrowsError(() => {
Reflect.construct(() => {}, [], value);
}, {
error: TypeError,
message: "Optional third argument of Reflect.construct() must be a constructor"
});
});
var a = Reflect.construct(Array, [5]);
assert(a instanceof Array);
assert(a.length === 5);
var s = Reflect.construct(String, [123]);
assert(s instanceof String);
assert(s.length === 3);
assert(s.toString() === "123");
function Foo() {
this.name = "foo";
}
function Bar() {
this.name = "bar";
}
var o = Reflect.construct(Foo, [], Bar);
assert(o.name === "foo");
assert(o instanceof Foo === false);
assert(o instanceof Bar === true);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}