summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-07-19 12:36:39 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2015-07-19 12:36:39 +0100
commit10c5dcd078700ff574512fc692adb6835653ba38 (patch)
tree94828bb4a1a14e3a9c78d2d9a45c25e902330161
parentd68e2c879c9254cae1ea8e248ebe70ddf5e797e6 (diff)
downloadnetsurf-10c5dcd078700ff574512fc692adb6835653ba38.tar.gz
netsurf-10c5dcd078700ff574512fc692adb6835653ba38.tar.bz2
REWORK: ALL THIS CRUD
-rw-r--r--javascript/Makefile4
-rw-r--r--javascript/dukky.c174
-rw-r--r--javascript/dukky.h19
-rw-r--r--javascript/duktape/character_data.c50
-rw-r--r--javascript/duktape/comment.c50
-rw-r--r--javascript/duktape/document.c60
-rw-r--r--javascript/duktape/node.c20
-rw-r--r--javascript/duktape/private.h15
-rw-r--r--javascript/duktape/prototypes.h3
-rw-r--r--javascript/duktape/text.c50
-rw-r--r--javascript/duktape/window.c21
-rw-r--r--utils/corestrings.c4
-rw-r--r--utils/corestrings.h1
13 files changed, 453 insertions, 18 deletions
diff --git a/javascript/Makefile b/javascript/Makefile
index 3baa845a5..80bba8489 100644
--- a/javascript/Makefile
+++ b/javascript/Makefile
@@ -61,7 +61,9 @@ $(eval $(foreach V,$(filter JSAPI_BINDING_%,$(.VARIABLES)),$(call convert_jsapi_
else
ifeq ($(NETSURF_USE_DUKTAPE),YES)
-S_DUKKY := event_target.c window.c node.c document.c element.c html_element.c html_unknown_element.c
+S_DUKKY := event_target.c window.c node.c document.c \
+ element.c html_element.c html_unknown_element.c \
+ character_data.c text.c comment.c
S_JAVASCRIPT += dukky.c duktape.c content.c fetcher.c $(addprefix duktape/,$(S_DUKKY))
diff --git a/javascript/dukky.c b/javascript/dukky.c
index 1f9123b2a..f5fae4e91 100644
--- a/javascript/dukky.c
+++ b/javascript/dukky.c
@@ -31,6 +31,8 @@
#include "duktape.h"
#include "dukky.h"
+#include <dom/dom.h>
+
static duk_ret_t dukky_populate_object(duk_context *ctx)
{
/* ... obj args protoname nargs */
@@ -77,6 +79,7 @@ duk_ret_t dukky_create_object(duk_context *ctx, const char *name, int args)
duk_push_string(ctx, name);
/* ... obj args name */
duk_push_int(ctx, args);
+ /* ... obj args name nargs */
if ((ret = duk_safe_call(ctx, dukky_populate_object, args + 3, 1))
!= DUK_EXEC_SUCCESS)
return ret;
@@ -100,6 +103,170 @@ static duk_ret_t dukky_create_prototype(duk_context *ctx,
return 0;
}
+duk_bool_t
+dukky_push_node_stacked(duk_context *ctx)
+{
+ int top_at_fail = duk_get_top(ctx) - 2;
+ /* ... nodeptr klass */
+ duk_get_global_string(ctx, NODE_MAGIC);
+ /* ... nodeptr klass nodes */
+ duk_dup(ctx, -3);
+ /* ... nodeptr klass nodes nodeptr */
+ duk_get_prop(ctx, -2);
+ /* ... nodeptr klass nodes node/undefined */
+ if (duk_is_undefined(ctx, -1)) {
+ /* ... nodeptr klass nodes undefined */
+ duk_pop(ctx);
+ /* ... nodeptr klass nodes */
+ duk_push_object(ctx);
+ /* ... nodeptr klass nodes obj */
+ duk_dup(ctx, -4);
+ /* ... nodeptr klass nodes obj nodeptr */
+ duk_dup(ctx, -4);
+ /* ... nodeptr klass nodes obj nodeptr klass */
+ duk_push_int(ctx, 1);
+ /* ... nodeptr klass nodes obj nodeptr klass 1 */
+ if (duk_safe_call(ctx, dukky_populate_object, 4, 1)
+ != DUK_EXEC_SUCCESS) {
+ duk_set_top(ctx, top_at_fail);
+ LOG("Boo and also hiss");
+ return false;
+ }
+ /* ... nodeptr klass nodes node */
+ duk_dup(ctx, -4);
+ /* ... nodeptr klass nodes node nodeptr */
+ duk_dup(ctx, -2);
+ /* ... nodeptr klass nodes node nodeptr node */
+ duk_put_prop(ctx, -4);
+ /* ... nodeptr klass nodes node */
+ }
+ /* ... nodeptr klass nodes node */
+ duk_insert(ctx, -4);
+ /* ... node nodeptr klass nodes */
+ duk_pop_3(ctx);
+ /* ... node */
+ return true;
+}
+
+static void
+dukky_push_node_klass(duk_context *ctx, struct dom_node *node)
+{
+ dom_node_type nodetype;
+ dom_exception err;
+
+ err = dom_node_get_node_type(node, &nodetype);
+ if (err != DOM_NO_ERR) {
+ /* Oh bum, just node then */
+ duk_push_string(ctx, PROTO_NAME(node));
+ return;
+ }
+
+ switch(nodetype) {
+ case DOM_ELEMENT_NODE: {
+ dom_string *namespace;
+ err = dom_node_get_namespace(node, &namespace);
+ if (err != DOM_NO_ERR) {
+ /* Feck it, element */
+ duk_push_string(ctx, PROTO_NAME(element));
+ break;
+ }
+ if (namespace == NULL) {
+ /* No namespace, -> element */
+ duk_push_string(ctx, PROTO_NAME(element));
+ break;
+ }
+
+ /* TODO: Work out how to decide between Element and HTML */
+ duk_push_string(ctx, PROTO_NAME(html_unknown_element));
+
+ dom_string_unref(namespace);
+ break;
+ }
+ case DOM_TEXT_NODE:
+ duk_push_string(ctx, PROTO_NAME(text));
+ break;
+ case DOM_COMMENT_NODE:
+ duk_push_string(ctx, PROTO_NAME(comment));
+ break;
+ case DOM_DOCUMENT_NODE:
+ duk_push_string(ctx, PROTO_NAME(document));
+ break;
+ case DOM_ATTRIBUTE_NODE:
+ case DOM_PROCESSING_INSTRUCTION_NODE:
+ case DOM_DOCUMENT_TYPE_NODE:
+ case DOM_DOCUMENT_FRAGMENT_NODE:
+ case DOM_NOTATION_NODE:
+ case DOM_ENTITY_REFERENCE_NODE:
+ case DOM_ENTITY_NODE:
+ case DOM_CDATA_SECTION_NODE:
+ default:
+ /* Oh bum, just node then */
+ duk_push_string(ctx, PROTO_NAME(node));
+ }
+}
+
+duk_bool_t
+dukky_push_node(duk_context *ctx, struct dom_node *node)
+{
+ LOG("Pushing node %p", node);
+ /* First check if we can find the node */
+ /* ... */
+ duk_get_global_string(ctx, NODE_MAGIC);
+ /* ... nodes */
+ duk_push_pointer(ctx, node);
+ /* ... nodes nodeptr */
+ duk_get_prop(ctx, -2);
+ /* ... nodes node/undefined */
+ if (!duk_is_undefined(ctx, -1)) {
+ /* ... nodes node */
+ duk_insert(ctx, -2);
+ /* ... node nodes */
+ duk_pop(ctx);
+ /* ... node */
+ LOG("Found it memoised");
+ return true;
+ }
+ /* ... nodes undefined */
+ duk_pop_2(ctx);
+ /* ... */
+ /* We couldn't, so now we determine the node type and then
+ * we ask for it to be created
+ */
+ duk_push_pointer(ctx, node);
+ /* ... nodeptr */
+ dukky_push_node_klass(ctx, node);
+ /* ... nodeptr klass */
+ return dukky_push_node_stacked(ctx);
+}
+
+duk_bool_t
+dukky_instanceof(duk_context *ctx, const char *klass)
+{
+ /* ... ??? */
+ if (!duk_check_type(ctx, -1, DUK_TYPE_OBJECT)) return false;
+ /* ... obj */
+ duk_get_global_string(ctx, PROTO_MAGIC);
+ /* ... obj protos */
+ duk_get_prop_string(ctx, -1, klass);
+ /* ... obj protos goalproto */
+ duk_get_prototype(ctx, -3);
+ /* ... obj protos goalproto proto? */
+ while (!duk_is_undefined(ctx, -1)) {
+ if (duk_strict_equals(ctx, -1, -2)) {
+ duk_pop_3(ctx);
+ return true;
+ }
+ duk_get_prototype(ctx, -1);
+ /* ... obj protos goalproto proto proto? */
+ duk_replace(ctx, -2);
+ /* ... obj protos goalproto proto? */
+ }
+ duk_pop_3(ctx);
+ /* ... obj */
+ return false;
+}
+
+
/**************************************** js.h ******************************/
struct jscontext {
duk_context *ctx;
@@ -140,6 +307,9 @@ jscontext *js_newcontext(int timeout, jscallback *cb, void *cbctx)
DUKKY_NEW_PROTOTYPE(event_target);
DUKKY_NEW_PROTOTYPE(window);
DUKKY_NEW_PROTOTYPE(node);
+ DUKKY_NEW_PROTOTYPE(character_data);
+ DUKKY_NEW_PROTOTYPE(text);
+ DUKKY_NEW_PROTOTYPE(comment);
DUKKY_NEW_PROTOTYPE(document);
DUKKY_NEW_PROTOTYPE(element);
DUKKY_NEW_PROTOTYPE(html_element);
@@ -173,6 +343,10 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
duk_put_prop_string(CTX, -2, PROTO_MAGIC);
duk_set_global_object(CTX);
+ /* Now we need to prepare our node mapping table */
+ duk_push_object(CTX);
+ duk_put_global_string(CTX, NODE_MAGIC);
+
return (jsobject *)ctx;
}
diff --git a/javascript/dukky.h b/javascript/dukky.h
index 5e81d68ae..bbcf9f38f 100644
--- a/javascript/dukky.h
+++ b/javascript/dukky.h
@@ -10,6 +10,7 @@
#define PROTO_MAGIC MAGIC(PROTOTYPES)
#define PRIVATE_MAGIC MAGIC(PRIVATE)
#define INIT_MAGIC MAGIC(INIT)
+#define NODE_MAGIC MAGIC(NODE_MAP)
#define _PROTO_NAME(K) _MAGIC("PROTOTYPE_" K)
#define PROTO_NAME(K) _PROTO_NAME(#K)
#define _PROP_NAME(K,V) _MAGIC(K "_PROPERTY_" V)
@@ -49,6 +50,10 @@ static inline void *dukky_get_private(duk_context *ctx, int idx)
t##_private_t *priv = dukky_get_private(ctx, idx); \
if (priv == NULL) return 0; /* No can do */
+#define DUKKY_SAFE_GET_ANOTHER(n,t,idx) \
+ t##_private_t *n = dukky_get_private(ctx, idx); \
+ if (priv == NULL) return 0; /* No can do */
+
#define DUKKY_GET_METHOD_PRIVATE(t) \
t##_private_t *priv = NULL; \
duk_push_this(ctx); \
@@ -78,6 +83,16 @@ static inline void *dukky_get_private(duk_context *ctx, int idx)
duk_push_c_function(ctx, DUKKY_FUNC_T(klass,prop##_setter), 1); \
duk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER | \
DUK_DEFPROP_HAVE_SETTER | \
+ DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE | \
+ DUK_DEFPROP_HAVE_CONFIGURABLE); \
+ duk_pop(ctx)
+
+#define DUKKY_POPULATE_READONLY_PROPERTY(klass,prop) \
+ duk_dup(ctx, 0); \
+ duk_push_string(ctx, #prop); \
+ duk_push_c_function(ctx, DUKKY_FUNC_T(klass,prop##_getter), 0); \
+ duk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER | \
+ DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE | \
DUK_DEFPROP_HAVE_CONFIGURABLE); \
duk_pop(ctx)
@@ -114,5 +129,7 @@ static inline void *dukky_get_private(duk_context *ctx, int idx)
#include "duktape/prototypes.h"
duk_ret_t dukky_create_object(duk_context *ctx, const char *name, int args);
-
+duk_bool_t dukky_push_node_stacked(duk_context *ctx);
+duk_bool_t dukky_push_node(duk_context *ctx, struct dom_node *node);
+duk_bool_t dukky_instanceof(duk_context *ctx, const char *klass);
#endif
diff --git a/javascript/duktape/character_data.c b/javascript/duktape/character_data.c
new file mode 100644
index 000000000..a71de478f
--- /dev/null
+++ b/javascript/duktape/character_data.c
@@ -0,0 +1,50 @@
+/* DO NOT USE, DODGY BIT FOR VINCE */
+
+#include <dom/dom.h>
+
+#include "utils/log.h"
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(character_data, struct dom_node_character_data *character_data)
+{
+ DUKKY_FUNC_T(node, __init)(ctx, &priv->parent, (struct dom_node *)character_data);
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+}
+
+DUKKY_FUNC_FINI(character_data)
+{
+ /* do any character_data finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ DUKKY_FUNC_T(node, __fini)(ctx, &priv->parent);
+}
+
+static DUKKY_FUNC(character_data, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(character_data);
+ DUKKY_FUNC_T(character_data, __init)(ctx, priv,
+ duk_get_pointer(ctx, 1));
+ duk_set_top(ctx, 1);
+ return 1;
+}
+
+static DUKKY_FUNC(character_data, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(character_data, 0);
+ DUKKY_FUNC_T(character_data, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+DUKKY_FUNC(character_data, __proto)
+{
+ /* Populate character_data's prototypical functionality */
+
+ /* Set this prototype's prototype (left-parent)*/
+ DUKKY_GET_PROTOTYPE(node);
+ duk_set_prototype(ctx, 0);
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, character_data);
+ DUKKY_SET_CONSTRUCTOR(0, character_data, 1);
+ return 1; /* The proto object */
+}
diff --git a/javascript/duktape/comment.c b/javascript/duktape/comment.c
new file mode 100644
index 000000000..877793af2
--- /dev/null
+++ b/javascript/duktape/comment.c
@@ -0,0 +1,50 @@
+/* DO NOT USE, DODGY BIT FOR VINCE */
+
+#include <dom/dom.h>
+
+#include "utils/log.h"
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(comment, struct dom_node_comment *comment)
+{
+ DUKKY_FUNC_T(character_data, __init)(ctx, &priv->parent, (struct dom_node_character_data *)comment);
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+}
+
+DUKKY_FUNC_FINI(comment)
+{
+ /* do any comment finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ DUKKY_FUNC_T(character_data, __fini)(ctx, &priv->parent);
+}
+
+static DUKKY_FUNC(comment, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(comment);
+ DUKKY_FUNC_T(comment, __init)(ctx, priv,
+ duk_get_pointer(ctx, 1));
+ duk_set_top(ctx, 1);
+ return 1;
+}
+
+static DUKKY_FUNC(comment, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(comment, 0);
+ DUKKY_FUNC_T(comment, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+DUKKY_FUNC(comment, __proto)
+{
+ /* Populate comment's prototypical functionality */
+
+ /* Set this prototype's prototype (left-parent)*/
+ DUKKY_GET_PROTOTYPE(character_data);
+ duk_set_prototype(ctx, 0);
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, comment);
+ DUKKY_SET_CONSTRUCTOR(0, comment, 1);
+ return 1; /* The proto object */
+}
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);
diff --git a/javascript/duktape/node.c b/javascript/duktape/node.c
index 5a0bc0e1a..d632a2414 100644
--- a/javascript/duktape/node.c
+++ b/javascript/duktape/node.c
@@ -38,10 +38,28 @@ static DUKKY_FUNC(node, __destructor)
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;
+}
+
DUKKY_FUNC(node, __proto)
{
/* Populate node's prototypical functionality */
-
+ DUKKY_ADD_METHOD(node, appendChild, 1);
/* Set this prototype's prototype (left-parent)*/
DUKKY_GET_PROTOTYPE(event_target);
duk_set_prototype(ctx, 0);
diff --git a/javascript/duktape/private.h b/javascript/duktape/private.h
index 5d5a070c3..6dd3086fd 100644
--- a/javascript/duktape/private.h
+++ b/javascript/duktape/private.h
@@ -7,6 +7,9 @@ struct dom_node;
struct dom_element;
struct dom_document;
struct dom_html_element;
+struct dom_node_character_data;
+struct dom_node_text;
+struct dom_node_comment;
typedef struct {
} event_target_private_t;
@@ -24,6 +27,18 @@ typedef struct {
typedef struct {
node_private_t parent;
+} character_data_private_t;
+
+typedef struct {
+ character_data_private_t parent;
+} text_private_t;
+
+typedef struct {
+ character_data_private_t parent;
+} comment_private_t;
+
+typedef struct {
+ node_private_t parent;
} element_private_t;
typedef struct {
diff --git a/javascript/duktape/prototypes.h b/javascript/duktape/prototypes.h
index 380b74111..aa1813e2f 100644
--- a/javascript/duktape/prototypes.h
+++ b/javascript/duktape/prototypes.h
@@ -4,6 +4,9 @@
DUKKY_DECLARE_INTERFACE(event_target);
DUKKY_DECLARE_INTERFACE(window, struct browser_window *, struct html_content *);
DUKKY_DECLARE_INTERFACE(node, struct dom_node *);
+DUKKY_DECLARE_INTERFACE(character_data, struct dom_node_character_data *);
+DUKKY_DECLARE_INTERFACE(text, struct dom_node_text *);
+DUKKY_DECLARE_INTERFACE(comment, struct dom_node_comment *);
DUKKY_DECLARE_INTERFACE(document, struct dom_document *);
DUKKY_DECLARE_INTERFACE(element, struct dom_element *);
DUKKY_DECLARE_INTERFACE(html_element, struct dom_html_element *);
diff --git a/javascript/duktape/text.c b/javascript/duktape/text.c
new file mode 100644
index 000000000..7669bae11
--- /dev/null
+++ b/javascript/duktape/text.c
@@ -0,0 +1,50 @@
+/* DO NOT USE, DODGY BIT FOR VINCE */
+
+#include <dom/dom.h>
+
+#include "utils/log.h"
+
+#include "javascript/dukky.h"
+
+DUKKY_FUNC_INIT(text, struct dom_node_text *text)
+{
+ DUKKY_FUNC_T(character_data, __init)(ctx, &priv->parent, (struct dom_node_character_data *)text);
+ LOG("Initialise %p (priv=%p)", duk_get_heapptr(ctx, 0), priv);
+}
+
+DUKKY_FUNC_FINI(text)
+{
+ /* do any text finalisation here, priv ptr exists */
+ LOG("Finalise %p", duk_get_heapptr(ctx, 0));
+ DUKKY_FUNC_T(character_data, __fini)(ctx, &priv->parent);
+}
+
+static DUKKY_FUNC(text, __constructor)
+{
+ DUKKY_CREATE_PRIVATE(text);
+ DUKKY_FUNC_T(text, __init)(ctx, priv,
+ duk_get_pointer(ctx, 1));
+ duk_set_top(ctx, 1);
+ return 1;
+}
+
+static DUKKY_FUNC(text, __destructor)
+{
+ DUKKY_SAFE_GET_PRIVATE(text, 0);
+ DUKKY_FUNC_T(text, __fini)(ctx, priv);
+ free(priv);
+ return 0;
+}
+
+DUKKY_FUNC(text, __proto)
+{
+ /* Populate text's prototypical functionality */
+
+ /* Set this prototype's prototype (left-parent)*/
+ DUKKY_GET_PROTOTYPE(character_data);
+ duk_set_prototype(ctx, 0);
+ /* And the initialiser/finalizer */
+ DUKKY_SET_DESTRUCTOR(0, text);
+ DUKKY_SET_CONSTRUCTOR(0, text, 1);
+ return 1; /* The proto object */
+}
diff --git a/javascript/duktape/window.c b/javascript/duktape/window.c
index efba5851c..e52fcb00d 100644
--- a/javascript/duktape/window.c
+++ b/javascript/duktape/window.c
@@ -57,22 +57,8 @@ static DUKKY_GETTER(window,document)
{
DUKKY_GET_METHOD_PRIVATE(window);
LOG("priv=%p", priv);
- duk_push_this(ctx);
- duk_get_prop_string(ctx, -1, PROP_NAME(window, document));
- if (!duk_is_undefined(ctx, -1)) {
- return 1;
- } else {
- duk_pop(ctx);
- }
dom_document *doc = priv->htmlc->document;
- duk_push_pointer(ctx, doc);
- if (dukky_create_object(ctx, PROTO_NAME(document), 1) != DUK_EXEC_SUCCESS) {
- LOG("ERROR");
- }
- duk_push_this(ctx);
- duk_dup(ctx, -2);
- duk_put_prop_string(ctx, -2, PROP_NAME(window, document));
- duk_pop(ctx);
+ dukky_push_node(ctx, (struct dom_node *)doc);
return 1;
}
@@ -82,8 +68,13 @@ static DUKKY_SETTER(window,document)
return 0;
}
+#define STEAL_THING(X) \
+ duk_get_global_string(ctx, #X); \
+ duk_put_prop_string(ctx, 0, #X)
+
DUKKY_FUNC(window, __proto)
{
+ STEAL_THING(undefined);
/* Populate window's prototypical functionality */
DUKKY_POPULATE_FULL_PROPERTY(window, document);
/* Set this prototype's prototype (left-parent)*/
diff --git a/utils/corestrings.c b/utils/corestrings.c
index f1ccbab82..20036a515 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -260,6 +260,7 @@ dom_string *corestring_dom_BUTTON;
dom_string *corestring_dom_INPUT;
dom_string *corestring_dom_SELECT;
dom_string *corestring_dom_TEXTAREA;
+dom_string *corestring_dom_BODY;
dom_string *corestring_dom_button;
dom_string *corestring_dom_image;
dom_string *corestring_dom_radio;
@@ -531,6 +532,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(INPUT);
CSS_DOM_STRING_UNREF(SELECT);
CSS_DOM_STRING_UNREF(TEXTAREA);
+ CSS_DOM_STRING_UNREF(BODY);
/* DOM input types, not really CSS */
CSS_DOM_STRING_UNREF(button);
CSS_DOM_STRING_UNREF(image);
@@ -543,6 +545,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(__ns_key_libcss_node_data);
CSS_DOM_STRING_UNREF(__ns_key_file_name_node_data);
CSS_DOM_STRING_UNREF(__ns_key_image_coords_node_data);
+ CSS_DOM_STRING_UNREF(__ns_key_html_content_data);
#undef CSS_DOM_STRING_UNREF
/* nsurl URLs */
@@ -847,6 +850,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(INPUT);
CSS_DOM_STRING_INTERN(SELECT);
CSS_DOM_STRING_INTERN(TEXTAREA);
+ CSS_DOM_STRING_INTERN(BODY);
/* DOM input types, not really CSS */
CSS_DOM_STRING_INTERN(button);
CSS_DOM_STRING_INTERN(image);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index e585a4800..2c3c4482c 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -272,6 +272,7 @@ extern struct dom_string *corestring_dom_BUTTON;
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 input node types */
extern struct dom_string *corestring_dom_button;
/* extern struct dom_string *corestring_dom_submit; */