Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/a3ef5c2c3c448f6ded44b4135a1a745721653230
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/a3ef5c2c3c448f6ded44b4135a1a745721653230
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/a3ef5c2c3c448f6ded44b4135a1a745721653230

The branch, master has been updated
       via  a3ef5c2c3c448f6ded44b4135a1a745721653230 (commit)
      from  c3f9e3d3cea7bddb708fb0c75d9b4ed31e6341d7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commitdiff/a3ef5c2c3c448f6ded44b4135a1a745721653230
commit a3ef5c2c3c448f6ded44b4135a1a745721653230
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    fixup jsapi dom interface to include correct html/dom acessor hierachy

diff --git a/Makefile.sources b/Makefile.sources
index f7f05ca..0229e91 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -31,7 +31,7 @@ S_DESKTOP := cookies.c history_global_core.c hotlist.c 
knockout.c     \
 
 # Javascript sources
 ifeq ($(NETSURF_USE_JS),YES)
-S_JSAPI = window.c document.c navigator.c console.c element.c
+S_JSAPI = window.c navigator.c console.c htmldocument.c htmlelement.c
 S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
 else
 S_JAVASCRIPT += none.c
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index a40ce20..e5dfcd5 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -16,18 +16,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
 
 /* IDL 
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-document
 
-CAUTION - write, writeln are not part of the DOM they come from:
-http://www.w3.org/TR/html5/apis-in-html-documents.html#document.write
-
 interface Document : Node {
   readonly attribute DOMImplementation implementation;
   readonly attribute DOMString URL;
@@ -69,29 +60,7 @@ interface Document : Node {
 
  */
 
-static void jsfinalize_document(JSContext *cx, JSObject *obj);
-
-struct jsclass_document_priv {
-       struct html_content *htmlc;
-       dom_document *node;
-};
-
-static JSClass jsclass_document =
-{
-        "document", 
-       JSCLASS_HAS_PRIVATE, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_StrictPropertyStub,
-        JS_EnumerateStub, 
-       JS_ResolveStub, 
-       JS_ConvertStub, 
-       jsfinalize_document, 
-       JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#define JSCLASS_NAME document
+#include "jsclass.h"
 
 #include "node.c"
 
@@ -104,7 +73,7 @@ static JSBool JSAPI_NATIVE(getElementById, JSContext *cx, 
uintN argc, jsval *vp)
        dom_element *idelement;
        struct jsclass_document_priv *document;
 
-       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&jsclass_document, NULL);
+       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&JSCLASS_OBJECT, NULL);
        if (document == NULL) {
                return JS_FALSE;
        }
@@ -132,88 +101,7 @@ static JSBool JSAPI_NATIVE(getElementById, JSContext *cx, 
uintN argc, jsval *vp)
        return JS_TRUE;
 }
 
-static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
-{
-       JSString* u16_txt;
-       char *txt;
-       unsigned long length;
-       struct jsclass_document_priv *document;
-
-       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&jsclass_document, NULL);
-       if (document == NULL) {
-               return JS_FALSE;
-       }
-
-       if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) {
-               return JS_FALSE;
-       }
-
-       JSString_to_char(u16_txt, txt, length);
-
-       LOG(("content %p parser %p writing %s",
-            document->htmlc, document->htmlc->parser, txt));
-       if (document->htmlc->parser != NULL) {
-               dom_hubbub_parser_insert_chunk(document->htmlc->parser, 
(uint8_t *)txt, length);
-       }
-       JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
+#define JSAPI_FS_DOCUMENT \
+       JSAPI_FS_NODE, \
+       JSAPI_FS(getElementById, 1, 0) \
 
-       return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_document[] = {
-       JSAPI_FS_NODE,
-       JSAPI_FS(write, 1, 0),
-       JSAPI_FS(getElementById, 1, 0),
-       JSAPI_FS_END
-};
-
-
-
-static void jsfinalize_document(JSContext *cx, JSObject *obj)
-{
-       struct jsclass_document_priv *document;
-
-       document = JS_GetInstancePrivate(cx, obj, &jsclass_document, NULL);
-       if (document != NULL) {
-               free(document);
-       }
-}
-
-JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, struct 
html_content *htmlc)
-{
-       /* create document object and return it */
-       JSObject *jsdocument;
-       struct jsclass_document_priv *document;
-
-       document = malloc(sizeof(document));
-       if (document == NULL) {
-               return NULL;
-       }
-       document->htmlc = htmlc;
-       document->node = htmlc->document;
-
-       jsdocument = JS_InitClass(cx, 
-                    parent, 
-                    NULL, 
-                    &jsclass_document, 
-                    NULL, 
-                    0, 
-                    NULL, 
-                    jsfunctions_document, 
-                    NULL, 
-                    NULL);
-       if (jsdocument == NULL) {
-               free(document);
-               return NULL;
-       }
-
-       LOG(("setting document private to %p", document));
-       /* private pointer to browsing context */
-       if (JS_SetPrivate(cx, jsdocument, document) != JS_TRUE) {
-               LOG(("failed to set document private"));
-               free(document);
-               return NULL;
-       }
-       
-       return jsdocument;
-}
diff --git a/javascript/jsapi/element.c b/javascript/jsapi/element.c
index 8ea7017..cefb959 100644
--- a/javascript/jsapi/element.c
+++ b/javascript/jsapi/element.c
@@ -16,18 +16,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-#include "render/html_internal.h"
-
-#include "javascript/jsapi.h"
 
 /* IDL 
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-element
 
-CAUTION - innerHTML etc. are not part of the DOM they come from:
-http://html5.org/specs/dom-parsing.html#extensions-to-the-element-interface
 
 interface Element : Node {
   readonly attribute DOMString? namespaceURI;
@@ -70,88 +61,24 @@ interface Element : Node {
 };
 */
 
-static void jsfinalize_element(JSContext *cx, JSObject *obj);
-
-struct jsclass_document_priv {
-       struct html_content *htmlc;
-       dom_element *node;
-};
-
-static JSClass jsclass_element =
-{
-        "Element", 
-       JSCLASS_HAS_PRIVATE, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_StrictPropertyStub,
-        JS_EnumerateStub, 
-       JS_ResolveStub, 
-       JS_ConvertStub, 
-       jsfinalize_element, 
-       JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#define JSCLASS_NAME element
+#include "jsclass.h"
 
 #include "node.c"
 
-static void jsfinalize_element(JSContext *cx, JSObject *obj)
+static JSBool JSAPI_NATIVE(getAttribute, JSContext *cx, uintN argc, jsval *vp)
 {
-       struct jsclass_document_priv *element;
-       element = JS_GetInstancePrivate(cx, obj, &jsclass_element, NULL);
-       if (element != NULL) {
-               free(element);
-       }
-}
-
+       struct JSCLASS_TYPE *priv;
 
+       priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&JSCLASS_OBJECT, NULL);
+       if (priv == NULL)
+               return JS_FALSE;
 
-static JSFunctionSpec jsfunctions_element[] = {
-       JSAPI_FS_NODE,
-       JSAPI_FS_END
-};
 
