2020-03-15 14:15:44 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-15 14:15:44 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-03-16 10:20:30 -03:00
|
|
|
#include <LibJS/Runtime/NativeProperty.h>
|
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
2020-03-15 14:15:44 -03:00
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
2020-09-27 13:36:49 -03:00
|
|
|
NativeProperty::NativeProperty(AK::Function<Value(VM&, GlobalObject&)> getter, AK::Function<void(VM&, GlobalObject&, Value)> setter)
|
2020-06-23 12:56:57 -03:00
|
|
|
: m_getter(move(getter))
|
2020-03-15 14:15:44 -03:00
|
|
|
, m_setter(move(setter))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NativeProperty::~NativeProperty()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-27 13:36:49 -03:00
|
|
|
Value NativeProperty::get(VM& vm, GlobalObject& global_object) const
|
2020-03-15 14:15:44 -03:00
|
|
|
{
|
|
|
|
|
if (!m_getter)
|
|
|
|
|
return js_undefined();
|
2020-09-27 13:36:49 -03:00
|
|
|
return m_getter(vm, global_object);
|
2020-03-15 14:15:44 -03:00
|
|
|
}
|
|
|
|
|
|
2020-09-27 13:36:49 -03:00
|
|
|
void NativeProperty::set(VM& vm, GlobalObject& global_object, Value value)
|
2020-03-15 14:15:44 -03:00
|
|
|
{
|
|
|
|
|
if (!m_setter)
|
|
|
|
|
return;
|
2020-09-27 13:36:49 -03:00
|
|
|
m_setter(vm, global_object, move(value));
|
2020-03-15 14:15:44 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|