summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/AST.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-04-10 18:47:18 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-10 21:00:04 +0200
commit2172e51246283311b8e699212baa9a5283b98737 (patch)
tree93f4aafca18183efb1433b0609728e2062f355e3 /Userland/Libraries/LibJS/AST.cpp
parent9cd010167ae6ee25a5fcee25ec9751545ca1a8e8 (diff)
downloadserenity-2172e51246283311b8e699212baa9a5283b98737.zip
LibJS: Implicitly break for..in loop if the RHS result is nullish
This implements the missing step 6a of 14.7.5.6 ForIn/OfHeadEvaluation: a. If exprValue is undefined or null, then i. Return Completion { [[Type]]: break, [[Value]]: empty, [[Target]]: empty }. In other words, this should just do nothing instead of throwing during the undefined to object coercion: for (const x in undefined);
Diffstat (limited to 'Userland/Libraries/LibJS/AST.cpp')
-rw-r--r--Userland/Libraries/LibJS/AST.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp
index cd414e4ae0..98204761f0 100644
--- a/Userland/Libraries/LibJS/AST.cpp
+++ b/Userland/Libraries/LibJS/AST.cpp
@@ -477,6 +477,8 @@ Value ForInStatement::execute(Interpreter& interpreter, GlobalObject& global_obj
auto rhs_result = m_rhs->execute(interpreter, global_object);
if (interpreter.exception())
return {};
+ if (rhs_result.is_nullish())
+ return {};
auto* object = rhs_result.to_object(global_object);
while (object) {
auto property_names = object->get_enumerable_own_property_names(Object::PropertyKind::Key);