+       JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
 
-JSObject *
-jsapi_new_element(JSContext *cx, 
-                 JSObject *parent, 
-                 struct html_content *htmlc, 
-                 dom_element *domelement)
-{
-       /* create element object and return it */
-       JSObject *jselement;
-       struct jsclass_document_priv *element;
-
-       element = malloc(sizeof(element));
-       if (element == NULL) {
-               return NULL;
-       }
-       element->htmlc = htmlc;
-       element->node = domelement;
-
-       jselement = JS_InitClass(cx, 
-                          parent, 
-                          NULL, 
-                          &jsclass_element, 
-                          NULL, 
-                          0, 
-                          NULL, 
-                          jsfunctions_element, 
-                          NULL, 
-                          NULL);
-       if (jselement == NULL) {
-               free(element);
-               return NULL;
-       }
-
-       LOG(("setting private to %p", element));
-       /* private pointer to browsing context */
-       if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
-               LOG(("failed to set private"));
-               free(element);
-               return NULL;
-       }
-
-       return jselement;
+       return JS_TRUE;
 }
+
+#define JSAPI_FS_ELEMENT \
+       JSAPI_FS_NODE, \
+       JSAPI_FS(getAttribute, 0, 0)
diff --git a/javascript/jsapi/eventtarget.c b/javascript/jsapi/eventtarget.c
index fc6f6f6..e2ab6a9 100644
--- a/javascript/jsapi/eventtarget.c
+++ b/javascript/jsapi/eventtarget.c
@@ -26,19 +26,7 @@ interface EventTarget {
 };
 */
 
