mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 12:07:35 +00:00
LibJS: Implement Object.is()
Basically === with two particularities: comparing NaN to itself is considered equal and comparing +0 and -0 is not.
This commit is contained in:
parent
f191b84b50
commit
38ba13e912
4 changed files with 73 additions and 0 deletions
|
@ -41,6 +41,7 @@ ObjectConstructor::ObjectConstructor()
|
|||
put("prototype", interpreter().global_object().object_prototype());
|
||||
|
||||
put_native_function("defineProperty", define_property, 3);
|
||||
put_native_function("is", is, 2);
|
||||
put_native_function("getOwnPropertyDescriptor", get_own_property_descriptor, 2);
|
||||
put_native_function("getOwnPropertyNames", get_own_property_names, 1);
|
||||
put_native_function("getPrototypeOf", get_prototype_of, 1);
|
||||
|
@ -146,4 +147,20 @@ Value ObjectConstructor::define_property(Interpreter& interpreter)
|
|||
return &object;
|
||||
}
|
||||
|
||||
Value ObjectConstructor::is(Interpreter& interpreter)
|
||||
{
|
||||
auto value1 = interpreter.argument(0);
|
||||
auto value2 = interpreter.argument(1);
|
||||
if (value1.is_nan() && value2.is_nan())
|
||||
return Value(true);
|
||||
if (value1.is_number() && value1.as_double() == 0 && value2.is_number() && value2.as_double() == 0) {
|
||||
if (value1.is_positive_zero() && value2.is_positive_zero())
|
||||
return Value(true);
|
||||
if (value1.is_negative_zero() && value2.is_negative_zero())
|
||||
return Value(true);
|
||||
return Value(false);
|
||||
}
|
||||
return typed_eq(interpreter, value1, value2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue