Explorar el Código

LibJS: Add create_simple_execution_context<GlobalObjectType>() helper

This makes it easy to set up a realm, global object and root execution
context with a single call to LibJS. It will be useful to basically
everyone except LibWeb.
Andreas Kling hace 1 año
padre
commit
9df7bf79cc
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      Userland/Libraries/LibJS/Runtime/VM.h

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

@@ -344,4 +344,16 @@ private:
     OwnPtr<Bytecode::Interpreter> m_bytecode_interpreter;
 };
 
+template<typename GlobalObjectType, typename... Args>
+[[nodiscard]] static NonnullOwnPtr<ExecutionContext> create_simple_execution_context(VM& vm, Args&&... args)
+{
+    auto root_execution_context = MUST(Realm::initialize_host_defined_realm(
+        vm,
+        [&](Realm& realm_) -> GlobalObject* {
+            return vm.heap().allocate_without_realm<GlobalObjectType>(realm_, forward<Args>(args)...);
+        },
+        nullptr));
+    return root_execution_context;
+}
+
 }