diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-07 23:11:08 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-07 23:11:08 +0100 |
commit | 39c3aefe5de1763384c33cae5b931802a866cb0f (patch) | |
tree | 0c6254d4422cfa5f3c760eef1983aec5c3e5e8ab /Userland/Libraries | |
parent | 7565bf059026685f8e13d9eda1eb1f1a6ef93983 (diff) | |
download | serenity-39c3aefe5de1763384c33cae5b931802a866cb0f.zip |
LibJS: Use to_property_key() a bunch in ReflectObject
Yay for correctness. :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ReflectObject.cpp | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index 3e7f911db6..0db3db5cd1 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -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 */ @@ -143,20 +143,10 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property) auto* target = get_target_object_from(global_object, "deleteProperty"); if (!target) return {}; - - auto property_key = vm.argument(1); - auto property_name = PropertyName::from_value(global_object, property_key); - if (vm.exception()) - return {}; - auto property_key_number = property_key.to_number(global_object); + auto property_key = vm.argument(1).to_property_key(global_object); 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)); + return Value(target->delete_property(property_key)); } 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"); if (!target) 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()) return {}; Value receiver = {}; @@ -178,7 +168,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get_own_property_descriptor) auto* target = get_target_object_from(global_object, "getOwnPropertyDescriptor"); if (!target) 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()) return {}; 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"); if (!target) 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()) return {}; 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"); if (!target) 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()) return {}; auto value = vm.argument(2); |