diff --git a/Makefile.sources b/Makefile.sources
index f7f05ca3a..0229e91d3 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 a40ce2011..e5dfcd523 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -16,18 +16,9 @@
* along with this program. If not, see .
*/
-#include
-
-#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;
+#define JSAPI_FS_DOCUMENT \
+ JSAPI_FS_NODE, \
+ JSAPI_FS(getElementById, 1, 0) \
- 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);
-
- 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 8ea7017d5..cefb95966 100644
--- a/javascript/jsapi/element.c
+++ b/javascript/jsapi/element.c
@@ -16,18 +16,9 @@
* along with this program. If not, see .
*/
-#include
-
-#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;
+
+
+ JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
+
+ return JS_TRUE;
}
-
-
-static JSFunctionSpec jsfunctions_element[] = {
- JSAPI_FS_NODE,
- 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_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;
-}
+#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 fc6f6f657..e2ab6a95d 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 000000000..aa9efbcd1
--- /dev/null
+++ b/javascript/jsapi/htmldocument.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2012 Vincent Sanders
+ *
+ * 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 .
+ */
+
+#include
+
+#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 000000000..90cb06aba
--- /dev/null
+++ b/javascript/jsapi/htmlelement.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2012 Vincent Sanders
+ *
+ * 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 .
+ */
+
+#include
+
+#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 000000000..30b926a52
--- /dev/null
+++ b/javascript/jsapi/jsclass.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2012 Vincent Sanders
+ *
+ * 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 .
+ */
+
+/** \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 ecb32004a..d6a4f4406 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,21 +74,10 @@ interface Node : EventTarget {
};
*/
+#include "jsclass.h"
+
#include "eventtarget.c"
-#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
-
static JSBool JSAPI_NATIVE(hasChildNodes, JSContext *cx, uintN argc, jsval *vp)
{
struct JSCLASS_TYPE *priv;
diff --git a/test/js/doc-dom1.html b/test/js/doc-dom1.html
new file mode 100644
index 000000000..b7743f4c2
--- /dev/null
+++ b/test/js/doc-dom1.html
@@ -0,0 +1,14 @@
+
+
+Direct DOM element reference
+
+
+
+Direct DOM element reference
+head
+
+body
+
+after
+
+
diff --git a/test/js/doc-dom2.html b/test/js/doc-dom2.html
new file mode 100644
index 000000000..17a916c81
--- /dev/null
+++ b/test/js/doc-dom2.html
@@ -0,0 +1,12 @@
+
+
+DOM getElementById
+
+
+
+Direct DOM element reference
+Before
+
+Afterwards
+
+
diff --git a/test/js/index.html b/test/js/index.html
index 6bb010c3b..276854712 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -7,14 +7,20 @@
Script Tests
+Document write tests
+
+Document write tests
+