-
-#ifndef JSCLASS_NAME
-#error "The class name must be defined"
-#endif
-
-#ifndef JSCLASS_TYPE
-#define CLASS jsclass
-#define PRIVATE priv
-#define EXPAND(a,b) PASTE(a,b)
-#define PASTE(x,y) x##_##y
-#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
-#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
-#endif
+#include "jsclass.h"
 
 static JSBool JSAPI_NATIVE(addEventListener, JSContext *cx, uintN argc, jsval 
*vp)
 {
diff --git a/javascript/jsapi/htmldocument.c b/javascript/jsapi/htmldocument.c
new file mode 100644
index 0000000..aa9efbc
--- /dev/null
+++ b/javascript/jsapi/htmldocument.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2012 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "javascript/jsapi.h"
+
+/* IDL http://www.whatwg.org/specs/web-apps/current-work/#the-document-object
+
+NOTE - this interface is not from the DOM specifications but from the
+html5 spec. I *think* thats right.
+
+[OverrideBuiltins]
+partial interface Document {
+  // resource metadata management
+  [PutForwards=href] readonly attribute Location? location;
+           attribute DOMString domain;
+  readonly attribute DOMString referrer;
+           attribute DOMString cookie;
+  readonly attribute DOMString lastModified;
+  readonly attribute DOMString readyState;
+
+  // DOM tree accessors
+  getter object (DOMString name);
+           attribute DOMString title;
+           attribute DOMString dir;
+           attribute HTMLElement? body;
+  readonly attribute HTMLHeadElement? head;
+  readonly attribute HTMLCollection images;
+  readonly attribute HTMLCollection embeds;
+  readonly attribute HTMLCollection plugins;
+  readonly attribute HTMLCollection links;
+  readonly attribute HTMLCollection forms;
+  readonly attribute HTMLCollection scripts;
+  NodeList getElementsByName(DOMString elementName);
+  NodeList getItems(optional DOMString typeNames); // microdata 
+  readonly attribute DOMElementMap cssElementMap;
+
+  // dynamic markup insertion
+  Document open(optional DOMString type, optional DOMString replace);
+  WindowProxy open(DOMString url, DOMString name, DOMString features, optional 
boolean replace);
+  void close();
+  void write(DOMString... text);
+  void writeln(DOMString... text);
+
+  // user interaction
+  readonly attribute WindowProxy? defaultView;
+  readonly attribute Element? activeElement;
+  boolean hasFocus();
+           attribute DOMString designMode;
+  boolean execCommand(DOMString commandId);
+  boolean execCommand(DOMString commandId, boolean showUI);
+  boolean execCommand(DOMString commandId, boolean showUI, DOMString value);
+  boolean queryCommandEnabled(DOMString commandId);
+  boolean queryCommandIndeterm(DOMString commandId);
+  boolean queryCommandState(DOMString commandId);
+  boolean queryCommandSupported(DOMString commandId);
+  DOMString queryCommandValue(DOMString commandId);
+  readonly attribute HTMLCollection commands;
+
+  // event handler IDL attributes
+           attribute EventHandler onabort;
+           attribute EventHandler onblur;
+           attribute EventHandler oncancel;
+           attribute EventHandler oncanplay;
+           attribute EventHandler oncanplaythrough;
+           attribute EventHandler onchange;
+           attribute EventHandler onclick;
+           attribute EventHandler onclose;
+           attribute EventHandler oncontextmenu;
+           attribute EventHandler oncuechange;
+           attribute EventHandler ondblclick;
+           attribute EventHandler ondrag;
+           attribute EventHandler ondragend;
+           attribute EventHandler ondragenter;
+           attribute EventHandler ondragleave;
+           attribute EventHandler ondragover;
+           attribute EventHandler ondragstart;
+           attribute EventHandler ondrop;
+           attribute EventHandler ondurationchange;
+           attribute EventHandler onemptied;
+           attribute EventHandler onended;
+           attribute OnErrorEventHandler onerror;
+           attribute EventHandler onfocus;
+           attribute EventHandler oninput;
+           attribute EventHandler oninvalid;
+           attribute EventHandler onkeydown;
+           attribute EventHandler onkeypress;
+           attribute EventHandler onkeyup;
+           attribute EventHandler onload;
+           attribute EventHandler onloadeddata;
+           attribute EventHandler onloadedmetadata;
+           attribute EventHandler onloadstart;
+           attribute EventHandler onmousedown;
+           attribute EventHandler onmousemove;
+           attribute EventHandler onmouseout;
+           attribute EventHandler onmouseover;
+           attribute EventHandler onmouseup;
+           attribute EventHandler onmousewheel;
+           attribute EventHandler onpause;
+           attribute EventHandler onplay;
+           attribute EventHandler onplaying;
+           attribute EventHandler onprogress;
+           attribute EventHandler onratechange;
+           attribute EventHandler onreset;
+           attribute EventHandler onscroll;
+           attribute EventHandler onseeked;
+           attribute EventHandler onseeking;
+           attribute EventHandler onselect;
+           attribute EventHandler onshow;
+           attribute EventHandler onstalled;
+           attribute EventHandler onsubmit;
+           attribute EventHandler onsuspend;
+           attribute EventHandler ontimeupdate;
+           attribute EventHandler onvolumechange;
+           attribute EventHandler onwaiting;
+
+  // special event handler IDL attributes that only apply to Document objects
+  [LenientThis] attribute EventHandler onreadystatechange;
+};
+
+ */
+
+static void jsfinalize_document(JSContext *cx, JSObject *obj);
+static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN 
flags, JSObject **objp);
+
+struct jsclass_document_priv {
+       struct html_content *htmlc;
+       dom_document *node;
+};
+
+
+#define JSCLASS_NAME document
+
+#include "jsclass.h"
+
+static JSClass JSCLASS_OBJECT =
+{
+        "document", 
+       JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE, 
+       JS_PropertyStub, 
+       JS_PropertyStub, 
+       JS_PropertyStub, 
+       JS_StrictPropertyStub,
+        JS_EnumerateStub, 
+       (JSResolveOp)jsresove_node, 
+       JS_ConvertStub, 
+       jsfinalize_document, 
+       JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+#include "document.c"
+
+static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN 
flags, JSObject **objp)
+{
+       *objp = NULL;
+       return JS_TRUE;
+}
+
+static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
+{
+       JSString* u16_txt;
+       char *txt;
+       unsigned long length;
+       struct jsclass_document_priv *document;
+
+       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&JSCLASS_OBJECT, NULL);
+       if (document == NULL) {
+               return JS_FALSE;
+       }
+
+       if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) {
+               return JS_FALSE;
+       }
+
+       JSString_to_char(u16_txt, txt, length);
+
+       LOG(("content %p parser %p writing %s",
+            document->htmlc, document->htmlc->parser, txt));
+       if (document->htmlc->parser != NULL) {
+               dom_hubbub_parser_insert_chunk(document->htmlc->parser, 
(uint8_t *)txt, length);
+       }
+       JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
+
+       return JS_TRUE;
+}
+
+static JSFunctionSpec jsfunctions_document[] = {
+       JSAPI_FS_DOCUMENT,
+       JSAPI_FS(write, 1, 0),
+       JSAPI_FS_END
+};
+
+static void jsfinalize_document(JSContext *cx, JSObject *obj)
+{
+       struct jsclass_document_priv *document;
+
+       document = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
+       if (document != NULL) {
+               free(document);
+       }
+}
+
+JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, struct 
html_content *htmlc)
+{
+       /* create document object and return it */
+       JSObject *jsdocument;
+       struct jsclass_document_priv *document;
+
+       document = malloc(sizeof(document));
+       if (document == NULL) {
+               return NULL;
+       }
+       document->htmlc = htmlc;
+       document->node = htmlc->document;
+
+       jsdocument = JS_InitClass(cx, 
+                    parent, 
+                    NULL, 
+                    &JSCLASS_OBJECT, 
+                    NULL, 
+                    0, 
+                    NULL, 
+                    jsfunctions_document, 
+                    NULL, 
+                    NULL);
+       if (jsdocument == NULL) {
+               free(document);
+               return NULL;
+       }
+
+       LOG(("setting document private to %p", document));
+       /* private pointer to browsing context */
+       if (JS_SetPrivate(cx, jsdocument, document) != JS_TRUE) {
+               LOG(("failed to set document private"));
+               free(document);
+               return NULL;
+       }
+       
+       return jsdocument;
+}
diff --git a/javascript/jsapi/htmlelement.c b/javascript/jsapi/htmlelement.c
new file mode 100644
index 0000000..90cb06a
--- /dev/null
+++ b/javascript/jsapi/htmlelement.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2012 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+#include "render/html_internal.h"
+
+#include "javascript/jsapi.h"
+
+/* IDL http://www.whatwg.org/specs/web-apps/current-work/#elements-in-the-dom
+
+CAUTION - innerHTML and outerHTML etc. are part of the DOM parsing
+         specification but more can be found in:
+http://html5.org/specs/dom-parsing.html#extensions-to-the-element-interface
+
+interface HTMLElement : Element {
+  // metadata attributes
+          attribute DOMString title;
+          attribute DOMString lang;
+          attribute boolean translate;
+          attribute DOMString dir;
+  readonly attribute DOMStringMap dataset;
+
+  // microdata
+          attribute boolean itemScope;
+  [PutForwards=value] readonly attribute DOMSettableTokenList itemType;
+          attribute DOMString itemId;
+  [PutForwards=value] readonly attribute DOMSettableTokenList itemRef;
+  [PutForwards=value] readonly attribute DOMSettableTokenList itemProp;
+  readonly attribute HTMLPropertiesCollection properties;
+          attribute any itemValue;
+
+  // user interaction
+          attribute boolean hidden;
+  void click();
+          attribute long tabIndex;
+  void focus();
+  void blur();
+          attribute DOMString accessKey;
+  readonly attribute DOMString accessKeyLabel;
+          attribute boolean draggable;
+  [PutForwards=value] readonly attribute DOMSettableTokenList dropzone;
+          attribute DOMString contentEditable;
+  readonly attribute boolean isContentEditable;
+          attribute HTMLMenuElement? contextMenu;
+          attribute boolean spellcheck;
+
+  // command API
+  readonly attribute DOMString? commandType;
+  readonly attribute DOMString? commandLabel;
+  readonly attribute DOMString? commandIcon;
+  readonly attribute boolean? commandHidden;
+  readonly attribute boolean? commandDisabled;
+  readonly attribute boolean? commandChecked;
+
+  // styling
+  readonly attribute CSSStyleDeclaration style;
+
+  // event handler IDL attributes
+          attribute EventHandler onabort;
+          attribute EventHandler onblur;
+          attribute EventHandler oncancel;
+          attribute EventHandler oncanplay;
+          attribute EventHandler oncanplaythrough;
+          attribute EventHandler onchange;
+          attribute EventHandler onclick;
+          attribute EventHandler onclose;
+          attribute EventHandler oncontextmenu;
+          attribute EventHandler oncuechange;
+          attribute EventHandler ondblclick;
+          attribute EventHandler ondrag;
+          attribute EventHandler ondragend;
+          attribute EventHandler ondragenter;
+          attribute EventHandler ondragleave;
+          attribute EventHandler ondragover;
+          attribute EventHandler ondragstart;
+          attribute EventHandler ondrop;
+          attribute EventHandler ondurationchange;
+          attribute EventHandler onemptied;
+          attribute EventHandler onended;
+          attribute OnErrorEventHandler onerror;
+          attribute EventHandler onfocus;
+          attribute EventHandler oninput;
+          attribute EventHandler oninvalid;
+          attribute EventHandler onkeydown;
+          attribute EventHandler onkeypress;
+          attribute EventHandler onkeyup;
+          attribute EventHandler onload;
+          attribute EventHandler onloadeddata;
+          attribute EventHandler onloadedmetadata;
+          attribute EventHandler onloadstart;
+          attribute EventHandler onmousedown;
+          attribute EventHandler onmousemove;
+          attribute EventHandler onmouseout;
+          attribute EventHandler onmouseover;
+          attribute EventHandler onmouseup;
+          attribute EventHandler onmousewheel;
+          attribute EventHandler onpause;
+          attribute EventHandler onplay;
+          attribute EventHandler onplaying;
+          attribute EventHandler onprogress;
+          attribute EventHandler onratechange;
+          attribute EventHandler onreset;
+          attribute EventHandler onscroll;
+          attribute EventHandler onseeked;
+          attribute EventHandler onseeking;
+          attribute EventHandler onselect;
+          attribute EventHandler onshow;
+          attribute EventHandler onstalled;
+          attribute EventHandler onsubmit;
+          attribute EventHandler onsuspend;
+          attribute EventHandler ontimeupdate;
+          attribute EventHandler onvolumechange;
+          attribute EventHandler onwaiting;
+};
+
+*/
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj);
+
+struct jsclass_document_priv {
+       struct html_content *htmlc;
+       dom_element *node;
+};
+
+#define JSCLASS_NAME htmlelement
+
+#include "jsclass.h"
+
+static JSClass JSCLASS_OBJECT =
+{
+       "HTMLElement",
+       JSCLASS_HAS_PRIVATE,
+       JS_PropertyStub,
+       JS_PropertyStub,
+       JS_PropertyStub,
+       JS_StrictPropertyStub,
+       JS_EnumerateStub,
+       JS_ResolveStub,
+       JS_ConvertStub,
+       jsfinalize_element,
+       JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+#include "element.c"
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj)
+{
+       struct jsclass_document_priv *element;
+       element = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
+       if (element != NULL) {
+               free(element);
+       }
+}
+
+
+
+static JSFunctionSpec jsfunctions_element[] = {
+       JSAPI_FS_ELEMENT,
+       JSAPI_FS_END
+};
+
+
+JSObject *
+jsapi_new_element(JSContext *cx,
+                 JSObject *parent,
+                 struct html_content *htmlc,
+                 dom_element *domelement)
+{
+       /* create element object and return it */
+       JSObject *jselement;
+       struct jsclass_document_priv *element;
+
+       element = malloc(sizeof(element));
+       if (element == NULL) {
+               return NULL;
+       }
+       element->htmlc = htmlc;
+       element->node = domelement;
+
+       jselement = JS_InitClass(cx,
+                          parent,
+                          NULL,
+                          &JSCLASS_OBJECT,
+                          NULL,
+                          0,
+                          NULL,
+                          jsfunctions_element,
+                          NULL,
+                          NULL);
+       if (jselement == NULL) {
+               free(element);
+               return NULL;
+       }
+
+       LOG(("setting private to %p", element));
+       /* private pointer to browsing context */
+       if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
+               LOG(("failed to set private"));
+               free(element);
+               return NULL;
+       }
+
+       return jselement;
+}
diff --git a/javascript/jsapi/jsclass.h b/javascript/jsapi/jsclass.h
new file mode 100644
index 0000000..30b926a
--- /dev/null
+++ b/javascript/jsapi/jsclass.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2012 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** \file
+ * jsapi pseudo class glue.
+ */
+
+#ifndef _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
+#define _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
+
+#ifndef JSCLASS_NAME
+#error "The class name must be defined"
+#endif
+
+#ifndef JSCLASS_TYPE
+#define CLASS jsclass
+#define PRIVATE priv
+#define EXPAND(a,b) PASTE(a,b)
+#define PASTE(x,y) x##_##y
+#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
+#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
+#endif
+
+#endif
diff --git a/javascript/jsapi/node.c b/javascript/jsapi/node.c
index ecb3200..d6a4f44 100644
--- a/javascript/jsapi/node.c
+++ b/javascript/jsapi/node.c
@@ -18,6 +18,7 @@
 
 
 /* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-node 
+
 interface Node : EventTarget {
   const unsigned short ELEMENT_NODE = 1;
   const unsigned short ATTRIBUTE_NODE = 2; // historical
@@ -73,20 +74,9 @@ interface Node : EventTarget {
 };
 */
 
