mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[quickjs] getNode
This commit is contained in:
parent
010b315257
commit
c271046d76
@ -44,7 +44,6 @@
|
|||||||
|
|
||||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
static JSValue getDoctype(JSContext *ctx, void *node);
|
|
||||||
static JSClassID js_doctype_class_id;
|
static JSClassID js_doctype_class_id;
|
||||||
static JSClassID js_document_class_id;
|
static JSClassID js_document_class_id;
|
||||||
|
|
||||||
@ -2015,7 +2014,7 @@ js_doctype_init(JSContext *ctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue
|
JSValue
|
||||||
getDoctype(JSContext *ctx, void *node)
|
getDoctype(JSContext *ctx, void *node)
|
||||||
{
|
{
|
||||||
#ifdef ECMASCRIPT_DEBUG
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
@ -11,6 +11,7 @@ void *js_doc_getopaque(JSValueConst obj);
|
|||||||
void *document_get_node(JSValueConst obj);
|
void *document_get_node(JSValueConst obj);
|
||||||
JSValue getDocument(JSContext *ctx, void *doc);
|
JSValue getDocument(JSContext *ctx, void *doc);
|
||||||
JSValue getDocument2(JSContext *ctx, void *doc);
|
JSValue getDocument2(JSContext *ctx, void *doc);
|
||||||
|
JSValue getDoctype(JSContext *ctx, void *node);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,13 @@
|
|||||||
#include "js/ecmascript.h"
|
#include "js/ecmascript.h"
|
||||||
#include "js/quickjs/mapa.h"
|
#include "js/quickjs/mapa.h"
|
||||||
#include "js/quickjs.h"
|
#include "js/quickjs.h"
|
||||||
|
#include "js/quickjs/attr.h"
|
||||||
|
#include "js/quickjs/document.h"
|
||||||
#include "js/quickjs/element.h"
|
#include "js/quickjs/element.h"
|
||||||
|
#include "js/quickjs/fragment.h"
|
||||||
|
#include "js/quickjs/node.h"
|
||||||
#include "js/quickjs/nodelist.h"
|
#include "js/quickjs/nodelist.h"
|
||||||
|
#include "js/quickjs/text.h"
|
||||||
|
|
||||||
|
|
||||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
@ -54,6 +59,36 @@ static JSClassDef node_class = {
|
|||||||
"Node",
|
"Node",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
JSValue
|
||||||
|
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 JS_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 getDocument2(ctx, n);
|
||||||
|
case DOCUMENT_TYPE_NODE:
|
||||||
|
return getDoctype(ctx, n);
|
||||||
|
case DOCUMENT_FRAGMENT_NODE:
|
||||||
|
return getDocumentFragment(ctx, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue
|
static JSValue
|
||||||
node_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
|
node_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JSValue js_node_init(JSContext *ctx);
|
int js_node_init(JSContext *ctx);
|
||||||
|
JSValue getNode(JSContext *ctx, void *n);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user