summaryrefslogtreecommitdiff
path: root/javascript/duktape/document.c
diff options
context:
space:
mode:
Diffstat (limited to 'javascript/duktape/document.c')
-rw-r--r--javascript/duktape/document.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index 07b8becd3..701d2d40d 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -55,10 +55,70 @@ static DUKKY_FUNC(document, write)
return 0;
}
+static DUKKY_FUNC(document, createTextNode)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ dom_node *newnode;
+ dom_exception err;
+ duk_size_t text_len;
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ dom_string *text_str;
+
+ err = dom_string_create((const uint8_t*)text, text_len, &text_str);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_document_create_text_node(priv->parent.node,
+ text_str,
+ &newnode);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(text_str);
+ return 0; /* coerced to undefined */
+ }
+
+ dom_string_unref(text_str);
+
+ dukky_push_node(ctx, newnode);
+
+ dom_node_unref(newnode);
+
+ return 1;
+}
+
+static DUKKY_GETTER(document, body)
+{
+ DUKKY_GET_METHOD_PRIVATE(document);
+ struct dom_nodelist *nodes;
+ struct dom_node *retnode;
+ dom_exception err;
+ err = dom_document_get_elements_by_tag_name(priv->parent.node,
+ corestring_dom_BODY,
+ &nodes);
+ if (err != DOM_NO_ERR) return 0; /* coerced to undefined */
+
+ err = dom_nodelist_item(nodes, 0, &retnode);
+
+ if (err != DOM_NO_ERR) {
+ dom_nodelist_unref(nodes);
+ return 0; /* coerced to undefined */
+ }
+
+ dom_nodelist_unref(nodes);
+
+ if (retnode == NULL) return 0; /* coerced to undefined */
+
+ dukky_push_node(ctx, retnode);
+
+ dom_node_unref(retnode);
+
+ return 1;
+}
+
DUKKY_FUNC(document, __proto)
{
/* Populate document's prototypical functionality */
DUKKY_ADD_METHOD(document, write, 1);
+ DUKKY_ADD_METHOD(document, createTextNode, 1);
+ DUKKY_POPULATE_READONLY_PROPERTY(document, body);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
duk_set_prototype(ctx, 0);