mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 22:42:08 +00:00
LibJS+LibWeb: Move native properties to separate getters/setters
This was a bit cumbersome now, but it gets us closer to a format suited for code generation.
This commit is contained in:
parent
56936b97d0
commit
30440134cb
19 changed files with 210 additions and 96 deletions
|
@ -27,20 +27,14 @@
|
|||
#include <AK/Function.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
Array::Array()
|
||||
{
|
||||
set_prototype(interpreter().array_prototype());
|
||||
put_native_property(
|
||||
"length",
|
||||
[this](Object*) {
|
||||
return Value(length());
|
||||
},
|
||||
[](Object*, Value) {
|
||||
ASSERT_NOT_REACHED();
|
||||
});
|
||||
put_native_property("length", length_getter, length_setter);
|
||||
}
|
||||
|
||||
Array::~Array()
|
||||
|
@ -96,4 +90,20 @@ bool Array::put_own_property(Object& this_object, const FlyString& property_name
|
|||
}
|
||||
return Object::put_own_property(this_object, property_name, value);
|
||||
}
|
||||
|
||||
Value Array::length_getter(Interpreter& interpreter)
|
||||
{
|
||||
auto* this_object = interpreter.this_value().to_object(interpreter.heap());
|
||||
if (!this_object)
|
||||
return {};
|
||||
if (!this_object->is_array())
|
||||
return interpreter.throw_exception<Error>("TypeError", "Not an array");
|
||||
return Value(static_cast<const Array*>(this_object)->length());
|
||||
}
|
||||
|
||||
void Array::length_setter(Interpreter&, Value)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue