mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] DOMParser
Not tested.
This commit is contained in:
parent
d10fe7d3c7
commit
7c249117f9
@ -30,6 +30,7 @@
|
||||
#include "ecmascript/spidermonkey/console.h"
|
||||
#include "ecmascript/spidermonkey/customevent.h"
|
||||
#include "ecmascript/spidermonkey/document.h"
|
||||
#include "ecmascript/spidermonkey/domparser.h"
|
||||
#include "ecmascript/spidermonkey/event.h"
|
||||
#include "ecmascript/spidermonkey/form.h"
|
||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||
@ -235,7 +236,7 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
JSObject *console_obj, *document_obj, /* *forms_obj,*/ *history_obj,
|
||||
*statusbar_obj, *menubar_obj, *navigator_obj, *localstorage_obj, *screen_obj,
|
||||
*xhr_obj, *event_obj, *keyboardEvent_obj, *messageEvent_obj, *customEvent_obj,
|
||||
*url_obj, *urlSearchParams_obj;
|
||||
*url_obj, *urlSearchParams_obj, *domparser_obj;
|
||||
|
||||
assert(interpreter);
|
||||
if (!js_module_init_ok) return NULL;
|
||||
@ -443,6 +444,17 @@ spidermonkey_get_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
if (!urlSearchParams_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
domparser_obj = spidermonkey_InitClass(ctx, global, NULL,
|
||||
&domparser_class, domparser_constructor, 0,
|
||||
NULL,
|
||||
domparser_funcs,
|
||||
NULL, NULL, "DOMParser");
|
||||
|
||||
if (!domparser_obj) {
|
||||
goto release_and_fail;
|
||||
}
|
||||
|
||||
#if 1
|
||||
// Register a hook in order to provide modules
|
||||
JS::SetModuleResolveHook(JS_GetRuntime(ctx), ExampleResolveHook);
|
||||
|
@ -2,7 +2,8 @@ top_builddir=../../..
|
||||
include $(top_builddir)/Makefile.config
|
||||
INCLUDES += $(SPIDERMONKEY_CFLAGS)
|
||||
|
||||
OBJS = attr.obj attributes.obj collection.obj console.obj css.obj customevent.obj dataset.obj document.obj domrect.obj element.obj event.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
||||
OBJS = attr.obj attributes.obj collection.obj console.obj css.obj customevent.obj dataset.obj document.obj domparser.obj domrect.obj \
|
||||
element.obj event.obj form.obj forms.obj heartbeat.obj history.obj implementation.obj input.obj \
|
||||
keyboard.obj localstorage.obj location.obj message.obj navigator.obj nodelist.obj nodelist2.obj screen.obj style.obj tokenlist.obj unibar.obj url.obj urlsearchparams.obj window.obj xhr.obj
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
151
src/ecmascript/spidermonkey/domparser.cpp
Normal file
151
src/ecmascript/spidermonkey/domparser.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
/* The SpiderMonkey DomParser object implementation. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "ecmascript/libdom/dom.h"
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
#include <js/BigInt.h>
|
||||
#include <js/Conversions.h>
|
||||
|
||||
#include "bfu/dialog.h"
|
||||
#include "cache/cache.h"
|
||||
#include "cookies/cookies.h"
|
||||
#include "dialogs/menu.h"
|
||||
#include "dialogs/status.h"
|
||||
#include "document/html/frames.h"
|
||||
#include "document/libdom/doc.h"
|
||||
#include "document/document.h"
|
||||
#include "document/forms.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
#include "ecmascript/spidermonkey.h"
|
||||
#include "ecmascript/spidermonkey/document.h"
|
||||
#include "ecmascript/spidermonkey/domparser.h"
|
||||
#include "ecmascript/spidermonkey/heartbeat.h"
|
||||
#include "ecmascript/timer.h"
|
||||
#include "intl/libintl.h"
|
||||
#include "main/select.h"
|
||||
#include "main/timer.h"
|
||||
#include "network/connection.h"
|
||||
#include "osdep/newwin.h"
|
||||
#include "osdep/sysname.h"
|
||||
#include "protocol/http/http.h"
|
||||
#include "protocol/uri.h"
|
||||
#include "session/download.h"
|
||||
#include "session/history.h"
|
||||
#include "session/location.h"
|
||||
#include "session/session.h"
|
||||
#include "session/task.h"
|
||||
#include "terminal/tab.h"
|
||||
#include "terminal/terminal.h"
|
||||
#include "util/conv.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "viewer/text/draw.h"
|
||||
#include "viewer/text/form.h"
|
||||
#include "viewer/text/link.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
static bool domparser_parseFromString(JSContext *ctx, unsigned int argc, JS::Value *vp);
|
||||
|
||||
JSClassOps domparser_ops = {
|
||||
nullptr, // addProperty
|
||||
nullptr, // deleteProperty
|
||||
nullptr, // enumerate
|
||||
nullptr, // newEnumerate
|
||||
nullptr, // resolve
|
||||
nullptr, // mayResolve
|
||||
nullptr, // finalize
|
||||
nullptr, // call
|
||||
nullptr, // construct
|
||||
JS_GlobalObjectTraceHook // trace
|
||||
};
|
||||
|
||||
JSClass domparser_class = {
|
||||
"DOMParser",
|
||||
JSCLASS_HAS_RESERVED_SLOTS(0),
|
||||
&domparser_ops
|
||||
};
|
||||
|
||||
bool
|
||||
domparser_constructor(JSContext* ctx, unsigned argc, JS::Value* vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject newObj(ctx, JS_NewObjectForConstructor(ctx, &domparser_class, args));
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
if (!newObj) {
|
||||
return false;
|
||||
}
|
||||
args.rval().setObject(*newObj);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const spidermonkeyFunctionSpec domparser_funcs[] = {
|
||||
{ "parseFromString", domparser_parseFromString, 2 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static bool
|
||||
domparser_parseFromString(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||
#endif
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
JS::RootedObject hobj(ctx, &args.thisv().toObject());
|
||||
JS::Realm *comp = js::GetContextRealm(ctx);
|
||||
|
||||
if (!comp) {
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if (argc < 1) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
char *text = jsval_to_string(ctx, args[0]);
|
||||
|
||||
if (!text) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
dom_html_document *doc = (dom_html_document *)document_parse_text("utf-8", text, strlen(text));
|
||||
mem_free(text);
|
||||
|
||||
if (!doc) {
|
||||
args.rval().setNull();
|
||||
return true;
|
||||
}
|
||||
return getDocument(ctx, doc);
|
||||
}
|
10
src/ecmascript/spidermonkey/domparser.h
Normal file
10
src/ecmascript/spidermonkey/domparser.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef EL__ECMASCRIPT_SPIDERMONKEY_DOMPARSER_H
|
||||
#define EL__ECMASCRIPT_SPIDERMONKEY_DOMPARSER_H
|
||||
|
||||
#include "ecmascript/spidermonkey/util.h"
|
||||
|
||||
extern JSClass domparser_class;
|
||||
extern const spidermonkeyFunctionSpec domparser_funcs[];
|
||||
bool domparser_constructor(JSContext* ctx, unsigned argc, JS::Value* vp);
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'css.cpp', 'customevent.cpp', 'dataset.cpp', 'document.cpp', 'domrect.cpp', 'element.cpp', 'event.cpp',
|
||||
srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'css.cpp', 'customevent.cpp', 'dataset.cpp', 'document.cpp', 'domparser.cpp', 'domrect.cpp', 'element.cpp', 'event.cpp',
|
||||
'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp', 'input.cpp', 'keyboard.cpp',
|
||||
'localstorage.cpp', 'location.cpp', 'message.cpp', 'navigator.cpp', 'nodelist.cpp', 'nodelist2.cpp', 'screen.cpp', 'style.cpp', 'tokenlist.cpp', 'unibar.cpp', 'url.cpp',
|
||||
'urlsearchparams.cpp', 'window.cpp', 'xhr.cpp')
|
||||
|
Loading…
Reference in New Issue
Block a user