diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-25 15:37:28 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-25 15:37:28 +0200 |
commit | 72cd31d033804b59c9335c34a72d82b5d4b81cad (patch) | |
tree | 336311dfca6aabac6b97ae6c69ee37514524fd1e | |
parent | cfbb69a9cd45d4fc8d2d5d2b489f48afc9030d67 (diff) | |
download | serenity-72cd31d033804b59c9335c34a72d82b5d4b81cad.zip |
LibJS: Tweak Value::to_property_key() fast path for Int32
Move the check for Int32 *before* we call to_primitive().
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Value.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 129c286387..db29fd636e 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -561,9 +561,9 @@ ThrowCompletionOr<double> Value::to_double(GlobalObject& global_object) const // 7.1.19 ToPropertyKey ( argument ), https://tc39.es/ecma262/#sec-topropertykey ThrowCompletionOr<PropertyKey> Value::to_property_key(GlobalObject& global_object) const { + if (type() == Type::Int32 && as_i32() >= 0) + return PropertyKey { as_i32() }; auto key = TRY(to_primitive(global_object, PreferredType::String)); - if (key.type() == Type::Int32 && key.as_i32() >= 0) - return PropertyKey { key.as_i32() }; if (key.is_symbol()) return &key.as_symbol(); return TRY(key.to_string(global_object)); |