mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mujs] DOMParser (not tested)
This commit is contained in:
parent
56c11ef07a
commit
0f5340834f
@ -28,6 +28,7 @@
|
||||
#include "ecmascript/mujs/console.h"
|
||||
#include "ecmascript/mujs/customevent.h"
|
||||
#include "ecmascript/mujs/document.h"
|
||||
#include "ecmascript/mujs/domparser.h"
|
||||
#include "ecmascript/mujs/element.h"
|
||||
#include "ecmascript/mujs/event.h"
|
||||
#include "ecmascript/mujs/history.h"
|
||||
@ -148,6 +149,7 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
mjs_messageEvent_init(J);
|
||||
mjs_customEvent_init(J);
|
||||
mjs_url_init(J);
|
||||
mjs_domparser_init(J);
|
||||
|
||||
return J;
|
||||
#if 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
|
||||
OBJS = attr.o attributes.o collection.o console.o css.o customevent.o dataset.o document.o domrect.o element.o event.o form.o forms.o history.o implementation.o input.o \
|
||||
OBJS = attr.o attributes.o collection.o console.o css.o customevent.o dataset.o document.o domparser.o domrect.o element.o event.o form.o forms.o history.o implementation.o input.o \
|
||||
keyboard.o localstorage.o location.o mapa.o message.o navigator.o nodelist.o nodelist2.o screen.o style.o tokenlist.o unibar.o url.o window.o xhr.o
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -1692,6 +1692,9 @@ mjs_push_document(js_State *J, void *doc)
|
||||
doc_private->node = doc;
|
||||
doc_private->ref_count = 1;
|
||||
doc_private->thisval = js_ref(J);
|
||||
if (doc) {
|
||||
dom_node_ref((dom_node *)doc);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
73
src/ecmascript/mujs/domparser.c
Normal file
73
src/ecmascript/mujs/domparser.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* The MuJS DOMParser implementation. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "document/libdom/doc.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
#include "ecmascript/mujs.h"
|
||||
#include "ecmascript/mujs/document.h"
|
||||
#include "ecmascript/mujs/domparser.h"
|
||||
#include "intl/charsets.h"
|
||||
#include "terminal/event.h"
|
||||
|
||||
static void mjs_domparser_parseFromString(js_State *J);
|
||||
|
||||
static void
|
||||
mjs_domparser_parseFromString(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
const char *str = js_tostring(J, 1);
|
||||
|
||||
if (!str) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
dom_html_document *doc = (dom_html_document *)document_parse_text("utf-8", str, strlen(str));
|
||||
|
||||
if (!doc) {
|
||||
js_pushnull(J);
|
||||
return;
|
||||
}
|
||||
mjs_push_document(J, doc);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_domparser_fun(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
js_pushundefined(J);
|
||||
}
|
||||
|
||||
static void
|
||||
mjs_domparser_constructor(js_State *J)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
js_newobject(J);
|
||||
{
|
||||
addmethod(J, "parseFromString", mjs_domparser_parseFromString, 2);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
mjs_domparser_init(js_State *J)
|
||||
{
|
||||
js_pushglobal(J);
|
||||
js_newcconstructor(J, mjs_domparser_fun, mjs_domparser_constructor, "DOMParser", 0);
|
||||
js_defglobal(J, "DOMParser", JS_DONTENUM);
|
||||
return 0;
|
||||
}
|
16
src/ecmascript/mujs/domparser.h
Normal file
16
src/ecmascript/mujs/domparser.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef EL__ECMASCRIPT_MUJS_DOMPARSER_H
|
||||
#define EL__ECMASCRIPT_MUJS_DOMPARSER_H
|
||||
|
||||
#include <mujs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int mjs_domparser_init(js_State *J);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,3 +1,3 @@
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'customevent.c', 'dataset.c', 'document.c', 'domrect.c',
|
||||
srcs += files('attr.c', 'attributes.c', 'collection.c', 'console.c', 'css.c', 'customevent.c', 'dataset.c', 'document.c', 'domparser.c', 'domrect.c',
|
||||
'element.c', 'event.c', 'form.c', 'forms.c', 'history.c', 'implementation.c', 'input.c', 'keyboard.c',
|
||||
'localstorage.c', 'location.c', 'mapa.c', 'message.c', 'navigator.c', 'nodelist.c', 'nodelist2.c', 'screen.c', 'style.c', 'tokenlist.c', 'unibar.c', 'url.c', 'window.c', 'xhr.c')
|
||||
|
Loading…
Reference in New Issue
Block a user