-#include "eventtarget.c"
+#include "jsclass.h"
 
-#ifndef JSCLASS_NAME
-#error "The class name must be defined"
-#endif
-
-#ifndef JSCLASS_TYPE
-#define CLASS jsclass
-#define PRIVATE priv
-#define EXPAND(a,b) PASTE(a,b)
-#define PASTE(x,y) x##_##y
-#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
-#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
-#endif
+#include "eventtarget.c"
 
 static JSBool JSAPI_NATIVE(hasChildNodes, JSContext *cx, uintN argc, jsval *vp)
 {
diff --git a/test/js/doc-dom1.html b/test/js/doc-dom1.html
new file mode 100644
index 0000000..b7743f4
--- /dev/null
+++ b/test/js/doc-dom1.html
@@ -0,0 +1,14 @@
+<html>
+<head>
+<title>Direct DOM element reference</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Direct DOM element reference</h1>
+<p>head</p>
+<script>document.write(document.head.firstElementChild.textContent);</script>
+<p>body</p>
+<script>document.write(document.body.firstElementChild.textContent);</script>
+<p>after</p>
+</body>
+</html>
diff --git a/test/js/doc-dom2.html b/test/js/doc-dom2.html
new file mode 100644
index 0000000..17a916c
--- /dev/null
+++ b/test/js/doc-dom2.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>DOM getElementById</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1 id="heading">Direct DOM element reference</h1>
+<p>Before</p>
+<script>document.write(document.getElementById("heading").textContent);</script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/index.html b/test/js/index.html
index 6bb010c..2768547 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -7,14 +7,20 @@
 <h1>Script Tests</h1>
 <ul>
 <li><a href="assorted.html">Assorted</a></li>
+</ul>
+<h2>Document write tests</h2>
+<ul>
 <li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
 <li><a href="inline-doc-write.html">Script within inline script</a></li>
 <li><a href="sync-script.html">External syncronous script</a></li>
 <li><a href="sync-script-err.html">External syncronous script with missing js 
file</a></li>
 <li><a href="sync-script-css.html">External syncronous script (with 
css)</a></li>
 <li><a href="inline-innerhtml.html">Inline script innerHtml test</a></li>
-
-
+</ul>
+<h2>Document write tests</h2>
+<ul>
+<li><a href="doc-dom1.html">Direct reference</a></li>
+<li><a href="doc-dom2.html">getElementById reference</a></li>
 </ul>
 </body>
 </html>


-----------------------------------------------------------------------

Summary of changes:
 Makefile.sources                       |    2 +-
 javascript/jsapi/document.c            |  122 +--------------
 javascript/jsapi/element.c             |   97 ++-----------
 javascript/jsapi/eventtarget.c         |   14 +--
 javascript/jsapi/htmldocument.c        |  259 ++++++++++++++++++++++++++++++++
 javascript/jsapi/htmlelement.c         |  222 +++++++++++++++++++++++++++
 javascript/{none.c => jsapi/jsclass.h} |   44 ++----
 javascript/jsapi/node.c                |   16 +--
 test/js/doc-dom1.html                  |   14 ++
 test/js/doc-dom2.html                  |   12 ++
 test/js/index.html                     |   10 +-
 11 files changed, 552 insertions(+), 260 deletions(-)
 create mode 100644 javascript/jsapi/htmldocument.c
 create mode 100644 javascript/jsapi/htmlelement.c
 copy javascript/{none.c => jsapi/jsclass.h} (61%)
 create mode 100644 test/js/doc-dom1.html
 create mode 100644 test/js/doc-dom2.html

diff --git a/Makefile.sources b/Makefile.sources
index f7f05ca..0229e91 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -31,7 +31,7 @@ S_DESKTOP := cookies.c history_global_core.c hotlist.c 
knockout.c     \
 
 # Javascript sources
 ifeq ($(NETSURF_USE_JS),YES)
-S_JSAPI = window.c document.c navigator.c console.c element.c
+S_JSAPI = window.c navigator.c console.c htmldocument.c htmlelement.c
 S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
 else
 S_JAVASCRIPT += none.c
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index a40ce20..e5dfcd5 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -16,18 +16,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-
-#include "javascript/jsapi.h"
 
 /* IDL 
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-document
 
-CAUTION - write, writeln are not part of the DOM they come from:
-http://www.w3.org/TR/html5/apis-in-html-documents.html#document.write
-
 interface Document : Node {
   readonly attribute DOMImplementation implementation;
   readonly attribute DOMString URL;
@@ -69,29 +60,7 @@ interface Document : Node {
 
  */
 
-static void jsfinalize_document(JSContext *cx, JSObject *obj);
-
-struct jsclass_document_priv {
-       struct html_content *htmlc;
-       dom_document *node;
-};
-
-static JSClass jsclass_document =
-{
-        "document", 
-       JSCLASS_HAS_PRIVATE, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_StrictPropertyStub,
-        JS_EnumerateStub, 
-       JS_ResolveStub, 
-       JS_ConvertStub, 
-       jsfinalize_document, 
-       JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#define JSCLASS_NAME document
+#include "jsclass.h"
 
 #include "node.c"
 
@@ -104,7 +73,7 @@ static JSBool JSAPI_NATIVE(getElementById, JSContext *cx, 
uintN argc, jsval *vp)
        dom_element *idelement;
        struct jsclass_document_priv *document;
 
-       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&jsclass_document, NULL);
+       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&JSCLASS_OBJECT, NULL);
        if (document == NULL) {
                return JS_FALSE;
        }
