From e46a705b0f3603b3cc92883c4731587cadbfe9c0 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 14 Aug 2015 15:34:00 +0200 Subject: More (untested) Node stuff --- javascript/duktape/Node.bnd | 89 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 7 deletions(-) (limited to 'javascript/duktape/Node.bnd') diff --git a/javascript/duktape/Node.bnd b/javascript/duktape/Node.bnd index 6ceab44c7..80fc1bada 100644 --- a/javascript/duktape/Node.bnd +++ b/javascript/duktape/Node.bnd @@ -44,9 +44,28 @@ getter Node::nodeName() return 1; %} -/*** @todo baseURI */ +getter Node::baseURI() +%{ + dom_exception exc; + dom_string *base; + exc = dom_node_get_base(priv->node, &base); + if (exc != DOM_NO_ERR) return 0; + duk_push_lstring(ctx, dom_string_data(base), dom_string_length(base)); + dom_string_unref(base); + return 1; +%} -/*** @todo ownerDocument */ +getter Node::ownerDocument() +%{ + dom_exception exc; + dom_node *doc; + exc = dom_node_get_owner_document(priv->node, &doc); + if (exc != DOM_NO_ERR) return 0; + if (doc == NULL) return 0; + dukky_push_node(ctx, doc); + dom_node_unref(doc); + return 1; +%} getter Node::parentNode() %{ @@ -182,7 +201,18 @@ getter Node::nodeValue() return 0; %} -/*** @todo setter nodeValue */ +setter Node::nodeValue() +%{ + dom_exception exc; + dom_string *content; + duk_size_t slen; + const char *s = duk_safe_to_lstring(ctx, 0, &slen); + exc = dom_string_create((const uint8_t *)s, slen, &content); + if (exc != DOM_NO_ERR) return 0; + exc = dom_node_set_node_value(priv->node, content); + dom_string_unref(content); + return 0; +%} getter Node::textContent() %{ @@ -202,13 +232,58 @@ getter Node::textContent() return 0; %} -/*** @todo setter textContent */ +setter Node::textContent() +%{ + dom_exception exc; + dom_string *content; + duk_size_t slen; + const char *s = duk_safe_to_lstring(ctx, 0, &slen); + exc = dom_string_create((const uint8_t *)s, slen, &content); + if (exc != DOM_NO_ERR) return 0; + exc = dom_node_set_text_content(priv->node, content); + dom_string_unref(content); + return 0; +%} + +method Node::normalize() +%{ + dom_exception exc; + exc = dom_node_normalize(priv->node); + return 0; +%} + +method Node::cloneNode() +%{ + dom_exception exc; + bool deep; + dom_node *clone; -/*** @todo method normalize */ + deep = duk_to_boolean(ctx, 0); -/*** @todo method cloneNode */ + exc = dom_node_clone_node(priv->node, deep, &clone); + if (exc != DOM_NO_ERR) return 0; + duk_set_top(ctx, 0); + dukky_push_node(ctx, clone); + dom_node_unref(clone); + return 1; +%} -/*** @todo method isEqualNode */ +method Node::isEqualNode() +%{ + dom_exception exc; + bool result; + + if (!dukky_instanceof_at(ctx, 0, PROTO_NAME(NODE))) return 0; + + duk_get_prop_string(ctx, 0, PRIVATE_MAGIC); + node_private_t *other = duk_get_pointer(ctx, -1); + duk_pop(ctx); + + exc = dom_node_is_equal(priv->node, other->node, &result); + if (exc != DOM_NO_ERR) return 0; + duk_push_boolean(ctx, result); + return 1; +%} /*** @todo method compareDocumentPosition */ -- cgit v1.2.3