mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
LibJS: Use to_property_key() a bunch in ReflectObject
Yay for correctness. :^)
This commit is contained in:
parent
7565bf0590
commit
39c3aefe5d
1 changed files with 7 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -143,20 +143,10 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property)
|
||||||
auto* target = get_target_object_from(global_object, "deleteProperty");
|
auto* target = get_target_object_from(global_object, "deleteProperty");
|
||||||
if (!target)
|
if (!target)
|
||||||
return {};
|
return {};
|
||||||
|
auto property_key = vm.argument(1).to_property_key(global_object);
|
||||||
auto property_key = vm.argument(1);
|
|
||||||
auto property_name = PropertyName::from_value(global_object, property_key);
|
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
auto property_key_number = property_key.to_number(global_object);
|
return Value(target->delete_property(property_key));
|
||||||
if (vm.exception())
|
|
||||||
return {};
|
|
||||||
if (property_key_number.is_finite_number()) {
|
|
||||||
auto property_key_as_double = property_key_number.as_double();
|
|
||||||
if (property_key_as_double >= 0 && (i32)property_key_as_double == property_key_as_double)
|
|
||||||
property_name = PropertyName(property_key_as_double);
|
|
||||||
}
|
|
||||||
return Value(target->delete_property(property_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get)
|
JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get)
|
||||||
|
@ -164,7 +154,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get)
|
||||||
auto* target = get_target_object_from(global_object, "get");
|
auto* target = get_target_object_from(global_object, "get");
|
||||||
if (!target)
|
if (!target)
|
||||||
return {};
|
return {};
|
||||||
auto property_key = PropertyName::from_value(global_object, vm.argument(1));
|
auto property_key = vm.argument(1).to_property_key(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
Value receiver = {};
|
Value receiver = {};
|
||||||
|
@ -178,7 +168,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_own_property_descriptor)
|
||||||
auto* target = get_target_object_from(global_object, "getOwnPropertyDescriptor");
|
auto* target = get_target_object_from(global_object, "getOwnPropertyDescriptor");
|
||||||
if (!target)
|
if (!target)
|
||||||
return {};
|
return {};
|
||||||
auto property_key = PropertyName::from_value(global_object, vm.argument(1));
|
auto property_key = vm.argument(1).to_property_key(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
return target->get_own_property_descriptor_object(property_key);
|
return target->get_own_property_descriptor_object(property_key);
|
||||||
|
@ -197,7 +187,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::has)
|
||||||
auto* target = get_target_object_from(global_object, "has");
|
auto* target = get_target_object_from(global_object, "has");
|
||||||
if (!target)
|
if (!target)
|
||||||
return {};
|
return {};
|
||||||
auto property_key = PropertyName::from_value(global_object, vm.argument(1));
|
auto property_key = vm.argument(1).to_property_key(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
return Value(target->has_property(property_key));
|
return Value(target->has_property(property_key));
|
||||||
|
@ -232,7 +222,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::set)
|
||||||
auto* target = get_target_object_from(global_object, "set");
|
auto* target = get_target_object_from(global_object, "set");
|
||||||
if (!target)
|
if (!target)
|
||||||
return {};
|
return {};
|
||||||
auto property_key = vm.argument(1).to_string(global_object);
|
auto property_key = vm.argument(1).to_property_key(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
auto value = vm.argument(2);
|
auto value = vm.argument(2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue