diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 45df4ec2ac..6f1f77011c 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -306,7 +307,7 @@ Value WithStatement::execute(Interpreter& interpreter, GlobalObject& global_obje VERIFY(object); - auto* object_environment_record = interpreter.heap().allocate(global_object, *object, interpreter.vm().call_frame().environment_record); + auto* object_environment_record = new_object_environment(*object, true, interpreter.vm().call_frame().environment_record); TemporaryChange scope_change(interpreter.vm().call_frame().environment_record, object_environment_record); return interpreter.execute_statement(global_object, m_body).value_or(js_undefined()); } diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 4833161962..52ee895ee4 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -165,4 +166,14 @@ DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord& env return global_object.heap().allocate(global_object, &environment_record); } +// 9.1.2.3 NewObjectEnvironment ( O, W, E ), https://tc39.es/ecma262/#sec-newobjectenvironment +ObjectEnvironmentRecord* new_object_environment(Object& object, bool is_with_environment, EnvironmentRecord* environment_record) +{ + auto& global_object = object.global_object(); + if (!is_with_environment) { + TODO(); + } + return global_object.heap().allocate(global_object, object, environment_record); +} + } diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index 69b0533477..0b4a7b22cd 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -14,6 +14,7 @@ namespace JS { DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord&); +ObjectEnvironmentRecord* new_object_environment(Object&, bool is_with_environment, EnvironmentRecord*); Value require_object_coercible(GlobalObject&, Value); Function* get_method(GlobalObject& global_object, Value, PropertyName const&); size_t length_of_array_like(GlobalObject&, Object const&);