瀏覽代碼

LibJS: Prepare ExecutionContext to store the current Realm Record

Also add VM::current_realm() to retrieve it, similar to all the other
getters (running_execution_context() et al.).
Linus Groh 3 年之前
父節點
當前提交
332946ab4f
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      Userland/Libraries/LibJS/Runtime/VM.h

+ 7 - 0
Userland/Libraries/LibJS/Runtime/VM.h

@@ -42,6 +42,7 @@ struct ScopeFrame {
     bool pushed_environment { false };
     bool pushed_environment { false };
 };
 };
 
 
+// 9.4 Execution Contexts, https://tc39.es/ecma262/#sec-execution-contexts
 struct ExecutionContext {
 struct ExecutionContext {
     explicit ExecutionContext(Heap& heap)
     explicit ExecutionContext(Heap& heap)
         : arguments(heap)
         : arguments(heap)
@@ -56,6 +57,7 @@ struct ExecutionContext {
     Object* arguments_object { nullptr };
     Object* arguments_object { nullptr };
     Environment* lexical_environment { nullptr };
     Environment* lexical_environment { nullptr };
     Environment* variable_environment { nullptr };
     Environment* variable_environment { nullptr };
+    Realm* realm { nullptr };
     bool is_strict_mode { false };
     bool is_strict_mode { false };
 };
 };
 
 
@@ -146,6 +148,11 @@ public:
     Environment const* variable_environment() const { return running_execution_context().variable_environment; }
     Environment const* variable_environment() const { return running_execution_context().variable_environment; }
     Environment* variable_environment() { return running_execution_context().variable_environment; }
     Environment* variable_environment() { return running_execution_context().variable_environment; }
 
 
+    // https://tc39.es/ecma262/#current-realm
+    // The value of the Realm component of the running execution context is also called the current Realm Record.
+    Realm const* current_realm() const { return running_execution_context().realm; }
+    Realm* current_realm() { return running_execution_context().realm; }
+
     bool in_strict_mode() const;
     bool in_strict_mode() const;
 
 
     template<typename Callback>
     template<typename Callback>