mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:28:11 +00:00
LibJS: Add Interpreter::create<GlobalObjectType>()
Force Interpreter construction to go via a create() helper that takes the global object type as a template parameter.
This commit is contained in:
parent
aee4c1f583
commit
9d5d0261e1
3 changed files with 16 additions and 17 deletions
|
@ -68,16 +68,16 @@ struct Argument {
|
|||
|
||||
class Interpreter {
|
||||
public:
|
||||
Interpreter();
|
||||
~Interpreter();
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void initialize_global_object(Args&&... args)
|
||||
template<typename GlobalObjectType, typename... Args>
|
||||
static NonnullOwnPtr<Interpreter> create(Args&&... args)
|
||||
{
|
||||
ASSERT(!m_global_object);
|
||||
m_global_object = heap().allocate<T>(forward<Args>(args)...);
|
||||
auto interpreter = adopt_own(*new Interpreter);
|
||||
interpreter->m_global_object = interpreter->heap().allocate<GlobalObjectType>(forward<Args>(args)...);
|
||||
return interpreter;
|
||||
}
|
||||
|
||||
~Interpreter();
|
||||
|
||||
Value run(const Statement&, Vector<Argument> = {}, ScopeType = ScopeType::Block);
|
||||
|
||||
Object& global_object() { return *m_global_object; }
|
||||
|
@ -136,6 +136,8 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Interpreter();
|
||||
|
||||
Heap m_heap;
|
||||
|
||||
Vector<ScopeFrame> m_scope_stack;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue