mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 09:18:52 +00:00
LibJS: Set length property in Object::put_native_function()
This commit is contained in:
parent
b3c4514902
commit
cd3e2690eb
Notes:
sideshowbarker
2024-07-19 07:56:28 +09:00
Author: https://github.com/linusg
Commit: cd3e2690eb
Pull-request: https://github.com/SerenityOS/serenity/pull/1622
Reviewed-by: https://github.com/awesomekling ✅
14 changed files with 25 additions and 23 deletions
|
@ -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()
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -44,7 +44,7 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
|
|||
: m_impl(impl)
|
||||
{
|
||||
put_native_property("fillStyle", fill_style_getter, fill_style_setter);
|
||||
put_native_function("fillRect", fill_rect);
|
||||
put_native_function("fillRect", fill_rect, 4);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DWrapper::~CanvasRenderingContext2DWrapper()
|
||||
|
|
|
@ -40,8 +40,8 @@ namespace Bindings {
|
|||
DocumentWrapper::DocumentWrapper(Document& document)
|
||||
: NodeWrapper(document)
|
||||
{
|
||||
put_native_function("getElementById", get_element_by_id);
|
||||
put_native_function("querySelectorAll", query_selector_all);
|
||||
put_native_function("getElementById", get_element_by_id, 1);
|
||||
put_native_function("querySelectorAll", query_selector_all, 1);
|
||||
}
|
||||
|
||||
DocumentWrapper::~DocumentWrapper()
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Bindings {
|
|||
EventTargetWrapper::EventTargetWrapper(EventTarget& impl)
|
||||
: m_impl(impl)
|
||||
{
|
||||
put_native_function("addEventListener", add_event_listener);
|
||||
put_native_function("addEventListener", add_event_listener, 2);
|
||||
}
|
||||
|
||||
EventTargetWrapper::~EventTargetWrapper()
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace Bindings {
|
|||
HTMLCanvasElementWrapper::HTMLCanvasElementWrapper(HTMLCanvasElement& element)
|
||||
: ElementWrapper(element)
|
||||
{
|
||||
put_native_function("getContext", get_context);
|
||||
put_native_function("getContext", get_context, 1);
|
||||
|
||||
put_native_property("width", width_getter, nullptr);
|
||||
put_native_property("height", height_getter, nullptr);
|
||||
|
|
|
@ -43,9 +43,9 @@ WindowObject::WindowObject(Window& impl)
|
|||
{
|
||||
put_native_property("document", document_getter, document_setter);
|
||||
put_native_function("alert", alert);
|
||||
put_native_function("setInterval", set_interval);
|
||||
put_native_function("requestAnimationFrame", request_animation_frame);
|
||||
put_native_function("cancelAnimationFrame", cancel_animation_frame);
|
||||
put_native_function("setInterval", set_interval, 1);
|
||||
put_native_function("requestAnimationFrame", request_animation_frame, 1);
|
||||
put_native_function("cancelAnimationFrame", cancel_animation_frame, 1);
|
||||
|
||||
put("navigator", heap().allocate<NavigatorObject>());
|
||||
}
|
||||
|
|
|
@ -243,8 +243,8 @@ ReplObject::ReplObject()
|
|||
{
|
||||
put_native_function("exit", exit_interpreter);
|
||||
put_native_function("help", repl_help);
|
||||
put_native_function("load", load_file);
|
||||
put_native_function("save", save_to_file);
|
||||
put_native_function("load", load_file, 1);
|
||||
put_native_function("save", save_to_file, 1);
|
||||
}
|
||||
|
||||
ReplObject::~ReplObject()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue