1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

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.
This commit is contained in:
Andreas Kling 2023-08-08 07:05:26 +02:00
parent d1d24569f8
commit 9df7bf79cc

View file

@ -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;
}
}