mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
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.
This commit is contained in:
parent
56abb01ee3
commit
12ceaf3790
Notes:
sideshowbarker
2024-07-17 04:35:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/12ceaf3790 Pull-request: https://github.com/SerenityOS/serenity/pull/16017 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/linusg ✅
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue