ProxyObject.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, AllowSideEffects = AllowSideEffects::Yes) 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. virtual bool is_proxy_object() const final { return true; }
  38. Object& m_target;
  39. Object& m_handler;
  40. bool m_is_revoked { false };
  41. };
  42. template<>
  43. inline bool Object::fast_is<ProxyObject>() const { return is_proxy_object(); }
  44. }