From a033ef49a0da4f88e1514474326c95f04cced95e Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Wed, 12 Apr 2023 17:44:12 +0200 Subject: [PATCH] [mujs] implementation.c --- src/ecmascript/libdom/mujs/Makefile | 2 +- src/ecmascript/libdom/mujs/implementation.c | 67 +++++++++++++++++++++ src/ecmascript/libdom/mujs/meson.build | 2 +- src/ecmascript/mujs/implementation.cpp | 3 + src/ecmascript/mujs/implementation.h | 8 +++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/ecmascript/libdom/mujs/implementation.c diff --git a/src/ecmascript/libdom/mujs/Makefile b/src/ecmascript/libdom/mujs/Makefile index 2bf45878..368796d3 100644 --- a/src/ecmascript/libdom/mujs/Makefile +++ b/src/ecmascript/libdom/mujs/Makefile @@ -1,6 +1,6 @@ top_builddir=../../../.. include $(top_builddir)/Makefile.config -OBJS = attr.o attributes.o collection.o console.o forms.o history.o mapa.obj +OBJS = attr.o attributes.o collection.o console.o forms.o history.o implementation.o mapa.obj include $(top_srcdir)/Makefile.lib diff --git a/src/ecmascript/libdom/mujs/implementation.c b/src/ecmascript/libdom/mujs/implementation.c new file mode 100644 index 00000000..ac78d744 --- /dev/null +++ b/src/ecmascript/libdom/mujs/implementation.c @@ -0,0 +1,67 @@ +/* The MuJS domimplementation object. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "elinks.h" + +#include "ecmascript/ecmascript.h" +#include "ecmascript/mujs.h" +#include "ecmascript/mujs/document.h" +#include "ecmascript/mujs/implementation.h" +#include "util/conv.h" + +static void +mjs_implementation_createHTMLDocument(js_State *J) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + const char *title = js_tostring(J, 1); + + if (!title) { + js_error(J, "!title"); + return; + } + struct string str; + + if (!init_string(&str)) { + js_error(J, "out of memory"); + return; + } + add_to_string(&str, "\n"); + add_html_to_string(&str, title, strlen(title)); + add_to_string(&str, ""); + + void *docu = document_parse_text(str.source, str.length); + done_string(&str); + mjs_push_document(J, docu); +} + +static void +mjs_implementation_toString(js_State *J) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + js_pushstring(J, "[implementation object]"); +} + +void +mjs_push_implementation(js_State *J) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + + js_newobject(J); + { + addmethod(J, "createHTMLDocument", mjs_implementation_createHTMLDocument, 1); + addmethod(J, "toString", mjs_implementation_toString, 0); + } +} diff --git a/src/ecmascript/libdom/mujs/meson.build b/src/ecmascript/libdom/mujs/meson.build index 03f12132..4ddef27b 100644 --- a/src/ecmascript/libdom/mujs/meson.build +++ b/src/ecmascript/libdom/mujs/meson.build @@ -1 +1 @@ -srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'mapa.cpp') +srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'forms.c', 'history.c', 'implementation.c', 'mapa.cpp') diff --git a/src/ecmascript/mujs/implementation.cpp b/src/ecmascript/mujs/implementation.cpp index 8e2da8bd..8b0d3d10 100644 --- a/src/ecmascript/mujs/implementation.cpp +++ b/src/ecmascript/mujs/implementation.cpp @@ -19,6 +19,8 @@ #include #include +#ifndef CONFIG_LIBDOM + static void mjs_implementation_createHTMLDocument(js_State *J) { @@ -73,3 +75,4 @@ mjs_push_implementation(js_State *J) addmethod(J, "toString", mjs_implementation_toString, 0); } } +#endif diff --git a/src/ecmascript/mujs/implementation.h b/src/ecmascript/mujs/implementation.h index 9c3838ab..850611ca 100644 --- a/src/ecmascript/mujs/implementation.h +++ b/src/ecmascript/mujs/implementation.h @@ -3,8 +3,16 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + void mjs_push_implementation(js_State *J); +#ifdef __cplusplus +} +#endif + #endif