1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-01 02:05:33 +00:00

[mujs] implementation.c

This commit is contained in:
Witold Filipczyk 2023-04-12 17:44:12 +02:00
parent 374f97759c
commit a033ef49a0
5 changed files with 80 additions and 2 deletions

View File

@ -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

View File

@ -0,0 +1,67 @@
/* The MuJS domimplementation object. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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, "<!doctype html>\n<html><head><title>");
add_html_to_string(&str, title, strlen(title));
add_to_string(&str, "</title></head><body></body></html>");
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);
}
}

View File

@ -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')

View File

@ -19,6 +19,8 @@
#include <libxml/HTMLparser.h>
#include <libxml++/libxml++.h>
#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

View File

@ -3,8 +3,16 @@
#include <mujs.h>
#ifdef __cplusplus
extern "C" {
#endif
void mjs_push_implementation(js_State *J);
#ifdef __cplusplus
}
#endif
#endif