mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:57:34 +00:00
LibJS: Add a scope object abstraction
Both GlobalObject and LexicalEnvironment now inherit from ScopeObject, and the VM's call frames point to a ScopeObject chain rather than just a LexicalEnvironment chain. This gives us much more flexibility to implement things like "with", and also unifies some of the code paths that previously required special handling of the global object. There's a bunch of more cleanup that can be done in the wake of this change, and there might be some oversights in the handling of the "super" keyword, but this generally seems like a good architectural improvement. :^)
This commit is contained in:
parent
e1bbc7c075
commit
c3fe9b4df8
16 changed files with 241 additions and 92 deletions
|
@ -59,7 +59,7 @@ struct CallFrame {
|
|||
FlyString function_name;
|
||||
Value this_value;
|
||||
Vector<Value> arguments;
|
||||
LexicalEnvironment* environment { nullptr };
|
||||
ScopeObject* scope { nullptr };
|
||||
bool is_strict_mode { false };
|
||||
};
|
||||
|
||||
|
@ -134,8 +134,8 @@ public:
|
|||
const Vector<CallFrame*>& call_stack() const { return m_call_stack; }
|
||||
Vector<CallFrame*>& call_stack() { return m_call_stack; }
|
||||
|
||||
const LexicalEnvironment* current_environment() const { return call_frame().environment; }
|
||||
LexicalEnvironment* current_environment() { return call_frame().environment; }
|
||||
const ScopeObject* current_scope() const { return call_frame().scope; }
|
||||
ScopeObject* current_scope() { return call_frame().scope; }
|
||||
|
||||
bool in_strict_mode() const;
|
||||
|
||||
|
@ -222,7 +222,7 @@ public:
|
|||
String join_arguments() const;
|
||||
|
||||
Value resolve_this_binding(GlobalObject&) const;
|
||||
const LexicalEnvironment* get_this_environment() const;
|
||||
const ScopeObject* find_this_scope() const;
|
||||
Value get_new_target() const;
|
||||
|
||||
template<typename... Args>
|
||||
|
@ -242,6 +242,8 @@ public:
|
|||
|
||||
CommonPropertyNames names;
|
||||
|
||||
Shape& scope_object_shape() { return *m_scope_object_shape; }
|
||||
|
||||
private:
|
||||
VM();
|
||||
|
||||
|
@ -271,6 +273,8 @@ private:
|
|||
Symbol* m_well_known_symbol_##snake_name { nullptr };
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
Shape* m_scope_object_shape { nullptr };
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue