From 6552a3df8a2cfe226514cfa43eb986e820dab23e Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 6 Jul 2024 11:43:14 +0200 Subject: [PATCH] [quickjs] "Fixes" related to DOMParser --- src/ecmascript/quickjs/document.c | 28 ++++++++++++++++++++++++++++ src/ecmascript/quickjs/document.h | 1 + src/ecmascript/quickjs/domparser.c | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/ecmascript/quickjs/document.c b/src/ecmascript/quickjs/document.c index be5be4dc..b815fb22 100644 --- a/src/ecmascript/quickjs/document.c +++ b/src/ecmascript/quickjs/document.c @@ -2009,6 +2009,34 @@ getDocument(JSContext *ctx, void *doc) RETURN_JS(document_obj); } +JSValue +getDocument2(JSContext *ctx, void *doc) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + struct js_document_private *doc_private = (struct js_document_private *)mem_calloc(1, sizeof(*doc_private)); + + if (!doc_private) { + return JS_NULL; + } + init_list(doc_private->listeners); + + if (doc) { + dom_node_ref((dom_node *)doc); + } + doc_private->node = doc; + struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); + doc_private->interpreter = interpreter; + + JSValue document_obj = JS_NewObjectClass(ctx, js_document_class_id); + JS_SetPropertyFunctionList(ctx, document_obj, js_document_proto_funcs, countof(js_document_proto_funcs)); + JS_SetOpaque(document_obj, doc_private); + doc_private->thisval = document_obj; + + RETURN_JS(document_obj); +} + static void document_event_handler(dom_event *event, void *pw) { diff --git a/src/ecmascript/quickjs/document.h b/src/ecmascript/quickjs/document.h index ebd60d5e..d8c8db8b 100644 --- a/src/ecmascript/quickjs/document.h +++ b/src/ecmascript/quickjs/document.h @@ -8,6 +8,7 @@ extern "C" { #endif JSValue getDocument(JSContext *ctx, void *doc); +JSValue getDocument2(JSContext *ctx, void *doc); #ifdef __cplusplus } diff --git a/src/ecmascript/quickjs/domparser.c b/src/ecmascript/quickjs/domparser.c index 5c6e746f..4673c591 100644 --- a/src/ecmascript/quickjs/domparser.c +++ b/src/ecmascript/quickjs/domparser.c @@ -54,7 +54,7 @@ js_domparser_parseFromString(JSContext *ctx, JSValueConst this_val, int argc, JS return JS_NULL; } - return getDocument(ctx, doc); + return getDocument2(ctx, doc); } static JSValue