summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-09 17:07:32 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-09 21:53:47 +0100
commitfbb176c926e84d0ed768700ab2af0449de0457ed (patch)
tree5ff4b12a7c2a12895b5aeec24efe631c889fc5dc /Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
parent617d3cd3d3d03fc5c2af8cfe71d8c34be2031bc0 (diff)
downloadserenity-fbb176c926e84d0ed768700ab2af0449de0457ed.zip
LibJS: Convert has_binding() to ThrowCompletionOr
Also add spec step comments to it while we're here.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
index 3aa0fc2040..301c398885 100644
--- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.cpp
@@ -25,20 +25,37 @@ void ObjectEnvironment::visit_edges(Cell::Visitor& visitor)
}
// 9.1.1.2.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-hasbinding-n
-bool ObjectEnvironment::has_binding(FlyString const& name, Optional<size_t>*) const
+ThrowCompletionOr<bool> ObjectEnvironment::has_binding(FlyString const& name, Optional<size_t>*) const
{
auto& vm = this->vm();
- bool found_binding = TRY_OR_DISCARD(m_binding_object.has_property(name));
+
+ // 1. Let bindingObject be envRec.[[BindingObject]].
+
+ // 2. Let foundBinding be ? HasProperty(bindingObject, N).
+ bool found_binding = TRY(m_binding_object.has_property(name));
+
+ // 3. If foundBinding is false, return false.
if (!found_binding)
return false;
+
+ // 4. If envRec.[[IsWithEnvironment]] is false, return true.
if (!m_with_environment)
return true;
- auto unscopables = TRY_OR_DISCARD(m_binding_object.get(*vm.well_known_symbol_unscopables()));
+
+ // 5. Let unscopables be ? Get(bindingObject, @@unscopables).
+ auto unscopables = TRY(m_binding_object.get(*vm.well_known_symbol_unscopables()));
+
+ // 6. If Type(unscopables) is Object, then
if (unscopables.is_object()) {
- auto blocked = TRY_OR_DISCARD(unscopables.as_object().get(name));
- if (blocked.to_boolean())
+ // a. Let blocked be ! ToBoolean(? Get(unscopables, N)).
+ auto blocked = TRY(unscopables.as_object().get(name)).to_boolean();
+
+ // b. If blocked is true, return false.
+ if (blocked)
return false;
}
+
+ // 7. Return true.
return true;
}