mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 07:48:47 +00:00
LibJS: Implement most of the Reflect object
This commit is contained in:
parent
1ba2e6768d
commit
79b829637e
Notes:
sideshowbarker
2024-07-19 07:08:14 +09:00
Author: https://github.com/linusg
Commit: 79b829637e
Pull-request: https://github.com/SerenityOS/serenity/pull/2047
Reviewed-by: https://github.com/awesomekling
22 changed files with 877 additions and 54 deletions
54
Libraries/LibJS/Tests/Reflect.construct.js
Normal file
54
Libraries/LibJS/Tests/Reflect.construct.js
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue