1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

LibJS: Make References see into Environment's bindings as well

'bindings' is the spec-compliant version of 'variables', but we were
simply not even looking at them, which made things using bindings (such
as named function expressions) break in unexpected ways after the move
to using references in call expressions.

Co-Authored-By: davidot <david.tuin@gmail.com>
This commit is contained in:
Ali Mohammad Pur 2021-09-15 04:52:39 +04:30 committed by Andreas Kling
parent 3f31f109b5
commit 53d24fbd65
3 changed files with 25 additions and 5 deletions

View file

@ -98,7 +98,17 @@ void ObjectEnvironment::set_mutable_binding(GlobalObject& global_object, FlyStri
global_object.vm().throw_exception<ReferenceError>(global_object, ErrorType::UnknownIdentifier, name);
return;
}
m_binding_object.set(name, value, strict ? Object::ShouldThrowExceptions::Yes : Object::ShouldThrowExceptions::No);
auto result = m_binding_object.set(name, value, strict ? Object::ShouldThrowExceptions::Yes : Object::ShouldThrowExceptions::No);
// Note: Nothing like this in the spec, this is here to produce nicer errors instead of the generic one thrown by Object::set().
if (!result && strict) {
auto property = m_binding_object.internal_get_own_property(name);
if (property.has_value() && !property->writable.value_or(true)) {
vm.clear_exception();
vm.throw_exception<TypeError>(global_object, ErrorType::DescWriteNonWritable, name);
}
}
}
// 9.1.1.2.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-getbindingvalue-n-s