@@ -132,88 +101,7 @@ static JSBool JSAPI_NATIVE(getElementById, JSContext *cx, 
uintN argc, jsval *vp)
        return JS_TRUE;
 }
 
-static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
-{
-       JSString* u16_txt;
-       char *txt;
-       unsigned long length;
-       struct jsclass_document_priv *document;
-
-       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&jsclass_document, NULL);
-       if (document == NULL) {
-               return JS_FALSE;
-       }
-
-       if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) {
-               return JS_FALSE;
-       }
-
-       JSString_to_char(u16_txt, txt, length);
-
-       LOG(("content %p parser %p writing %s",
-            document->htmlc, document->htmlc->parser, txt));
-       if (document->htmlc->parser != NULL) {
-               dom_hubbub_parser_insert_chunk(document->htmlc->parser, 
(uint8_t *)txt, length);
-       }
-       JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
+#define JSAPI_FS_DOCUMENT \
+       JSAPI_FS_NODE, \
+       JSAPI_FS(getElementById, 1, 0) \
 
-       return JS_TRUE;
-}
-
-static JSFunctionSpec jsfunctions_document[] = {
-       JSAPI_FS_NODE,
-       JSAPI_FS(write, 1, 0),
-       JSAPI_FS(getElementById, 1, 0),
-       JSAPI_FS_END
-};
-
-
-
-static void jsfinalize_document(JSContext *cx, JSObject *obj)
-{
-       struct jsclass_document_priv *document;
-
-       document = JS_GetInstancePrivate(cx, obj, &jsclass_document, NULL);
-       if (document != NULL) {
-               free(document);
-       }
-}
-
-JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, struct 
html_content *htmlc)
-{
-       /* create document object and return it */
-       JSObject *jsdocument;
-       struct jsclass_document_priv *document;
-
-       document = malloc(sizeof(document));
-       if (document == NULL) {
-               return NULL;
-       }
-       document->htmlc = htmlc;
-       document->node = htmlc->document;
-
-       jsdocument = JS_InitClass(cx, 
-                    parent, 
-                    NULL, 
-                    &jsclass_document, 
-                    NULL, 
-                    0, 
-                    NULL, 
-                    jsfunctions_document, 
-                    NULL, 
-                    NULL);
-       if (jsdocument == NULL) {
-               free(document);
-               return NULL;
-       }
-
-       LOG(("setting document private to %p", document));
-       /* private pointer to browsing context */
-       if (JS_SetPrivate(cx, jsdocument, document) != JS_TRUE) {
-               LOG(("failed to set document private"));
-               free(document);
-               return NULL;
-       }
-       
-       return jsdocument;
-}
diff --git a/javascript/jsapi/element.c b/javascript/jsapi/element.c
index 8ea7017..cefb959 100644
--- a/javascript/jsapi/element.c
+++ b/javascript/jsapi/element.c
@@ -16,18 +16,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <dom/dom.h>
-
-#include "utils/config.h"
-#include "utils/log.h"
-#include "render/html_internal.h"
-
-#include "javascript/jsapi.h"
 
 /* IDL 
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-element
 
-CAUTION - innerHTML etc. are not part of the DOM they come from:
-http://html5.org/specs/dom-parsing.html#extensions-to-the-element-interface
 
 interface Element : Node {
   readonly attribute DOMString? namespaceURI;
@@ -70,88 +61,24 @@ interface Element : Node {
 };
 */
 
-static void jsfinalize_element(JSContext *cx, JSObject *obj);
-
-struct jsclass_document_priv {
-       struct html_content *htmlc;
-       dom_element *node;
-};
-
-static JSClass jsclass_element =
-{
-        "Element", 
-       JSCLASS_HAS_PRIVATE, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_PropertyStub, 
-       JS_StrictPropertyStub,
-        JS_EnumerateStub, 
-       JS_ResolveStub, 
-       JS_ConvertStub, 
-       jsfinalize_element, 
-       JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-#define JSCLASS_NAME element
+#include "jsclass.h"
 
 #include "node.c"
 
-static void jsfinalize_element(JSContext *cx, JSObject *obj)
+static JSBool JSAPI_NATIVE(getAttribute, JSContext *cx, uintN argc, jsval *vp)
 {
-       struct jsclass_document_priv *element;
-       element = JS_GetInstancePrivate(cx, obj, &jsclass_element, NULL);
-       if (element != NULL) {
-               free(element);
-       }
-}
-
+       struct JSCLASS_TYPE *priv;
 
+       priv = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&JSCLASS_OBJECT, NULL);
+       if (priv == NULL)
+               return JS_FALSE;
 
-static JSFunctionSpec jsfunctions_element[] = {
-       JSAPI_FS_NODE,
-       JSAPI_FS_END
-};
 
+       JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
 
