ProxyObject.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/Function.h>
  8. namespace JS {
  9. class ProxyObject final : public Function {
  10. JS_OBJECT(ProxyObject, Function);
  11. public:
  12. static ProxyObject* create(GlobalObject&, Object& target, Object& handler);
  13. ProxyObject(Object& target, Object& handler, Object& prototype);
  14. virtual ~ProxyObject() override;
  15. virtual Value call() override;
  16. virtual Value construct(Function& new_target) override;
  17. virtual const FlyString& name() const override;
  18. virtual LexicalEnvironment* create_environment() override;
  19. const Object& target() const { return m_target; }
  20. const Object& handler() const { return m_handler; }
  21. virtual Object* prototype() override;
  22. virtual const Object* prototype() const override;
  23. virtual bool set_prototype(Object* object) override;
  24. virtual bool is_extensible() const override;
  25. virtual bool prevent_extensions() override;
  26. virtual Optional<PropertyDescriptor> get_own_property_descriptor(const PropertyName&) const override;
  27. virtual bool define_property(const StringOrSymbol& property_name, const Object& descriptor, bool throw_exceptions = true) override;
  28. virtual bool has_property(const PropertyName& name) const override;
  29. virtual Value get(const PropertyName& name, Value receiver, bool without_side_effects = false) const override;
  30. virtual bool put(const PropertyName& name, Value value, Value receiver) override;
  31. virtual bool delete_property(const PropertyName& name) override;
  32. bool is_revoked() const { return m_is_revoked; }
  33. void revoke() { m_is_revoked = true; }
  34. private:
  35. virtual void visit_edges(Visitor&) override;
  36. virtual bool is_function() const override { return m_target.is_function(); }
  37. Object& m_target;
  38. Object& m_handler;
  39. bool m_is_revoked { false };
  40. };
  41. }