ProxyObject.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <LibJS/Runtime/Object.h>
  28. namespace JS {
  29. class ProxyObject : public Object {
  30. public:
  31. static ProxyObject* create(GlobalObject&, Object& target, Object& handler);
  32. ProxyObject(Object& target, Object& handler, Object& prototype);
  33. virtual ~ProxyObject() override;
  34. const Object& target() const { return m_target; }
  35. const Object& handler() const { return m_handler; }
  36. virtual Object* prototype() override;
  37. virtual const Object* prototype() const override;
  38. virtual bool set_prototype(Object* object) override;
  39. virtual bool is_extensible() const override;
  40. virtual bool prevent_extensions() override;
  41. virtual Optional<PropertyDescriptor> get_own_property_descriptor(PropertyName) const override;
  42. virtual bool define_property(const FlyString& property_name, const Object& descriptor, bool throw_exceptions = true) override;
  43. virtual bool has_property(PropertyName name) const override;
  44. virtual Value get(PropertyName name) const override;
  45. virtual bool put(PropertyName name, Value value) override;
  46. virtual Value delete_property(PropertyName name) override;
  47. void revoke() { m_is_revoked = true; }
  48. private:
  49. virtual void visit_children(Visitor&) override;
  50. virtual const char* class_name() const override { return "ProxyObject"; }
  51. virtual bool is_proxy_object() const override { return true; }
  52. Object& m_target;
  53. Object& m_handler;
  54. bool m_is_revoked { false };
  55. };
  56. }