-JSObject *
-jsapi_new_element(JSContext *cx, 
-                 JSObject *parent, 
-                 struct html_content *htmlc, 
-                 dom_element *domelement)
-{
-       /* create element object and return it */
-       JSObject *jselement;
-       struct jsclass_document_priv *element;
-
-       element = malloc(sizeof(element));
-       if (element == NULL) {
-               return NULL;
-       }
-       element->htmlc = htmlc;
-       element->node = domelement;
-
-       jselement = JS_InitClass(cx, 
-                          parent, 
-                          NULL, 
-                          &jsclass_element, 
-                          NULL, 
-                          0, 
-                          NULL, 
-                          jsfunctions_element, 
-                          NULL, 
-                          NULL);
-       if (jselement == NULL) {
-               free(element);
-               return NULL;
-       }
-
-       LOG(("setting private to %p", element));
-       /* private pointer to browsing context */
-       if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
-               LOG(("failed to set private"));
-               free(element);
-               return NULL;
-       }
-
-       return jselement;
+       return JS_TRUE;
 }
+
+#define JSAPI_FS_ELEMENT \
+       JSAPI_FS_NODE, \
+       JSAPI_FS(getAttribute, 0, 0)
diff --git a/javascript/jsapi/eventtarget.c b/javascript/jsapi/eventtarget.c
index fc6f6f6..e2ab6a9 100644
--- a/javascript/jsapi/eventtarget.c
+++ b/javascript/jsapi/eventtarget.c
@@ -26,19 +26,7 @@ interface EventTarget {
 };
 */
 
