ProxyObject.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/Completion.h>
  9. #include <LibJS/Runtime/FunctionObject.h>
  10. namespace JS {
  11. class ProxyObject final : public FunctionObject {
  12. JS_OBJECT(ProxyObject, FunctionObject);
  13. public:
  14. static ProxyObject* create(GlobalObject&, Object& target, Object& handler);
  15. ProxyObject(Object& target, Object& handler, Object& prototype);
  16. virtual ~ProxyObject() override;
  17. virtual Value call() override;
  18. virtual Value construct(FunctionObject& new_target) override;
  19. virtual const FlyString& name() const override;
  20. virtual FunctionEnvironment* create_environment(FunctionObject&) override;
  21. virtual bool has_constructor() const override { return true; }
  22. const Object& target() const { return m_target; }
  23. const Object& handler() const { return m_handler; }
  24. bool is_revoked() const { return m_is_revoked; }
  25. void revoke() { m_is_revoked = true; }
  26. // 10.5 Proxy Object Internal Methods and Internal Slots, https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots
  27. virtual ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
  28. virtual ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
  29. virtual bool internal_is_extensible() const override;
  30. virtual bool internal_prevent_extensions() override;
  31. virtual Optional<PropertyDescriptor> internal_get_own_property(PropertyName const&) const override;
  32. virtual bool internal_define_own_property(PropertyName const&, PropertyDescriptor const&) override;
  33. virtual bool internal_has_property(PropertyName const&) const override;
  34. virtual Value internal_get(PropertyName const&, Value receiver) const override;
  35. virtual bool internal_set(PropertyName const&, Value value, Value receiver) override;
  36. virtual bool internal_delete(PropertyName const&) override;
  37. virtual MarkedValueList internal_own_property_keys() const override;
  38. private:
  39. virtual void visit_edges(Visitor&) override;
  40. virtual bool is_function() const override { return m_target.is_function(); }
  41. virtual bool is_proxy_object() const final { return true; }
  42. Object& m_target;
  43. Object& m_handler;
  44. bool m_is_revoked { false };
  45. };
  46. template<>
  47. inline bool Object::fast_is<ProxyObject>() const { return is_proxy_object(); }
  48. }