diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp index 2ff649c32c..11ee6986c5 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp @@ -92,6 +92,13 @@ ThrowCompletionOr 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));