1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibJS+LibWeb: Move native JS functions into dedicated member functions

Instead of implementing every native function as a lambda function,
use static member functions instead.

This makes it easier to navigate the code + backtraces look nicer. :^)
This commit is contained in:
Andreas Kling 2020-03-28 23:10:37 +01:00
parent 7c4e53f31e
commit 56936b97d0
20 changed files with 233 additions and 149 deletions

View file

@ -40,14 +40,8 @@ namespace Bindings {
HTMLCanvasElementWrapper::HTMLCanvasElementWrapper(HTMLCanvasElement& element)
: ElementWrapper(element)
{
put_native_function("getContext", [this](JS::Interpreter& interpreter) -> JS::Value {
auto& arguments = interpreter.call_frame().arguments;
if (arguments.size() >= 1) {
auto* context = node().get_context(arguments[0].to_string());
return wrap(heap(), *context);
}
return JS::js_undefined();
});
put_native_function("getContext", get_context);
put_native_property(
"width",
[this](JS::Object*) {
@ -76,5 +70,20 @@ const HTMLCanvasElement& HTMLCanvasElementWrapper::node() const
return static_cast<const HTMLCanvasElement&>(NodeWrapper::node());
}
JS::Value HTMLCanvasElementWrapper::get_context(JS::Interpreter& interpreter)
{
auto* this_object = interpreter.this_value().to_object(interpreter.heap());
if (!this_object)
return {};
// FIXME: Verify that it's an HTMLCanvasElementWrapper somehow!
auto& node = static_cast<HTMLCanvasElementWrapper*>(this_object)->node();
auto& arguments = interpreter.call_frame().arguments;
if (arguments.size() >= 1) {
auto* context = node.get_context(arguments[0].to_string());
return wrap(interpreter.heap(), *context);
}
return JS::js_undefined();
}
}
}