From 118a2438dfc3bc06b03cd6e73a2e3ce95349f0c8 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Tue, 17 Sep 2024 15:36:45 +0200 Subject: [PATCH] [quickjs] Check for NULL and return JS_EXCEPTION in contains --- src/ecmascript/quickjs/element.c | 10 +++++++--- src/ecmascript/quickjs/fragment.c | 10 +++++++--- src/ecmascript/quickjs/text.c | 9 ++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ecmascript/quickjs/element.c b/src/ecmascript/quickjs/element.c index 92e075b66..61b147d7d 100644 --- a/src/ecmascript/quickjs/element.c +++ b/src/ecmascript/quickjs/element.c @@ -2897,14 +2897,18 @@ js_element_contains(JSContext *ctx, JSValueConst this_val, int argc, JSValueCons dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id)); if (!el) { - return JS_FALSE; + return JS_EXCEPTION; } //dom_node_ref(el); - dom_node *el2 = (dom_node *)(js_getopaque(argv[0], js_element_class_id)); + dom_node *el2 = NULL; + + if (!JS_IsNull(argv[0])) { + el2 = (dom_node *)(js_getopaque(argv[0], js_element_class_id)); + } if (!el2) { //dom_node_unref(el); - return JS_FALSE; + return JS_EXCEPTION; } #ifdef ECMASCRIPT_DEBUG fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); diff --git a/src/ecmascript/quickjs/fragment.c b/src/ecmascript/quickjs/fragment.c index 6782cafa1..f72f12de8 100644 --- a/src/ecmascript/quickjs/fragment.c +++ b/src/ecmascript/quickjs/fragment.c @@ -1135,14 +1135,18 @@ js_fragment_contains(JSContext *ctx, JSValueConst this_val, int argc, JSValueCon dom_node *el = (dom_node *)(js_getopaque_fragment(this_val, js_fragment_class_id)); if (!el) { - return JS_FALSE; + return JS_EXCEPTION; } + dom_node *el2 = NULL; + + if (!JS_IsNull(argv[0])) { //dom_node_ref(el); - dom_node *el2 = (dom_node *)(js_getopaque_fragment(argv[0], js_fragment_class_id)); + el2 = (dom_node *)(js_getopaque_fragment(argv[0], js_fragment_class_id)); + } if (!el2) { //dom_node_unref(el); - return JS_FALSE; + return JS_EXCEPTION; } #ifdef ECMASCRIPT_DEBUG fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); diff --git a/src/ecmascript/quickjs/text.c b/src/ecmascript/quickjs/text.c index 4e5ed8722..708b1bfe2 100644 --- a/src/ecmascript/quickjs/text.c +++ b/src/ecmascript/quickjs/text.c @@ -1169,14 +1169,17 @@ js_text_contains(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst * dom_node *el = (dom_node *)(js_getopaque_text(this_val, js_text_class_id)); if (!el) { - return JS_FALSE; + return JS_EXCEPTION; } + dom_node *el2 = NULL; //dom_node_ref(el); - dom_node *el2 = (dom_node *)(js_getopaque_text(argv[0], js_text_class_id)); + if (!JS_IsNull(argv[0])) { + el2 = (dom_node *)(js_getopaque_text(argv[0], js_text_class_id)); + } if (!el2) { //dom_node_unref(el); - return JS_FALSE; + return JS_EXCEPTION; } #ifdef ECMASCRIPT_DEBUG fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__);