-
-#ifndef JSCLASS_NAME
-#error "The class name must be defined"
-#endif
-
-#ifndef JSCLASS_TYPE
-#define CLASS jsclass
-#define PRIVATE priv
-#define EXPAND(a,b) PASTE(a,b)
-#define PASTE(x,y) x##_##y
-#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
-#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
-#endif
+#include "jsclass.h"
 
 static JSBool JSAPI_NATIVE(addEventListener, JSContext *cx, uintN argc, jsval 
*vp)
 {
diff --git a/javascript/jsapi/htmldocument.c b/javascript/jsapi/htmldocument.c
new file mode 100644
index 0000000..aa9efbc
--- /dev/null
+++ b/javascript/jsapi/htmldocument.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2012 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+
+#include "javascript/jsapi.h"
+
+/* IDL http://www.whatwg.org/specs/web-apps/current-work/#the-document-object
+
+NOTE - this interface is not from the DOM specifications but from the
+html5 spec. I *think* thats right.
+
+[OverrideBuiltins]
+partial interface Document {
+  // resource metadata management
+  [PutForwards=href] readonly attribute Location? location;
+           attribute DOMString domain;
+  readonly attribute DOMString referrer;
+           attribute DOMString cookie;
+  readonly attribute DOMString lastModified;
+  readonly attribute DOMString readyState;
+
+  // DOM tree accessors
+  getter object (DOMString name);
+           attribute DOMString title;
+           attribute DOMString dir;
+           attribute HTMLElement? body;
+  readonly attribute HTMLHeadElement? head;
+  readonly attribute HTMLCollection images;
+  readonly attribute HTMLCollection embeds;
+  readonly attribute HTMLCollection plugins;
+  readonly attribute HTMLCollection links;
+  readonly attribute HTMLCollection forms;
+  readonly attribute HTMLCollection scripts;
+  NodeList getElementsByName(DOMString elementName);
+  NodeList getItems(optional DOMString typeNames); // microdata 
+  readonly attribute DOMElementMap cssElementMap;
+
+  // dynamic markup insertion
+  Document open(optional DOMString type, optional DOMString replace);
+  WindowProxy open(DOMString url, DOMString name, DOMString features, optional 
boolean replace);
+  void close();
+  void write(DOMString... text);
+  void writeln(DOMString... text);
+
+  // user interaction
+  readonly attribute WindowProxy? defaultView;
+  readonly attribute Element? activeElement;
+  boolean hasFocus();
+           attribute DOMString designMode;
+  boolean execCommand(DOMString commandId);
+  boolean execCommand(DOMString commandId, boolean showUI);
+  boolean execCommand(DOMString commandId, boolean showUI, DOMString value);
+  boolean queryCommandEnabled(DOMString commandId);
+  boolean queryCommandIndeterm(DOMString commandId);
+  boolean queryCommandState(DOMString commandId);
+  boolean queryCommandSupported(DOMString commandId);
+  DOMString queryCommandValue(DOMString commandId);
+  readonly attribute HTMLCollection commands;
+
+  // event handler IDL attributes
+           attribute EventHandler onabort;
+           attribute EventHandler onblur;
+           attribute EventHandler oncancel;
+           attribute EventHandler oncanplay;
+           attribute EventHandler oncanplaythrough;
+           attribute EventHandler onchange;
+           attribute EventHandler onclick;
+           attribute EventHandler onclose;
+           attribute EventHandler oncontextmenu;
+           attribute EventHandler oncuechange;
+           attribute EventHandler ondblclick;
+           attribute EventHandler ondrag;
+           attribute EventHandler ondragend;
+           attribute EventHandler ondragenter;
+           attribute EventHandler ondragleave;
+           attribute EventHandler ondragover;
+           attribute EventHandler ondragstart;
+           attribute EventHandler ondrop;
+           attribute EventHandler ondurationchange;
+           attribute EventHandler onemptied;
+           attribute EventHandler onended;
+           attribute OnErrorEventHandler onerror;
+           attribute EventHandler onfocus;
+           attribute EventHandler oninput;
+           attribute EventHandler oninvalid;
+           attribute EventHandler onkeydown;
+           attribute EventHandler onkeypress;
+           attribute EventHandler onkeyup;
+           attribute EventHandler onload;
+           attribute EventHandler onloadeddata;
+           attribute EventHandler onloadedmetadata;
+           attribute EventHandler onloadstart;
+           attribute EventHandler onmousedown;
+           attribute EventHandler onmousemove;
+           attribute EventHandler onmouseout;
+           attribute EventHandler onmouseover;
+           attribute EventHandler onmouseup;
+           attribute EventHandler onmousewheel;
+           attribute EventHandler onpause;
+           attribute EventHandler onplay;
+           attribute EventHandler onplaying;
+           attribute EventHandler onprogress;
+           attribute EventHandler onratechange;
+           attribute EventHandler onreset;
+           attribute EventHandler onscroll;
+           attribute EventHandler onseeked;
+           attribute EventHandler onseeking;
+           attribute EventHandler onselect;
+           attribute EventHandler onshow;
+           attribute EventHandler onstalled;
+           attribute EventHandler onsubmit;
+           attribute EventHandler onsuspend;
+           attribute EventHandler ontimeupdate;
+           attribute EventHandler onvolumechange;
+           attribute EventHandler onwaiting;
+
+  // special event handler IDL attributes that only apply to Document objects
+  [LenientThis] attribute EventHandler onreadystatechange;
+};
+
+ */
+
+static void jsfinalize_document(JSContext *cx, JSObject *obj);
+static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN 
flags, JSObject **objp);
+
+struct jsclass_document_priv {
+       struct html_content *htmlc;
+       dom_document *node;
+};
+
+
+#define JSCLASS_NAME document
+
+#include "jsclass.h"
+
+static JSClass JSCLASS_OBJECT =
+{
+        "document", 
+       JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE, 
+       JS_PropertyStub, 
+       JS_PropertyStub, 
+       JS_PropertyStub, 
+       JS_StrictPropertyStub,
+        JS_EnumerateStub, 
+       (JSResolveOp)jsresove_node, 
+       JS_ConvertStub, 
+       jsfinalize_document, 
+       JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+#include "document.c"
+
+static JSBool jsresove_node(JSContext *cx, JSObject *obj, jsval id, uintN 
flags, JSObject **objp)
+{
+       *objp = NULL;
+       return JS_TRUE;
+}
+
+static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
+{
+       JSString* u16_txt;
+       char *txt;
+       unsigned long length;
+       struct jsclass_document_priv *document;
+
+       document = JS_GetInstancePrivate(cx, JS_THIS_OBJECT(cx,vp), 
&JSCLASS_OBJECT, NULL);
+       if (document == NULL) {
+               return JS_FALSE;
+       }
+
+       if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) {
+               return JS_FALSE;
+       }
+
+       JSString_to_char(u16_txt, txt, length);
+
+       LOG(("content %p parser %p writing %s",
+            document->htmlc, document->htmlc->parser, txt));
+       if (document->htmlc->parser != NULL) {
+               dom_hubbub_parser_insert_chunk(document->htmlc->parser, 
(uint8_t *)txt, length);
+       }
+       JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
+
+       return JS_TRUE;
+}
+
+static JSFunctionSpec jsfunctions_document[] = {
+       JSAPI_FS_DOCUMENT,
+       JSAPI_FS(write, 1, 0),
+       JSAPI_FS_END
+};
+
+static void jsfinalize_document(JSContext *cx, JSObject *obj)
+{
+       struct jsclass_document_priv *document;
+
+       document = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
+       if (document != NULL) {
+               free(document);
+       }
+}
+
+JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, struct 
html_content *htmlc)
+{
+       /* create document object and return it */
+       JSObject *jsdocument;
+       struct jsclass_document_priv *document;
+
+       document = malloc(sizeof(document));
+       if (document == NULL) {
+               return NULL;
+       }
+       document->htmlc = htmlc;
+       document->node = htmlc->document;
+
+       jsdocument = JS_InitClass(cx, 
+                    parent, 
+                    NULL, 
+                    &JSCLASS_OBJECT, 
+                    NULL, 
+                    0, 
+                    NULL, 
+                    jsfunctions_document, 
+                    NULL, 
+                    NULL);
+       if (jsdocument == NULL) {
+               free(document);
+               return NULL;
+       }
+
+       LOG(("setting document private to %p", document));
+       /* private pointer to browsing context */
+       if (JS_SetPrivate(cx, jsdocument, document) != JS_TRUE) {
+               LOG(("failed to set document private"));
+               free(document);
+               return NULL;
+       }
+       
+       return jsdocument;
+}
diff --git a/javascript/jsapi/htmlelement.c b/javascript/jsapi/htmlelement.c
new file mode 100644
index 0000000..90cb06a
--- /dev/null
+++ b/javascript/jsapi/htmlelement.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2012 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dom/dom.h>
+
+#include "utils/config.h"
+#include "utils/log.h"
+#include "render/html_internal.h"
+
+#include "javascript/jsapi.h"
+
+/* IDL http://www.whatwg.org/specs/web-apps/current-work/#elements-in-the-dom
+
+CAUTION - innerHTML and outerHTML etc. are part of the DOM parsing
+         specification but more can be found in:
+http://html5.org/specs/dom-parsing.html#extensions-to-the-element-interface
+
+interface HTMLElement : Element {
+  // metadata attributes
+          attribute DOMString title;
+          attribute DOMString lang;
+          attribute boolean translate;
+          attribute DOMString dir;
+  readonly attribute DOMStringMap dataset;
+
+  // microdata
+          attribute boolean itemScope;
+  [PutForwards=value] readonly attribute DOMSettableTokenList itemType;
+          attribute DOMString itemId;
+  [PutForwards=value] readonly attribute DOMSettableTokenList itemRef;
+  [PutForwards=value] readonly attribute DOMSettableTokenList itemProp;
+  readonly attribute HTMLPropertiesCollection properties;
+          attribute any itemValue;
+
+  // user interaction
+          attribute boolean hidden;
+  void click();
+          attribute long tabIndex;
+  void focus();
+  void blur();
+          attribute DOMString accessKey;
+  readonly attribute DOMString accessKeyLabel;
+          attribute boolean draggable;
+  [PutForwards=value] readonly attribute DOMSettableTokenList dropzone;
+          attribute DOMString contentEditable;
+  readonly attribute boolean isContentEditable;
+          attribute HTMLMenuElement? contextMenu;
+          attribute boolean spellcheck;
+
+  // command API
+  readonly attribute DOMString? commandType;
+  readonly attribute DOMString? commandLabel;
+  readonly attribute DOMString? commandIcon;
+  readonly attribute boolean? commandHidden;
+  readonly attribute boolean? commandDisabled;
+  readonly attribute boolean? commandChecked;
+
+  // styling
+  readonly attribute CSSStyleDeclaration style;
+
+  // event handler IDL attributes
+          attribute EventHandler onabort;
+          attribute EventHandler onblur;
+          attribute EventHandler oncancel;
+          attribute EventHandler oncanplay;
+          attribute EventHandler oncanplaythrough;
+          attribute EventHandler onchange;
+          attribute EventHandler onclick;
+          attribute EventHandler onclose;
+          attribute EventHandler oncontextmenu;
+          attribute EventHandler oncuechange;
+          attribute EventHandler ondblclick;
+          attribute EventHandler ondrag;
+          attribute EventHandler ondragend;
+          attribute EventHandler ondragenter;
+          attribute EventHandler ondragleave;
+          attribute EventHandler ondragover;
+          attribute EventHandler ondragstart;
+          attribute EventHandler ondrop;
+          attribute EventHandler ondurationchange;
+          attribute EventHandler onemptied;
+          attribute EventHandler onended;
+          attribute OnErrorEventHandler onerror;
+          attribute EventHandler onfocus;
+          attribute EventHandler oninput;
+          attribute EventHandler oninvalid;
+          attribute EventHandler onkeydown;
+          attribute EventHandler onkeypress;
+          attribute EventHandler onkeyup;
+          attribute EventHandler onload;
+          attribute EventHandler onloadeddata;
+          attribute EventHandler onloadedmetadata;
+          attribute EventHandler onloadstart;
+          attribute EventHandler onmousedown;
+          attribute EventHandler onmousemove;
+          attribute EventHandler onmouseout;
+          attribute EventHandler onmouseover;
+          attribute EventHandler onmouseup;
+          attribute EventHandler onmousewheel;
+          attribute EventHandler onpause;
+          attribute EventHandler onplay;
+          attribute EventHandler onplaying;
+          attribute EventHandler onprogress;
+          attribute EventHandler onratechange;
+          attribute EventHandler onreset;
+          attribute EventHandler onscroll;
+          attribute EventHandler onseeked;
+          attribute EventHandler onseeking;
+          attribute EventHandler onselect;
+          attribute EventHandler onshow;
+          attribute EventHandler onstalled;
+          attribute EventHandler onsubmit;
+          attribute EventHandler onsuspend;
+          attribute EventHandler ontimeupdate;
+          attribute EventHandler onvolumechange;
+          attribute EventHandler onwaiting;
+};
+
+*/
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj);
+
+struct jsclass_document_priv {
+       struct html_content *htmlc;
+       dom_element *node;
+};
+
+#define JSCLASS_NAME htmlelement
+
+#include "jsclass.h"
+
+static JSClass JSCLASS_OBJECT =
+{
+       "HTMLElement",
+       JSCLASS_HAS_PRIVATE,
+       JS_PropertyStub,
+       JS_PropertyStub,
+       JS_PropertyStub,
+       JS_StrictPropertyStub,
+       JS_EnumerateStub,
+       JS_ResolveStub,
+       JS_ConvertStub,
+       jsfinalize_element,
+       JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+#include "element.c"
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj)
+{
+       struct jsclass_document_priv *element;
+       element = JS_GetInstancePrivate(cx, obj, &JSCLASS_OBJECT, NULL);
+       if (element != NULL) {
+               free(element);
+       }
+}
+
+
+
+static JSFunctionSpec jsfunctions_element[] = {
+       JSAPI_FS_ELEMENT,
+       JSAPI_FS_END
+};
+
+
+JSObject *
+jsapi_new_element(JSContext *cx,
+                 JSObject *parent,
+                 struct html_content *htmlc,
+                 dom_element *domelement)
+{
+       /* create element object and return it */
+       JSObject *jselement;
+       struct jsclass_document_priv *element;
+
+       element = malloc(sizeof(element));
+       if (element == NULL) {
+               return NULL;
+       }
+       element->htmlc = htmlc;
+       element->node = domelement;
+
+       jselement = JS_InitClass(cx,
+                          parent,
+                          NULL,
+                          &JSCLASS_OBJECT,
+                          NULL,
+                          0,
+                          NULL,
+                          jsfunctions_element,
+                          NULL,
+                          NULL);
+       if (jselement == NULL) {
+               free(element);
+               return NULL;
+       }
+
+       LOG(("setting private to %p", element));
+       /* private pointer to browsing context */
+       if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
+               LOG(("failed to set private"));
+               free(element);
+               return NULL;
+       }
+
+       return jselement;
+}
diff --git a/javascript/none.c b/javascript/jsapi/jsclass.h
similarity index 61%
copy from javascript/none.c
copy to javascript/jsapi/jsclass.h
index e5cfb0d..30b926a 100644
--- a/javascript/none.c
+++ b/javascript/jsapi/jsclass.h
@@ -17,37 +17,23 @@
  */
 
 /** \file
- * Dummy implementation of javascript engine functions.
+ * jsapi pseudo class glue.
  */
 
