NativeProperty.cpp 766 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/NativeProperty.h>
  7. #include <LibJS/Runtime/Value.h>
  8. namespace JS {
  9. NativeProperty::NativeProperty(AK::Function<Value(VM&, GlobalObject&)> getter, AK::Function<void(VM&, GlobalObject&, Value)> setter)
  10. : m_getter(move(getter))
  11. , m_setter(move(setter))
  12. {
  13. }
  14. NativeProperty::~NativeProperty()
  15. {
  16. }
  17. Value NativeProperty::get(VM& vm, GlobalObject& global_object) const
  18. {
  19. if (!m_getter)
  20. return js_undefined();
  21. return m_getter(vm, global_object);
  22. }
  23. void NativeProperty::set(VM& vm, GlobalObject& global_object, Value value)
  24. {
  25. if (!m_setter)
  26. return;
  27. m_setter(vm, global_object, move(value));
  28. }
  29. }