You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.0 KiB
92 lines
2.0 KiB
/* DO NOT USE, DODGY BIT FOR VINCE */
|
|
|
|
#include <dom/dom.h>
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "javascript/dukky.h"
|
|
|
|
DUKKY_FUNC_INIT(node, struct dom_node *node)
|
|
{
|
|
DUKKY_FUNC_T(event_target, __init)(ctx, &priv->parent);
|
|
LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
|
|
priv->node = dom_node_ref(node);
|
|
}
|
|
|
|
DUKKY_FUNC_FINI(node)
|
|
{
|
|
/* do any node finalisation here, priv ptr exists */
|
|
LOG("Finalise %p", duk_get_heapptr(ctx, 0));
|
|
dom_node_unref(priv->node);
|
|
DUKKY_FUNC_T(event_target, __fini)(ctx, &priv->parent);
|
|
}
|
|
|
|
static DUKKY_FUNC(node, __constructor)
|
|
{
|
|
DUKKY_CREATE_PRIVATE(node);
|
|
DUKKY_FUNC_T(node, __init)(ctx, priv,
|
|
duk_get_pointer(ctx, 1));
|
|
duk_set_top(ctx, 1);
|
|
return 1;
|
|
}
|
|
|
|
static DUKKY_FUNC(node, __destructor)
|
|
{
|
|
DUKKY_SAFE_GET_PRIVATE(node, 0);
|
|
DUKKY_FUNC_T(node, __fini)(ctx, priv);
|
|
free(priv);
|
|
return 0;
|
|
}
|
|
|
|
static DUKKY_FUNC(node, appendChild)
|
|
{
|
|
DUKKY_GET_METHOD_PRIVATE(node);
|
|
|
|
if (!dukky_instanceof(ctx, PROTO_NAME(NODE))) return 0;
|
|
|
|
DUKKY_SAFE_GET_ANOTHER(other,node,0);
|
|
|
|
dom_exception err;
|
|
dom_node *spare;
|
|
|
|
err = dom_node_append_child(priv->node, other->node, &spare);
|
|
if (err != DOM_NO_ERR) return 0;
|
|
dom_node_unref(spare);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static DUKKY_GETTER(node, textContent)
|
|
{
|
|
DUKKY_GET_METHOD_PRIVATE(node);
|
|
dom_exception exc;
|
|
dom_string *content;
|
|
|
|
exc = dom_node_get_text_content(priv->node, &content);
|
|
if (exc != DOM_NO_ERR) {
|
|
return 0;
|
|
}
|
|
|
|
if (content != NULL) {
|
|
duk_push_lstring(ctx, dom_string_data(content), dom_string_length(content));
|
|
dom_string_unref(content);
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
DUKKY_FUNC(node, __proto)
|
|
{
|
|
/* Populate node's prototypical functionality */
|
|
DUKKY_ADD_METHOD(node, appendChild, 1);
|
|
DUKKY_POPULATE_READONLY_PROPERTY(node, textContent);
|
|
/* Set this prototype's prototype (left-parent)*/
|
|
DUKKY_GET_PROTOTYPE(EVENTTARGET);
|
|
duk_set_prototype(ctx, 0);
|
|
/* And the initialiser/finalizer */
|
|
DUKKY_SET_DESTRUCTOR(0, node);
|
|
DUKKY_SET_CONSTRUCTOR(0, node, 1);
|
|
return 1; /* The proto object */
|
|
}
|