diff options
author | Andreas Kling <kling@serenityos.org> | 2022-11-10 20:27:53 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-11 12:22:01 +0000 |
commit | 12ceaf37902f173a14b8a8fb92fbd19cdee678b8 (patch) | |
tree | 0bd2c569ff9c159b7ae0af3acd83b4ee687056eb /Userland/Libraries/LibJS | |
parent | 56abb01ee3be7213f67ba7024881e3a0c7baf941 (diff) | |
download | serenity-12ceaf37902f173a14b8a8fb92fbd19cdee678b8.zip |
LibJS: Make ObjectEnvironment::get_binding_value() faster in sloppy mode
We can combine HasProperty and Get into just Get in non-strict mode for
non-with object environments.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp index 10fa8722c8..2ff649c32c 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp @@ -127,6 +127,14 @@ ThrowCompletionOr<Value> ObjectEnvironment::get_binding_value(VM&, FlyString con { auto& vm = this->vm(); + // OPTIMIZATION: For non-with environments in non-strict mode, we don't need the separate HasProperty check + // since Get will return undefined for missing properties anyway. So we take advantage of this + // to avoid doing both HasProperty and Get. + // We can't do this for with environments, since it would be observable (e.g via a Proxy) + // FIXME: We could combine HasProperty and Get in non-strict mode if Get would return a bit more failure information. + if (!m_with_environment && !strict) + return m_binding_object.get(name); + // 1. Let bindingObject be envRec.[[BindingObject]]. // 2. Let value be ? HasProperty(bindingObject, N). auto value = TRY(m_binding_object.has_property(name)); |