1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +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:
Andreas Kling 2020-03-29 00:37:33 +01:00
parent 56936b97d0
commit 30440134cb
19 changed files with 210 additions and 96 deletions

View file

@ -42,18 +42,8 @@ HTMLCanvasElementWrapper::HTMLCanvasElementWrapper(HTMLCanvasElement& element)
{
put_native_function("getContext", get_context);
put_native_property(
"width",
[this](JS::Object*) {
return JS::Value(node().preferred_width());
},
nullptr);
put_native_property(
"height",
[this](JS::Object*) {
return JS::Value(node().preferred_height());
},
nullptr);
put_native_property("width", width_getter, nullptr);
put_native_property("height", height_getter, nullptr);
}
HTMLCanvasElementWrapper::~HTMLCanvasElementWrapper()
@ -70,20 +60,41 @@ const HTMLCanvasElement& HTMLCanvasElementWrapper::node() const
return static_cast<const HTMLCanvasElement&>(NodeWrapper::node());
}
JS::Value HTMLCanvasElementWrapper::get_context(JS::Interpreter& interpreter)
static HTMLCanvasElement* impl_from(JS::Interpreter& interpreter)
{
auto* this_object = interpreter.this_value().to_object(interpreter.heap());
if (!this_object)
return nullptr;
// FIXME: Verify that it's a HTMLCanvasElementWrapper somehow!
return &static_cast<HTMLCanvasElementWrapper*>(this_object)->node();
}
JS::Value HTMLCanvasElementWrapper::get_context(JS::Interpreter& interpreter)
{
auto* impl = impl_from(interpreter);
if (!impl)
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());
auto* context = impl->get_context(arguments[0].to_string());
return wrap(interpreter.heap(), *context);
}
return JS::js_undefined();
}
JS::Value HTMLCanvasElementWrapper::width_getter(JS::Interpreter& interpreter)
{
if (auto* impl = impl_from(interpreter))
return JS::Value(impl->preferred_width());
return {};
}
JS::Value HTMLCanvasElementWrapper::height_getter(JS::Interpreter& interpreter)
{
if (auto* impl = impl_from(interpreter))
return JS::Value(impl->preferred_height());
return {};
}
}
}