summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-11-04 21:13:07 +0000
committerAndreas Kling <kling@serenityos.org>2020-11-04 23:06:44 +0100
commit2645dfafcfe52c3ef3556cadca55fb7697e2627d (patch)
tree75c0ecc5f7fc863c8efbacbed3791fba3be646fc
parent501cef2bd70a22e8eb9d0ee81c5931d0561e47e7 (diff)
downloadserenity-2645dfafcfe52c3ef3556cadca55fb7697e2627d.zip
LibJS: Implement Object(value) constructor
Not sure why we didn't have this yet, it's super simple :^)
-rw-r--r--Libraries/LibJS/Runtime/ObjectConstructor.cpp5
-rw-r--r--Libraries/LibJS/Tests/builtins/Object/Object.js5
2 files changed, 9 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp
index 2eda863241..f2e1bdd354 100644
--- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp
+++ b/Libraries/LibJS/Runtime/ObjectConstructor.cpp
@@ -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&)
diff --git a/Libraries/LibJS/Tests/builtins/Object/Object.js b/Libraries/LibJS/Tests/builtins/Object/Object.js
index 3ff78623da..544704c1f0 100644
--- a/Libraries/LibJS/Tests/builtins/Object/Object.js
+++ b/Libraries/LibJS/Tests/builtins/Object/Object.js
@@ -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");
});