ProxyObject.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibJS/Runtime/FunctionObject.h>
  9. namespace JS {
  10. class ProxyObject final : public FunctionObject {
  11. JS_OBJECT(ProxyObject, FunctionObject);
  12. public:
  13. static ProxyObject* create(GlobalObject&, Object& target, Object& handler);
  14. ProxyObject(Object& target, Object& handler, Object& prototype);
  15. virtual ~ProxyObject() override;
  16. virtual Value call() override;
  17. virtual Value construct(FunctionObject& new_target) override;
  18. virtual const FlyString& name() const override;
  19. virtual FunctionEnvironment* create_environment(FunctionObject&) override;
  20. const Object& target() const { return m_target; }
  21. const Object& handler() const { return m_handler; }
  22. bool is_revoked() const { return m_is_revoked; }
  23. void revoke() { m_is_revoked = true; }
  24. // 10.5 Proxy Object Internal Methods and Internal Slots, https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots
  25. virtual Object* internal_get_prototype_of() const override;
  26. virtual bool internal_set_prototype_of(Object* prototype) override;
  27. virtual bool internal_is_extensible() const override;
  28. virtual bool internal_prevent_extensions() override;
  29. virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const override;
  30. virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
  31. virtual bool internal_has_property(PropertyName const&) const override;
  32. virtual Value internal_get(PropertyName const&, Value receiver) const override;
  33. virtual bool internal_set(PropertyName const&, Value value, Value receiver) override;
  34. virtual bool internal_delete(PropertyName const&) override;
  35. virtual MarkedValueList internal_own_property_keys() const override;
  36. private:
  37. virtual void visit_edges(Visitor&) override;
  38. virtual bool is_function() const override { return m_target.is_function(); }
  39. virtual bool is_proxy_object() const final { return true; }
  40. Object& m_target;
  41. Object& m_handler;
  42. bool m_is_revoked { false };
  43. };
  44. template<>
  45. inline bool Object::fast_is<ProxyObject>() const { return is_proxy_object(); }
  46. }