1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:47:37 +00:00

LibJS: Fix Object.prototype.valueOf() behavior

No idea why it was implemented like this, but a value_of() call on the
coerced object is not part of the spec. Also added some tests.
This commit is contained in:
Linus Groh 2021-06-13 01:04:52 +01:00
parent 1253a3d038
commit 33eea1f722
2 changed files with 9 additions and 4 deletions

View file

@ -106,10 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string)
// 20.1.3.7 Object.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-object.prototype.valueof
JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::value_of)
{
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
return this_object->value_of();
return vm.this_value(global_object).to_object(global_object);
}
// 20.1.3.4 Object.prototype.propertyIsEnumerable ( V ), https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable

View file

@ -0,0 +1,8 @@
test("basic functionality", () => {
expect(Object.prototype.valueOf).toHaveLength(0);
const o = {};
expect(o.valueOf()).toBe(o);
expect(Object.prototype.valueOf.call(42)).toEqual(new Number(42));
});