summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Bindings
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-28 22:48:35 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-28 22:51:09 +0100
commit7c4e53f31e23223e67bcb04156ed8b12b515b1b5 (patch)
treea11de166c7587e4488c46f8f64680cd04fb8720d /Libraries/LibWeb/Bindings
parentc209ea1985087ac135cbbd40635de13d5cf701c6 (diff)
downloadserenity-7c4e53f31e23223e67bcb04156ed8b12b515b1b5.zip
LibJS: Rework how native functions are called to improve |this| value
Native functions now only get the Interpreter& as an argument. They can then extract |this| along with any indexed arguments it wants from it. This forces functions that want |this| to actually deal with calling interpreter.this_value().to_object(), and dealing with the possibility of a non-object |this|. This is still not great but let's keep massaging it forward.
Diffstat (limited to 'Libraries/LibWeb/Bindings')
-rw-r--r--Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp6
-rw-r--r--Libraries/LibWeb/Bindings/DocumentWrapper.cpp4
-rw-r--r--Libraries/LibWeb/Bindings/EventTargetWrapper.cpp10
-rw-r--r--Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp6
4 files changed, 19 insertions, 7 deletions
diff --git a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp
index a5c6a576e4..3041bcd1f6 100644
--- a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp
+++ b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp
@@ -24,8 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <AK/Function.h>
#include <AK/FlyString.h>
+#include <AK/Function.h>
+#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Value.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
@@ -50,7 +51,8 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
[this](JS::Object*, JS::Value value) {
m_impl->set_fill_style(value.to_string());
});
- put_native_function("fillRect", [this](JS::Object*, const Vector<JS::Value>& arguments) {
+ put_native_function("fillRect", [this](JS::Interpreter& interpreter) {
+ auto& arguments = interpreter.call_frame().arguments;
if (arguments.size() >= 4) {
m_impl->fill_rect(arguments[0].to_i32(), arguments[1].to_i32(), arguments[2].to_i32(), arguments[3].to_i32());
}
diff --git a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp
index 737a8dca66..04f95713e4 100644
--- a/Libraries/LibWeb/Bindings/DocumentWrapper.cpp
+++ b/Libraries/LibWeb/Bindings/DocumentWrapper.cpp
@@ -25,6 +25,7 @@
*/
#include <AK/FlyString.h>
+#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Value.h>
#include <LibWeb/Bindings/DocumentWrapper.h>
@@ -37,7 +38,8 @@ namespace Bindings {
DocumentWrapper::DocumentWrapper(Document& document)
: NodeWrapper(document)
{
- put_native_function("getElementById", [this](JS::Object*, const Vector<JS::Value>& arguments) -> JS::Value {
+ put_native_function("getElementById", [this](JS::Interpreter& interpreter) -> JS::Value {
+ auto& arguments = interpreter.call_frame().arguments;
if (arguments.is_empty())
return JS::js_null();
auto id = arguments[0].to_string();
diff --git a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp
index 452be45599..fb29a8ed3c 100644
--- a/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp
+++ b/Libraries/LibWeb/Bindings/EventTargetWrapper.cpp
@@ -24,8 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <AK/Function.h>
#include <AK/FlyString.h>
+#include <AK/Function.h>
+#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Function.h>
#include <LibWeb/Bindings/EventListenerWrapper.h>
#include <LibWeb/Bindings/EventTargetWrapper.h>
@@ -38,7 +39,12 @@ namespace Bindings {
EventTargetWrapper::EventTargetWrapper(EventTarget& impl)
: m_impl(impl)
{
- put_native_function("addEventListener", [](Object* this_object, const Vector<JS::Value>& arguments) {
+ put_native_function("addEventListener", [](JS::Interpreter& interpreter) -> JS::Value {
+ auto* this_object = interpreter.this_value().to_object(interpreter.heap());
+ if (!this_object)
+ return {};
+
+ auto& arguments = interpreter.call_frame().arguments;
if (arguments.size() < 2)
return JS::js_undefined();
diff --git a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp
index 99b8f9df10..2c78580280 100644
--- a/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp
+++ b/Libraries/LibWeb/Bindings/HTMLCanvasElementWrapper.cpp
@@ -24,8 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <AK/Function.h>
#include <AK/FlyString.h>
+#include <AK/Function.h>
+#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Value.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
@@ -39,7 +40,8 @@ namespace Bindings {
HTMLCanvasElementWrapper::HTMLCanvasElementWrapper(HTMLCanvasElement& element)
: ElementWrapper(element)
{
- put_native_function("getContext", [this](JS::Object*, const Vector<JS::Value>& arguments) -> JS::Value {
+ 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);