summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-07-19 12:59:49 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2015-07-19 12:59:49 +0100
commite4f46aceb3a3406d4f52d73f72a69e28578b7af4 (patch)
tree1395cba1a664e5773d854943f6c5aa990e92e530
parent10c5dcd078700ff574512fc692adb6835653ba38 (diff)
downloadnetsurf-e4f46aceb3a3406d4f52d73f72a69e28578b7af4.tar.gz
netsurf-e4f46aceb3a3406d4f52d73f72a69e28578b7af4.tar.bz2
Support createElement
-rw-r--r--javascript/duktape/document.c31
-rw-r--r--utils/corestrings.c13
-rw-r--r--utils/corestrings.h2
3 files changed, 45 insertions, 1 deletions
diff --git a/javascript/duktape/document.c b/javascript/duktape/document.c
index 701d2d40d..b4f8cefbe 100644
--- a/javascript/duktape/document.c
+++ b/javascript/duktape/document.c
@@ -84,6 +84,36 @@ static DUKKY_FUNC(document, createTextNode)
return 1;
}
+static DUKKY_FUNC(document, createElement)
+{
+ 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_element_ns(priv->parent.node,
+ corestring_dom_html_namespace,
+ 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);
@@ -118,6 +148,7 @@ DUKKY_FUNC(document, __proto)
/* Populate document's prototypical functionality */
DUKKY_ADD_METHOD(document, write, 1);
DUKKY_ADD_METHOD(document, createTextNode, 1);
+ DUKKY_ADD_METHOD(document, createElement, 1);
DUKKY_POPULATE_READONLY_PROPERTY(document, body);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(node);
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 20036a515..1d20362a3 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -261,6 +261,7 @@ dom_string *corestring_dom_INPUT;
dom_string *corestring_dom_SELECT;
dom_string *corestring_dom_TEXTAREA;
dom_string *corestring_dom_BODY;
+dom_string *corestring_dom_html_namespace;
dom_string *corestring_dom_button;
dom_string *corestring_dom_image;
dom_string *corestring_dom_radio;
@@ -533,6 +534,8 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(SELECT);
CSS_DOM_STRING_UNREF(TEXTAREA);
CSS_DOM_STRING_UNREF(BODY);
+ /* DOM namespaces, not really CSS */
+ CSS_DOM_STRING_UNREF(html_namespace);
/* DOM input types, not really CSS */
CSS_DOM_STRING_UNREF(button);
CSS_DOM_STRING_UNREF(image);
@@ -882,11 +885,19 @@ nserror corestrings_init(void)
goto error;
}
+ exc = dom_string_create_interned((const uint8_t *) "http://www.w3.org/1999/xhtml",
+ SLEN("http://www.w3.org/1999/xhtml"),
+ &corestring_dom_html_namespace);
+ if ((exc != DOM_NO_ERR) || (corestring_dom_html_namespace == NULL)) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
error = nsurl_create("about:blank", &corestring_nsurl_about_blank);
if (error != NSERROR_OK) {
goto error;
}
-
+
return NSERROR_OK;
error:
diff --git a/utils/corestrings.h b/utils/corestrings.h
index 2c3c4482c..415dece26 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -273,6 +273,8 @@ extern struct dom_string *corestring_dom_INPUT;
extern struct dom_string *corestring_dom_SELECT;
extern struct dom_string *corestring_dom_TEXTAREA;
extern struct dom_string *corestring_dom_BODY;
+/* DOM namespaces */
+extern struct dom_string *corestring_dom_html_namespace;
/* DOM input node types */
extern struct dom_string *corestring_dom_button;
/* extern struct dom_string *corestring_dom_submit; */