summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Reference.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-15 04:52:39 +0430
committerAndreas Kling <kling@serenityos.org>2021-09-15 11:56:00 +0200
commit53d24fbd655ddb600dbff5ccf492b1757cd55d2b (patch)
treeb2d5cc706028ad47b2650dbb7b1a04f397b539d1 /Userland/Libraries/LibJS/Runtime/Reference.cpp
parent3f31f109b56730f71d6d61914429038501a8ed23 (diff)
downloadserenity-53d24fbd655ddb600dbff5ccf492b1757cd55d2b.zip
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>
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Reference.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Reference.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp
index bb6d3620b1..adae50a022 100644
--- a/Userland/Libraries/LibJS/Runtime/Reference.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp
@@ -50,6 +50,7 @@ void Reference::put_value(GlobalObject& global_object, Value value)
}
VERIFY(m_base_type == BaseType::Environment);
+ // FIXME: This entire following section is 100% not spec-compliant.
auto existing_variable = m_base_environment->get_from_environment(m_name.as_string());
Variable variable {
.value = value,
@@ -66,10 +67,11 @@ void Reference::put_value(GlobalObject& global_object, Value value)
if (vm.exception())
return;
- if (!succeeded && m_strict) {
- // FIXME: This is a hack and will disappear when we support proper variable bindings.
- vm.throw_exception<TypeError>(global_object, ErrorType::DescWriteNonWritable, m_name);
- return;
+ if (!succeeded) {
+ if (m_base_environment->has_binding(m_name.as_string())) {
+ m_base_environment->set_mutable_binding(global_object, m_name.as_string(), value, is_strict());
+ return;
+ }
}
}
@@ -98,8 +100,11 @@ Value Reference::get_value(GlobalObject& global_object, bool throw_if_undefined)
}
VERIFY(m_base_type == BaseType::Environment);
+ // FIXME: This entire section is 100% not spec-compliant.
auto value = m_base_environment->get_from_environment(m_name.as_string());
if (!value.has_value()) {
+ if (m_base_environment->has_binding(m_name.as_string()))
+ return m_base_environment->get_binding_value(global_object, m_name.as_string(), is_strict());
if (!throw_if_undefined) {
// FIXME: This is an ad-hoc hack for the `typeof` operator until we support proper variable bindings.
return js_undefined();
@@ -168,6 +173,9 @@ bool Reference::delete_(GlobalObject& global_object)
VERIFY(m_base_type == BaseType::Environment);
// c. Return ? base.DeleteBinding(ref.[[ReferencedName]]).
+ if (m_base_environment->has_binding(m_name.as_string()))
+ return m_base_environment->delete_binding(global_object, m_name.as_string());
+
// FIXME: This is ad-hoc, we should be calling DeleteBinding.
return m_base_environment->delete_from_environment(m_name.as_string());
}