mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
LibJS: Add basic prototype support
Object will now traverse up the prototype chain when doing a get(). When a function is called on an object, that object will now also be the "this" value inside the function. This stuff is probably not very correct, but we will improve things as we go! :^)
This commit is contained in:
parent
d02c37f3e3
commit
f7c15d00c9
5 changed files with 42 additions and 2 deletions
|
@ -79,10 +79,20 @@ public:
|
|||
void enter_scope(const ScopeNode&, Vector<Argument>, ScopeType);
|
||||
void exit_scope(const ScopeNode&);
|
||||
|
||||
void push_this_value(Value value) { m_this_stack.append(move(value)); }
|
||||
void pop_this_value() { m_this_stack.take_last(); }
|
||||
Value this_value() const
|
||||
{
|
||||
if (m_this_stack.is_empty())
|
||||
return m_global_object;
|
||||
return m_this_stack.last();
|
||||
}
|
||||
|
||||
private:
|
||||
Heap m_heap;
|
||||
|
||||
Vector<ScopeFrame> m_scope_stack;
|
||||
Vector<Value> m_this_stack;
|
||||
|
||||
Object* m_global_object { nullptr };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue