1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

LibJS: Implement Proxy [[Call]] and [[Construct]] traps

In order to do this, Proxy now extends Function rather than Object, and
whether or not it returns true for is_function() depends on it's
m_target.
This commit is contained in:
Matthew Olsson 2020-06-25 14:49:56 -07:00 committed by Andreas Kling
parent ed683663cd
commit 98323e19e5
5 changed files with 98 additions and 6 deletions

View file

@ -26,12 +26,12 @@
#pragma once
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Function.h>
namespace JS {
class ProxyObject : public Object {
JS_OBJECT(ProxyObject, Object);
class ProxyObject final : public Function {
JS_OBJECT(ProxyObject, Function);
public:
static ProxyObject* create(GlobalObject&, Object& target, Object& handler);
@ -39,6 +39,11 @@ public:
ProxyObject(Object& target, Object& handler, Object& prototype);
virtual ~ProxyObject() override;
virtual Value call(Interpreter&) override;
virtual Value construct(Interpreter&) override;
virtual const FlyString& name() const override;
virtual LexicalEnvironment* create_environment() override;
const Object& target() const { return m_target; }
const Object& handler() const { return m_handler; }
@ -59,6 +64,8 @@ public:
private:
virtual void visit_children(Visitor&) override;
virtual bool is_proxy_object() const override { return true; }
virtual bool is_function() const override { return m_target.is_function(); }
virtual bool is_array() const override { return m_target.is_array(); };
Object& m_target;