mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Implement Object(value) constructor
Not sure why we didn't have this yet, it's super simple :^)
This commit is contained in:
parent
501cef2bd7
commit
2645dfafcf
Notes:
sideshowbarker
2024-07-19 01:33:11 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/2645dfafcfe Pull-request: https://github.com/SerenityOS/serenity/pull/3949 Issue: https://github.com/SerenityOS/serenity/issues/3947
2 changed files with 9 additions and 1 deletions
|
@ -66,7 +66,10 @@ ObjectConstructor::~ObjectConstructor()
|
|||
|
||||
Value ObjectConstructor::call()
|
||||
{
|
||||
return Object::create_empty(global_object());
|
||||
auto value = vm().argument(0);
|
||||
if (value.is_nullish())
|
||||
return Object::create_empty(global_object());
|
||||
return value.to_object(global_object());
|
||||
}
|
||||
|
||||
Value ObjectConstructor::construct(Function&)
|
||||
|
|
|
@ -5,4 +5,9 @@ test("basic functionality", () => {
|
|||
|
||||
expect(typeof Object()).toBe("object");
|
||||
expect(typeof new Object()).toBe("object");
|
||||
|
||||
expect(typeof Object(42)).toBe("object");
|
||||
expect(Object(42).valueOf()).toBe(42);
|
||||
expect(typeof Object("foo")).toBe("object");
|
||||
expect(Object("foo").valueOf()).toBe("foo");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue