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:
parent
d1d24569f8
commit
9df7bf79cc
1 changed files with 12 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue