1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

LibJS: Make ObjectEnvironment::set_mutable_binding() faster as well

We can combine HasProperty and Set into just Set in non-strict mode for
non-with object environments.
This commit is contained in:
Andreas Kling 2022-11-10 20:36:02 +01:00 committed by Linus Groh
parent 12ceaf3790
commit 7b30df0840

View file

@ -92,6 +92,13 @@ ThrowCompletionOr<void> ObjectEnvironment::set_mutable_binding(VM&, FlyString co
{
auto& vm = this->vm();
// OPTIMIZATION: For non-with environments in non-strict mode, we don't need the separate HasProperty check since we only use that
// information to throw errors in strict mode.
// We can't do this for with environments, since it would be observable (e.g via a Proxy)
// FIXME: I think we could combine HasProperty and Set in strict mode if Set would return a bit more failure information.
if (!m_with_environment && !strict)
return m_binding_object.set(name, value, Object::ShouldThrowExceptions::No);
// 1. Let bindingObject be envRec.[[BindingObject]].
// 2. Let stillExists be ? HasProperty(bindingObject, N).
auto still_exists = TRY(m_binding_object.has_property(name));