-#include "content/content.h"
+#ifndef _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
+#define _NETSURF_JAVASCRIPT_JSAPI_JSCLASS_H_
 
-#include "javascript/js.h"
-#include "utils/log.h"
+#ifndef JSCLASS_NAME
+#error "The class name must be defined"
+#endif
 
-void js_initialise(void)
-{
-}
+#ifndef JSCLASS_TYPE
+#define CLASS jsclass
+#define PRIVATE priv
+#define EXPAND(a,b) PASTE(a,b)
+#define PASTE(x,y) x##_##y
+#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
+#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
+#endif
 
-void js_finalise(void)
-{
-}
-
-jscontext *js_newcontext(void)
-{
-       return NULL;
-}
-
-void js_destroycontext(jscontext *ctx)
-{
-}
-
-jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
-{
-       return NULL;
-}
-
-bool js_exec(jscontext *ctx, const char *txt, size_t txtlen)
-{
-       return true;
-}
+#endif
diff --git a/javascript/jsapi/node.c b/javascript/jsapi/node.c
index ecb3200..d6a4f44 100644
--- a/javascript/jsapi/node.c
+++ b/javascript/jsapi/node.c
@@ -18,6 +18,7 @@
 
 
 /* IDL http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-node 
+
 interface Node : EventTarget {
   const unsigned short ELEMENT_NODE = 1;
   const unsigned short ATTRIBUTE_NODE = 2; // historical
@@ -73,20 +74,9 @@ interface Node : EventTarget {
 };
 */
 
-#include "eventtarget.c"
+#include "jsclass.h"
 
-#ifndef JSCLASS_NAME
-#error "The class name must be defined"
-#endif
-
-#ifndef JSCLASS_TYPE
-#define CLASS jsclass
-#define PRIVATE priv
-#define EXPAND(a,b) PASTE(a,b)
-#define PASTE(x,y) x##_##y
-#define JSCLASS_OBJECT EXPAND(CLASS,JSCLASS_NAME)
-#define JSCLASS_TYPE EXPAND(JSCLASS_OBJECT,PRIVATE)
-#endif
+#include "eventtarget.c"
 
 static JSBool JSAPI_NATIVE(hasChildNodes, JSContext *cx, uintN argc, jsval *vp)
 {
diff --git a/test/js/doc-dom1.html b/test/js/doc-dom1.html
new file mode 100644
index 0000000..b7743f4
--- /dev/null
+++ b/test/js/doc-dom1.html
@@ -0,0 +1,14 @@
+<html>
+<head>
+<title>Direct DOM element reference</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Direct DOM element reference</h1>
+<p>head</p>
+<script>document.write(document.head.firstElementChild.textContent);</script>
+<p>body</p>
+<script>document.write(document.body.firstElementChild.textContent);</script>
+<p>after</p>
+</body>
+</html>
diff --git a/test/js/doc-dom2.html b/test/js/doc-dom2.html
new file mode 100644
index 0000000..17a916c
--- /dev/null
+++ b/test/js/doc-dom2.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>DOM getElementById</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1 id="heading">Direct DOM element reference</h1>
+<p>Before</p>
+<script>document.write(document.getElementById("heading").textContent);</script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/index.html b/test/js/index.html
index 6bb010c..2768547 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -7,14 +7,20 @@
 <h1>Script Tests</h1>
 <ul>
 <li><a href="assorted.html">Assorted</a></li>
+</ul>
+<h2>Document write tests</h2>
+<ul>
 <li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
 <li><a href="inline-doc-write.html">Script within inline script</a></li>
 <li><a href="sync-script.html">External syncronous script</a></li>
 <li><a href="sync-script-err.html">External syncronous script with missing js 
file</a></li>
 <li><a href="sync-script-css.html">External syncronous script (with 
css)</a></li>
 <li><a href="inline-innerhtml.html">Inline script innerHtml test</a></li>
-
-
+</ul>
+<h2>Document write tests</h2>
+<ul>
+<li><a href="doc-dom1.html">Direct reference</a></li>
+<li><a href="doc-dom2.html">getElementById reference</a></li>
 </ul>
 </body>
 </html>


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to