Quellcode durchsuchen

LibJS: Add vector of local variables in ExecutionContext

Now ExecutionContext has vector of values that will represent values
of local variables.

This vector is initialized in ECMAScriptFunctionObject::internal_call()
or ECMAScriptFunctionObject::internal_const() using number of local
variables provided to ECMAScriptFunctionObject by the parser.
Aliaksandr Kalenik vor 2 Jahren
Ursprung
Commit
0daff637e2

+ 4 - 0
Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp

@@ -149,6 +149,8 @@ ThrowCompletionOr<Value> ECMAScriptFunctionObject::internal_call(Value this_argu
 
 
     ExecutionContext callee_context(heap());
     ExecutionContext callee_context(heap());
 
 
+    callee_context.local_variables.resize(m_local_variables_names.size());
+
     // Non-standard
     // Non-standard
     callee_context.arguments.extend(move(arguments_list));
     callee_context.arguments.extend(move(arguments_list));
     if (auto* interpreter = vm.interpreter_if_exists())
     if (auto* interpreter = vm.interpreter_if_exists())
@@ -218,6 +220,8 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ECMAScriptFunctionObject::internal_const
 
 
     ExecutionContext callee_context(heap());
     ExecutionContext callee_context(heap());
 
 
+    callee_context.local_variables.resize(m_local_variables_names.size());
+
     // Non-standard
     // Non-standard
     callee_context.arguments.extend(move(arguments_list));
     callee_context.arguments.extend(move(arguments_list));
     if (auto* interpreter = vm.interpreter_if_exists())
     if (auto* interpreter = vm.interpreter_if_exists())

+ 4 - 2
Userland/Libraries/LibJS/Runtime/ExecutionContext.cpp

@@ -13,17 +13,19 @@ namespace JS {
 
 
 ExecutionContext::ExecutionContext(Heap& heap)
 ExecutionContext::ExecutionContext(Heap& heap)
     : arguments(heap)
     : arguments(heap)
+    , local_variables(heap)
 {
 {
 }
 }
 
 
-ExecutionContext::ExecutionContext(MarkedVector<Value> existing_arguments)
+ExecutionContext::ExecutionContext(MarkedVector<Value> existing_arguments, MarkedVector<Value> existing_local_variables)
     : arguments(move(existing_arguments))
     : arguments(move(existing_arguments))
+    , local_variables(move(existing_local_variables))
 {
 {
 }
 }
 
 
 ExecutionContext ExecutionContext::copy() const
 ExecutionContext ExecutionContext::copy() const
 {
 {
-    ExecutionContext copy { arguments };
+    ExecutionContext copy { arguments, local_variables };
 
 
     copy.function = function;
     copy.function = function;
     copy.realm = realm;
     copy.realm = realm;

+ 2 - 1
Userland/Libraries/LibJS/Runtime/ExecutionContext.h

@@ -29,7 +29,7 @@ struct ExecutionContext {
     void visit_edges(Cell::Visitor&);
     void visit_edges(Cell::Visitor&);
 
 
 private:
 private:
-    explicit ExecutionContext(MarkedVector<Value> existing_arguments);
+    explicit ExecutionContext(MarkedVector<Value> existing_arguments, MarkedVector<Value> existing_local_variables);
 
 
 public:
 public:
     GCPtr<FunctionObject> function;                // [[Function]]
     GCPtr<FunctionObject> function;                // [[Function]]
@@ -46,6 +46,7 @@ public:
     DeprecatedFlyString function_name;
     DeprecatedFlyString function_name;
     Value this_value;
     Value this_value;
     MarkedVector<Value> arguments;
     MarkedVector<Value> arguments;
+    MarkedVector<Value> local_variables;
     bool is_strict_mode { false };
     bool is_strict_mode { false };
 
 
     // https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter
     // https://html.spec.whatwg.org/multipage/webappapis.html#skip-when-determining-incumbent-counter