summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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");
});