Sfoglia il codice sorgente

LibJS: Implement the NewObjectEnvironment() abstract operation

Andreas Kling 4 anni fa
parent
commit
395bee07e0

+ 2 - 1
Userland/Libraries/LibJS/AST.cpp

@@ -14,6 +14,7 @@
 #include <LibCrypto/BigInt/SignedBigInteger.h>
 #include <LibJS/AST.h>
 #include <LibJS/Interpreter.h>
+#include <LibJS/Runtime/AbstractOperations.h>
 #include <LibJS/Runtime/Accessor.h>
 #include <LibJS/Runtime/Array.h>
 #include <LibJS/Runtime/BigInt.h>
@@ -306,7 +307,7 @@ Value WithStatement::execute(Interpreter& interpreter, GlobalObject& global_obje
 
     VERIFY(object);
 
-    auto* object_environment_record = interpreter.heap().allocate<ObjectEnvironmentRecord>(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<EnvironmentRecord*> scope_change(interpreter.vm().call_frame().environment_record, object_environment_record);
     return interpreter.execute_statement(global_object, m_body).value_or(js_undefined());
 }

+ 11 - 0
Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp

@@ -14,6 +14,7 @@
 #include <LibJS/Runtime/Function.h>
 #include <LibJS/Runtime/GlobalObject.h>
 #include <LibJS/Runtime/Object.h>
+#include <LibJS/Runtime/ObjectEnvironmentRecord.h>
 #include <LibJS/Runtime/PropertyName.h>
 #include <LibJS/Runtime/ProxyObject.h>
 
@@ -165,4 +166,14 @@ DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord& env
     return global_object.heap().allocate<DeclarativeEnvironmentRecord>(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<ObjectEnvironmentRecord>(global_object, object, environment_record);
+}
+
 }

+ 1 - 0
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&);