mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 07:36:50 +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:
@@ -68,7 +68,7 @@
|
||||
namespace JS {
|
||||
|
||||
GlobalObject::GlobalObject()
|
||||
: Object(GlobalObjectTag::Tag)
|
||||
: ScopeObject(GlobalObjectTag::Tag)
|
||||
, m_console(make<Console>(*this))
|
||||
{
|
||||
}
|
||||
@@ -149,7 +149,7 @@ GlobalObject::~GlobalObject()
|
||||
|
||||
void GlobalObject::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Object::visit_edges(visitor);
|
||||
Base::visit_edges(visitor);
|
||||
|
||||
visitor.visit(m_empty_object_shape);
|
||||
visitor.visit(m_new_object_shape);
|
||||
@@ -205,4 +205,27 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
|
||||
return js_nan();
|
||||
}
|
||||
|
||||
Optional<Variable> GlobalObject::get_from_scope(const FlyString& name) const
|
||||
{
|
||||
auto value = get(name);
|
||||
if (value.is_empty())
|
||||
return {};
|
||||
return Variable { value, DeclarationKind::Var };
|
||||
}
|
||||
|
||||
void GlobalObject::put_to_scope(const FlyString& name, Variable variable)
|
||||
{
|
||||
put(name, variable.value);
|
||||
}
|
||||
|
||||
bool GlobalObject::has_this_binding() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Value GlobalObject::get_this_binding(GlobalObject&) const
|
||||
{
|
||||
return Value(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user