mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] Added function getNode
This function will create appropriate object based on node type.
This commit is contained in:
parent
097939ae91
commit
be98f168cf
@ -95,7 +95,6 @@ struct document_private {
|
||||
enum readyState state;
|
||||
};
|
||||
|
||||
static JSObject *getDoctype(JSContext *ctx, void *node);
|
||||
static void document_event_handler(dom_event *event, void *pw);
|
||||
|
||||
static void document_finalize(JS::GCContext *op, JSObject *obj)
|
||||
@ -2381,7 +2380,7 @@ JSPropertySpec doctype_props[] = {
|
||||
JS_PS_END
|
||||
};
|
||||
|
||||
static JSObject *
|
||||
JSObject *
|
||||
getDoctype(JSContext *ctx, void *node)
|
||||
{
|
||||
#ifdef ECMASCRIPT_DEBUG
|
||||
|
@ -11,6 +11,8 @@ extern const spidermonkeyFunctionSpec document_funcs[];
|
||||
extern JSPropertySpec document_props[];
|
||||
|
||||
JSObject *getDocument(JSContext *ctx, void *doc);
|
||||
JSObject *getDoctype(JSContext *ctx, void *node);
|
||||
|
||||
bool initDocument(JSContext *ctx, struct ecmascript_interpreter *interpreter, JSObject *document_obj, void *doc);
|
||||
|
||||
#endif
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "js/libdom/dom.h"
|
||||
|
||||
#include "js/spidermonkey/util.h"
|
||||
#include <js/BigInt.h>
|
||||
#include <js/Conversions.h>
|
||||
@ -25,8 +27,13 @@
|
||||
#include "document/view.h"
|
||||
#include "js/ecmascript.h"
|
||||
#include "js/spidermonkey.h"
|
||||
#include "js/spidermonkey/attr.h"
|
||||
#include "js/spidermonkey/document.h"
|
||||
#include "js/spidermonkey/element.h"
|
||||
#include "js/spidermonkey/fragment.h"
|
||||
#include "js/spidermonkey/heartbeat.h"
|
||||
#include "js/spidermonkey/node.h"
|
||||
#include "js/spidermonkey/text.h"
|
||||
#include "js/timer.h"
|
||||
#include "intl/libintl.h"
|
||||
#include "main/select.h"
|
||||
@ -83,6 +90,36 @@ JSClass node_class = {
|
||||
&node_ops
|
||||
};
|
||||
|
||||
JSObject *
|
||||
getNode(JSContext *ctx, void *n)
|
||||
{
|
||||
dom_node *node = (dom_node *)n;
|
||||
dom_node_type typ;
|
||||
dom_exception exc = dom_node_get_node_type(node, &typ);
|
||||
|
||||
if (exc != DOM_NO_ERR) {
|
||||
return NULL;
|
||||
}
|
||||
switch (typ) {
|
||||
case ELEMENT_NODE:
|
||||
return getElement(ctx, n);
|
||||
case ATTRIBUTE_NODE:
|
||||
return getAttr(ctx, n);
|
||||
case TEXT_NODE:
|
||||
case CDATA_SECTION_NODE:
|
||||
case PROCESSING_INSTRUCTION_NODE:
|
||||
case COMMENT_NODE:
|
||||
default:
|
||||
return getText(ctx, n);
|
||||
case DOCUMENT_NODE:
|
||||
return getDocument(ctx, n);
|
||||
case DOCUMENT_TYPE_NODE:
|
||||
return getDoctype(ctx, n);
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
return getDocumentFragment(ctx, n);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
node_constructor(JSContext* ctx, unsigned argc, JS::Value* vp)
|
||||
{
|
||||
|
@ -6,5 +6,6 @@
|
||||
extern JSClass node_class;
|
||||
extern JSPropertySpec node_static_props[];
|
||||
bool node_constructor(JSContext* ctx, unsigned argc, JS::Value* vp);
|
||||
JSObject *getNode(JSContext *ctx, void *node);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user