瀏覽代碼

LibJS: Make JS::Script keep the VM alive

Script has a Handle member (m_realm), and for handles to remain valid,
the VM must stay alive.
Andreas Kling 3 年之前
父節點
當前提交
f08a46bd9e
共有 2 個文件被更改,包括 5 次插入1 次删除
  1. 2 1
      Userland/Libraries/LibJS/Script.cpp
  2. 3 0
      Userland/Libraries/LibJS/Script.h

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

@@ -30,7 +30,8 @@ NonnullRefPtr<Script> Script::parse(StringView source_text, Realm& realm, String
 }
 
 Script::Script(Realm& realm, NonnullRefPtr<Program> parse_node)
-    : m_realm(make_handle(&realm))
+    : m_vm(realm.vm())
+    , m_realm(make_handle(&realm))
     , m_parse_node(move(parse_node))
 {
 }

+ 3 - 0
Userland/Libraries/LibJS/Script.h

@@ -26,6 +26,9 @@ public:
 private:
     Script(Realm&, NonnullRefPtr<Program>);
 
+    // Handles are not safe unless we keep the VM alive.
+    NonnullRefPtr<VM> m_vm;
+
     Handle<Realm> m_realm;               // [[Realm]]
     NonnullRefPtr<Program> m_parse_node; // [[ECMAScriptCode]]
 };