1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:18:11 +00:00

LibJS: Set length property in Object::put_native_function()

This commit is contained in:
Linus Groh 2020-04-04 14:13:53 +01:00 committed by Andreas Kling
parent b3c4514902
commit cd3e2690eb
14 changed files with 25 additions and 23 deletions

View file

@ -37,7 +37,7 @@ ArrayPrototype::ArrayPrototype()
{
put_native_function("shift", shift);
put_native_function("pop", pop);
put_native_function("push", push);
put_native_function("push", push, 1);
}
ArrayPrototype::~ArrayPrototype()

View file

@ -16,7 +16,7 @@ namespace JS {
GlobalObject::GlobalObject()
{
put_native_function("gc", gc);
put_native_function("isNaN", is_nan);
put_native_function("isNaN", is_nan, 1);
// FIXME: These are read-only in ES5
put("NaN", js_nan());

View file

@ -34,7 +34,7 @@ namespace JS {
MathObject::MathObject()
{
put_native_function("abs", abs);
put_native_function("abs", abs, 1);
put_native_function("random", random);
put("E", Value(M_E));

View file

@ -155,9 +155,11 @@ void Object::put(const FlyString& property_name, Value value)
put_own_property(*this, property_name, value);
}
void Object::put_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)> native_function)
void Object::put_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)> native_function, i32 length)
{
put(property_name, heap().allocate<NativeFunction>(move(native_function)));
auto* function = heap().allocate<NativeFunction>(move(native_function));
function->put("length", Value(length));
put(property_name, function);
}
void Object::put_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter)

View file

@ -49,7 +49,7 @@ public:
virtual Optional<Value> get_own_property(const Object& this_object, const FlyString& property_name) const;
virtual bool put_own_property(Object& this_object, const FlyString& property_name, Value);
void put_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)>);
void put_native_function(const FlyString& property_name, AK::Function<Value(Interpreter&)>, i32 length = 0);
void put_native_property(const FlyString& property_name, AK::Function<Value(Interpreter&)> getter, AK::Function<void(Interpreter&, Value)> setter);
virtual bool is_array() const { return false; }

View file

@ -37,9 +37,9 @@ ObjectConstructor::ObjectConstructor()
{
put("prototype", interpreter().object_prototype());
put_native_function("getOwnPropertyNames", get_own_property_names);
put_native_function("getPrototypeOf", get_prototype_of);
put_native_function("setPrototypeOf", set_prototype_of);
put_native_function("getOwnPropertyNames", get_own_property_names, 1);
put_native_function("getPrototypeOf", get_prototype_of, 1);
put_native_function("setPrototypeOf", set_prototype_of, 2);
}
ObjectConstructor::~ObjectConstructor()

View file

@ -37,7 +37,7 @@ ObjectPrototype::ObjectPrototype()
{
set_prototype(nullptr);
put_native_function("hasOwnProperty", has_own_property);
put_native_function("hasOwnProperty", has_own_property, 1);
put_native_function("toString", to_string);
put_native_function("valueOf", value_of);
}

View file

@ -39,9 +39,9 @@ namespace JS {
StringPrototype::StringPrototype()
{
put_native_property("length", length_getter, nullptr);
put_native_function("charAt", char_at);
put_native_function("repeat", repeat);
put_native_function("startsWith", starts_with);
put_native_function("charAt", char_at, 1);
put_native_function("repeat", repeat, 1);
put_native_function("startsWith", starts_with, 1);
}
StringPrototype::~StringPrototype()