diff options
author | Vincent Sanders <vince@kyllikki.org> | 2016-06-07 00:07:47 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2016-06-07 00:07:47 +0100 |
commit | 9754539e2275e33af34b5de9d343b85e8122d871 (patch) | |
tree | 587ea8b67f8bfc75e529dcab8e9d7dd7b8a2771c /javascript/jsapi | |
parent | 0fad46cd0f21af5b896e7a6ee1f3b45fdf2a091a (diff) | |
download | netsurf-9754539e2275e33af34b5de9d343b85e8122d871.tar.gz netsurf-9754539e2275e33af34b5de9d343b85e8122d871.tar.bz2 |
remove unused and broken spidermonkey integration
Diffstat (limited to 'javascript/jsapi')
-rw-r--r-- | javascript/jsapi/Makefile | 53 | ||||
-rw-r--r-- | javascript/jsapi/comment.bnd | 47 | ||||
-rw-r--r-- | javascript/jsapi/console.bnd | 47 | ||||
-rw-r--r-- | javascript/jsapi/dom.bnd | 172 | ||||
-rw-r--r-- | javascript/jsapi/event.bnd | 37 | ||||
-rw-r--r-- | javascript/jsapi/htmlcollection.bnd | 93 | ||||
-rw-r--r-- | javascript/jsapi/htmldocument.bnd | 596 | ||||
-rw-r--r-- | javascript/jsapi/htmlelement.bnd | 721 | ||||
-rw-r--r-- | javascript/jsapi/jsapi.c | 613 | ||||
-rw-r--r-- | javascript/jsapi/jsapi.h | 396 | ||||
-rw-r--r-- | javascript/jsapi/location.bnd | 224 | ||||
-rw-r--r-- | javascript/jsapi/navigator.bnd | 121 | ||||
-rw-r--r-- | javascript/jsapi/node.bnd | 35 | ||||
-rw-r--r-- | javascript/jsapi/nodelist.bnd | 99 | ||||
-rw-r--r-- | javascript/jsapi/text.bnd | 47 | ||||
-rw-r--r-- | javascript/jsapi/window.bnd | 402 |
16 files changed, 0 insertions, 3703 deletions
diff --git a/javascript/jsapi/Makefile b/javascript/jsapi/Makefile deleted file mode 100644 index f684287ab..000000000 --- a/javascript/jsapi/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -# NetSurf javascript source file inclusion -# -# Included by javascript/Makefile -# - -# ---------------------------------------------------------------------------- -# JSAPI binding -# ---------------------------------------------------------------------------- - -D_JSAPI_BINDING:= - -JSAPI_BINDING_htmldocument := javascript/jsapi/htmldocument.bnd -JSAPI_BINDING_htmlelement := javascript/jsapi/htmlelement.bnd -JSAPI_BINDING_window := javascript/jsapi/window.bnd -JSAPI_BINDING_navigator := javascript/jsapi/navigator.bnd -JSAPI_BINDING_console := javascript/jsapi/console.bnd -JSAPI_BINDING_location := javascript/jsapi/location.bnd -JSAPI_BINDING_htmlcollection := javascript/jsapi/htmlcollection.bnd -JSAPI_BINDING_nodelist := javascript/jsapi/nodelist.bnd -JSAPI_BINDING_text := javascript/jsapi/text.bnd -JSAPI_BINDING_comment := javascript/jsapi/comment.bnd -JSAPI_BINDING_node := javascript/jsapi/node.bnd -JSAPI_BINDING_event := javascript/jsapi/event.bnd - -# 1: input binding file -# 2: source output file -# 3: header output file -# 4: binding name -define convert_jsapi_binding - -S_JAVASCRIPT_BINDING += $(2) -D_JSAPI_BINDING += $(patsubst %.c,%.d,$(2)) - -$(2): $(1) $(OBJROOT)/created - $$(VQ)echo " GENBIND: $(1)" - $(Q)nsgenbind -g -I javascript/WebIDL -d $(patsubst %.c,%.d,$(2)) -h $(3) -o $(2) $(1) - -$(3): $(2) - -endef - - -S_JSAPI := - -S_JAVASCRIPT += content.c jsapi/jsapi.c $(addprefix jsapi/,$(S_JSAPI)) - -$(eval $(foreach V,$(filter JSAPI_BINDING_%,$(.VARIABLES)),$(call convert_jsapi_binding,$($(V)),$(OBJROOT)/$(patsubst JSAPI_BINDING_%,%,$(V)).c,$(OBJROOT)/$(patsubst JSAPI_BINDING_%,%,$(V)).h,$(patsubst JSAPI_BINDING_%,%,$(V))_jsapi))) - -ifeq ($(filter $(MAKECMDGOALS),clean test coverage),) --include $(D_JSAPI_BINDING) -endif - diff --git a/javascript/jsapi/comment.bnd b/javascript/jsapi/comment.bnd deleted file mode 100644 index 580f5cbed..000000000 --- a/javascript/jsapi/comment.bnd +++ /dev/null @@ -1,47 +0,0 @@ -/* Binding to generate Comment interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - - -webidlfile "html.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "render/html_internal.h" -#include "javascript/jsapi.h" - -#include "comment.h" - -%} - -#include "dom.bnd" - -binding comment { - type js_libdom; /* the binding type */ - - interface Comment; /* Web IDL interface to generate */ - - private "dom_comment *" node; - private "struct html_content *" htmlc; -} - -api finalise %{ - if (private != NULL) { - dom_node_unref(private->node); - } -%} diff --git a/javascript/jsapi/console.bnd b/javascript/jsapi/console.bnd deleted file mode 100644 index 8303eb06c..000000000 --- a/javascript/jsapi/console.bnd +++ /dev/null @@ -1,47 +0,0 @@ -/* Binding to generate Console interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -webidlfile "console.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include "utils/config.h" -#include "utils/log.h" -#include "javascript/jsapi.h" - -#include "console.h" - -%} - -binding navigator { - type js_libdom; /* the binding type */ - - interface Console; /* Web IDL interface to generate */ - -} - -operation log %{ - unsigned int argloop; - JSString *jsstr; - unsigned long jsstrlen; - char *txt; - - for (argloop = 0; argloop < argc; argloop++) { - jsstr = JS_ValueToString(cx, argv[argloop]); - - JSString_to_char(jsstr, txt, jsstrlen); - LOG("%s", txt); - } -%} diff --git a/javascript/jsapi/dom.bnd b/javascript/jsapi/dom.bnd deleted file mode 100644 index 3fc7f9ed1..000000000 --- a/javascript/jsapi/dom.bnd +++ /dev/null @@ -1,172 +0,0 @@ -/* Binding to generate interfaces for the DOM IDL - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -webidlfile "dom.idl"; - -preamble %{ -#include "comment.h" -#include "text.h" -#include "htmlelement.h" -%} - - -prologue %{ -/* CAUTION this expects all javascript Node objects private pointers - * to have private->node in the same place. - */ -static struct dom_node *jsnode_to_domnode(JSContext *cx, JSObject *jsnode) -{ - struct jsclass_private *jsnode_private; - - if (jsnode == NULL) { - return NULL; - } - - /* element */ - jsnode_private = JS_GetInstancePrivate(cx, - jsnode, - &JSClass_HTMLElement, - NULL); - if (jsnode_private != NULL) { - return (struct dom_node *)jsnode_private->node; - } - - /* text */ - jsnode_private = JS_GetInstancePrivate(cx, - jsnode, - &JSClass_Text, - NULL); - if (jsnode_private != NULL) { - return (struct dom_node *)jsnode_private->node; - } - - /* comment */ - jsnode_private = JS_GetInstancePrivate(cx, - jsnode, - &JSClass_Comment, - NULL); - if (jsnode_private != NULL) { - return (struct dom_node *)jsnode_private->node; - } - - return NULL; -} - -%} - -/* interface Node members */ - -getter nodeType %{ - dom_exception exc; - dom_node_type node_type; - - exc = dom_node_get_node_type(private->node, &node_type); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - jsret = node_type; -%} - - -getter nodeName %{ - dom_exception exc; - dom_string *name; - - exc = dom_node_get_node_name(private->node, &name); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (name != NULL) { - jsret = JS_NewStringCopyN(cx, - dom_string_data(name), - dom_string_length(name)); - dom_string_unref(name); - } -%} - -getter nodeValue %{ - dom_exception exc; - dom_string *value; - - exc = dom_node_get_node_value(private->node, &value); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (value != NULL) { - jsret = JS_NewStringCopyN(cx, - dom_string_data(value), - dom_string_length(value)); - dom_string_unref(value); - } -%} - -getter textContent %{ - dom_exception exc; - dom_string *content; - - exc = dom_node_get_text_content(private->node, &content); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (content != NULL) { - jsret = JS_NewStringCopyN(cx, dom_string_data(content), dom_string_length(content)); - dom_string_unref(content); - - } -%} - -/* interface Node { Node appendChild(Node node); } */ -operation appendChild %{ - struct dom_node *domnode; /* dom node from js input node */ - struct dom_node *result = NULL; - dom_exception exc; - dom_node_type node_type; - - domnode = jsnode_to_domnode(cx, node); - if (domnode == NULL) { - /* should cause Error: NOT_FOUND_ERR: DOM Exception 8 */ - JSLOG("Error: NOT_FOUND_ERR: DOM Exception 8"); - return JS_FALSE; - } - - JSLOG("appending js node %p (dom %p)", node, domnode); - - /* append the found element */ - exc = dom_node_append_child(private->node, domnode, &result); - if (exc != DOM_NO_ERR) { - JSLOG("Error: DOM Exception (libdom append child)"); - return JS_FALSE; - } - - if (result != NULL) { - exc = dom_node_get_node_type(result, &node_type); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - switch (node_type) { - case DOM_ELEMENT_NODE: - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)result, private->htmlc); - break; - - case DOM_TEXT_NODE: - jsret = jsapi_new_Text(cx, NULL, NULL, (dom_text *)result, private->htmlc); - break; - - default: - JSLOG("Unsupported result node type %d", node_type); - } - - } else { - JSLOG("No result"); - } -%} diff --git a/javascript/jsapi/event.bnd b/javascript/jsapi/event.bnd deleted file mode 100644 index b8b0aff47..000000000 --- a/javascript/jsapi/event.bnd +++ /dev/null @@ -1,37 +0,0 @@ -/* Binding to generate event interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -webidlfile "dom.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ -#include <stdlib.h> - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "javascript/jsapi.h" - -#include "event.h" - -%} - -binding node { - type js_libdom; /* the binding type */ - - interface Event; /* Web IDL interface to generate */ - - private "dom_event *" event; -} diff --git a/javascript/jsapi/htmlcollection.bnd b/javascript/jsapi/htmlcollection.bnd deleted file mode 100644 index 38e14ed1d..000000000 --- a/javascript/jsapi/htmlcollection.bnd +++ /dev/null @@ -1,93 +0,0 @@ -/* Binding to generate HTMLcollection interface - * - * The js_libdom (javascript to libdom) binding type is currently the - * only one implemented and this principly describes that binding. - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -/* The hdrcomment are added into the geenrated output comment header */ -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "javascript/jsapi.h" -#include "render/html_internal.h" - -#include "htmlelement.h" -#include "htmlcollection.h" - -%} - -webidlfile "dom.idl"; - -binding htmlcollection { - type js_libdom; /* the binding type */ - - interface HTMLCollection; /* The WebIDL interface to generate a binding for */ - - private "dom_html_collection *" collection; - private "struct html_content *" htmlc; -} - -getter length %{ - dom_exception err; - - err = dom_html_collection_get_length(private->collection, &jsret); - if (err != DOM_NO_ERR) { - return JS_FALSE; - } - %} - -operation item %{ - dom_exception err; - dom_node *domnode; - - err = dom_html_collection_item(private->collection, index, &domnode); - if (err != DOM_NO_ERR) { - return JS_FALSE; - } - - if (domnode != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc); - } - %} - -operation namedItem %{ - dom_exception err; - dom_node *domnode; - dom_string *name_dom; - - err = dom_string_create((uint8_t *)name, name_len, &name_dom); - if (err != DOM_NO_ERR) { - return JS_FALSE; - } - - err = dom_html_collection_named_item(private->collection, name_dom, &domnode); - if (err != DOM_NO_ERR) { - return JS_FALSE; - } - - if (domnode != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc); - } - -%} - -api finalise %{ - if (private != NULL) { - dom_html_collection_unref(private->collection); - } -%} diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd deleted file mode 100644 index 705f56d85..000000000 --- a/javascript/jsapi/htmldocument.bnd +++ /dev/null @@ -1,596 +0,0 @@ -/* Binding to generate HTMLdocument interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -webidlfile "html.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "utils/corestrings.h" -#include "utils/libdom.h" -#include "content/urldb.h" -#include "javascript/js.h" -#include "javascript/jsapi.h" -#include "render/html_internal.h" - -#include "htmldocument.h" -#include "htmlelement.h" -#include "text.h" -#include "nodelist.h" -#include "location.h" - -%} - -#include "dom.bnd" - -binding document { - type js_libdom; /* the binding type */ - - interface Document; /* Web IDL interface to generate */ - - /* parameters to constructor value stored in private - * context structure. - */ - private "dom_document *" node; - private "struct html_content *" htmlc; - - /** location instantiated on first use */ - property unshared location; - - /* compatability mode instantiated on first use */ - property unshared compatMode; - - /* events through a single interface */ - property unshared type EventHandler; -} - -api finalise %{ - LOG("jscontext:%p jsobject:%p private:%p", cx, obj, private); - if (private != NULL) { - JSLOG("dom_document %p in content %p", - private->node, private->htmlc); - dom_node_unref(private->node); - } -%} - - -getter location %{ - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { - /* already created - return it */ - return JS_TRUE; - } - jsret = jsapi_new_Location(cx, - NULL, - NULL, - llcache_handle_get_url(private->htmlc->base.llcache)); -%} - -getter URL %{ - jsval loc; - jsval jsstr = JSVAL_NULL; - if (JS_GetProperty(cx, obj, "location", &loc) == JS_TRUE) { - JS_GetProperty(cx, JSVAL_TO_OBJECT(loc), "href", &jsstr); - } - jsret = JSVAL_TO_STRING(jsstr); -%} - -getter documentURI %{ - jsval loc; - jsval jsstr = JSVAL_NULL; - if (JS_GetProperty(cx, obj, "location", &loc) == JS_TRUE) { - JS_GetProperty(cx, JSVAL_TO_OBJECT(loc), "href", &jsstr); - } - jsret = JSVAL_TO_STRING(jsstr); -%} - - -getter compatMode %{ - /* Returns the string "CSS1Compat" if document is in no-quirks - * mode or limited-quirks mode, and "BackCompat", if document - * is in quirks mode. - */ - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { - /* already created, just use it */ - return JS_TRUE; - } - if (private->htmlc->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL) { - jsret = JS_NewStringCopyN(cx, "BackCompat", SLEN("BackCompat")); - } else { - jsret = JS_NewStringCopyN(cx, "CSS1Compat", SLEN("CSS1Compat")); - } - -%} - -/* -getter characterSet %{ -%} - -getter contentType %{ -%} -*/ - -getter cookie %{ - char *cookie_str; - cookie_str = urldb_get_cookie(llcache_handle_get_url(private->htmlc->base.llcache), false); - if (cookie_str != NULL) { - jsret = JS_NewStringCopyN(cx, cookie_str, strlen(cookie_str)); - free(cookie_str); - } -%} - -getter documentElement %{ - dom_exception exc; - dom_element *element; - - /* document (html) element */ - exc = dom_document_get_document_element(private->node, (void *)&element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (element != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); - } -%} - -getter head %{ - dom_node *element; - dom_node *head; - dom_exception exc; - - /* document (html) element */ - exc = dom_document_get_document_element(private->node, &element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (element != NULL) { - head = libdom_find_first_element(element, corestring_lwc_head) ; - if (head != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)head, private->htmlc); - } - dom_node_unref(element); - } -%} - -getter body %{ - dom_node *element; - dom_node *body; - dom_exception exc; - - JSDBG("Getting your body"); - - /* document (html) element */ - exc = dom_document_get_document_element(private->node, &element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (element != NULL) { - body = libdom_find_first_element(element, corestring_lwc_body) ; - if (body != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)body, private->htmlc); - } - dom_node_unref(element); - } - - JSDBG("returning jsobject %p",jsret); - -%} - -operation getElementById %{ - dom_string *elementId_dom; - dom_element *element; - dom_exception exc; - - exc = dom_string_create((unsigned char*)elementId, elementId_len, &elementId_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_document_get_element_by_id(private->node, elementId_dom, &element); - dom_string_unref(elementId_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (element != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); - } -%} - -/* - * - * Dom 4 says this should return a htmlcollection, libdom currently - * returns DOM 3 spec of a nodelist - */ -/* HTMLCollection Document::getElementsByTagName(DOMString localName); */ -operation getElementsByTagName %{ - dom_string *localName_dom; - /* dom_html_collection *collection;*/ - dom_nodelist *nodelist; - dom_exception exc; - - exc = dom_string_create((uint8_t *)localName, localName_len, &localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_document_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist); - dom_string_unref(localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (/*collection*/nodelist != NULL) { - /*jsret = jsapi_new_HTMLCollection(cx, - NULL, - NULL, - collection, - private->htmlc);*/ - jsret = jsapi_new_NodeList(cx, - NULL, - NULL, - nodelist, - private->htmlc); - } - -%} - -operation write %{ - if (private->htmlc->parser != NULL) { - dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len); - } -%} - -/* interface Document (dom) { Text createTextNode(DOMString data); } */ -operation createTextNode %{ - dom_string *data_dom; - dom_exception exc; - dom_text *text; - - if (data != NULL) { - - JSDBG("Creating text node for string \"%s\"", data); - exc = dom_string_create((unsigned char*)data, data_len, &data_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_document_create_text_node(private->node, data_dom, &text); - dom_string_unref(data_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - jsret = jsapi_new_Text(cx, NULL, NULL, text, private->htmlc); - } - - JSDBG("returning jsobject %p",jsret); - -%} - -/* interface Document (dom) { Comment createComment(DOMString data); } */ -operation createComment %{ - dom_string *data_dom; - dom_exception exc; - dom_comment *comment; - - if (data != NULL) { - - JSDBG("Creating string \"%s\"", data); - exc = dom_string_create((unsigned char*)data, - data_len, - &data_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - JSDBG("Creating comment object for dom string \"%s\"", - dom_string_data(data_dom)); - exc = dom_document_create_comment(private->node, - data_dom, - &comment); - dom_string_unref(data_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - jsret = jsapi_new_Comment(cx, NULL, NULL, comment, private->htmlc); - } - - JSDBG("returning jsobject %p", jsret); - -%} - -/* in dom Document */ -operation createElement %{ - dom_string *localName_dom; - dom_exception exc; - dom_element *element; - - if (localName != NULL) { - JSDBG("Creating text node for string \"%s\"", localName); - exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_document_create_element(private->node, localName_dom, &element); - dom_string_unref(localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); - } - - JSDBG("returning jsobject %p",jsret); - -%} - -getter EventHandler %{ - JSLOG("propname[%d].name=\"%s\"", - tinyid, - jsclass_properties[tinyid].name); -%} - - -setter EventHandler %{ - dom_string *event_type_dom; - - JSLOG("propname[%d].name=\"%s\"", - tinyid, - jsclass_properties[tinyid].name); - - switch (tinyid) { - case JSAPI_PROP_TINYID_onabort: - event_type_dom = corestring_dom_abort; - break; - - case JSAPI_PROP_TINYID_onblur: - event_type_dom = corestring_dom_blur; - break; - - case JSAPI_PROP_TINYID_oncancel: - event_type_dom = corestring_dom_cancel; - break; - - case JSAPI_PROP_TINYID_oncanplay: - event_type_dom = corestring_dom_canplay; - break; - - case JSAPI_PROP_TINYID_oncanplaythrough: - event_type_dom = corestring_dom_canplaythrough; - break; - - case JSAPI_PROP_TINYID_onchange: - event_type_dom = corestring_dom_change; - break; - - case JSAPI_PROP_TINYID_onclick: - event_type_dom = corestring_dom_click; - break; - - case JSAPI_PROP_TINYID_onclose: - event_type_dom = corestring_dom_close; - break; - - case JSAPI_PROP_TINYID_oncontextmenu: - event_type_dom = corestring_dom_contextmenu; - break; - - case JSAPI_PROP_TINYID_oncuechange: - event_type_dom = corestring_dom_cuechange; - break; - - case JSAPI_PROP_TINYID_ondblclick: - event_type_dom = corestring_dom_dblclick; - break; - - case JSAPI_PROP_TINYID_ondrag: - event_type_dom = corestring_dom_drag; - break; - - case JSAPI_PROP_TINYID_ondragend: - event_type_dom = corestring_dom_dragend; - break; - - case JSAPI_PROP_TINYID_ondragenter: - event_type_dom = corestring_dom_dragenter; - break; - - case JSAPI_PROP_TINYID_ondragleave: - event_type_dom = corestring_dom_dragleave; - break; - - case JSAPI_PROP_TINYID_ondragover: - event_type_dom = corestring_dom_dragover; - break; - - case JSAPI_PROP_TINYID_ondragstart: - event_type_dom = corestring_dom_dragstart; - break; - - case JSAPI_PROP_TINYID_ondrop: - event_type_dom = corestring_dom_drop; - break; - - case JSAPI_PROP_TINYID_ondurationchange: - event_type_dom = corestring_dom_durationchange; - break; - - case JSAPI_PROP_TINYID_onemptied: - event_type_dom = corestring_dom_emptied; - break; - - case JSAPI_PROP_TINYID_onended: - event_type_dom = corestring_dom_ended; - break; - - case JSAPI_PROP_TINYID_onerror: - event_type_dom = corestring_dom_error; - break; - - case JSAPI_PROP_TINYID_onfocus: - event_type_dom = corestring_dom_focus; - break; - - case JSAPI_PROP_TINYID_oninput: - event_type_dom = corestring_dom_input; - break; - - case JSAPI_PROP_TINYID_oninvalid: - event_type_dom = corestring_dom_invalid; - break; - - case JSAPI_PROP_TINYID_onkeydown: - event_type_dom = corestring_dom_keydown; - break; - - case JSAPI_PROP_TINYID_onkeypress: - event_type_dom = corestring_dom_keypress; - break; - - case JSAPI_PROP_TINYID_onkeyup: - event_type_dom = corestring_dom_keyup; - break; - - case JSAPI_PROP_TINYID_onload: - event_type_dom = corestring_dom_load; - break; - - case JSAPI_PROP_TINYID_onloadeddata: - event_type_dom = corestring_dom_loadeddata; - break; - - case JSAPI_PROP_TINYID_onloadedmetadata: - event_type_dom = corestring_dom_loadedmetadata; - break; - - case JSAPI_PROP_TINYID_onloadstart: - event_type_dom = corestring_dom_loadstart; - break; - - case JSAPI_PROP_TINYID_onmousedown: - event_type_dom = corestring_dom_mousedown; - break; - - case JSAPI_PROP_TINYID_onmousemove: - event_type_dom = corestring_dom_mousemove; - break; - - case JSAPI_PROP_TINYID_onmouseout: - event_type_dom = corestring_dom_mouseout; - break; - - case JSAPI_PROP_TINYID_onmouseover: - event_type_dom = corestring_dom_mouseover; - break; - - case JSAPI_PROP_TINYID_onmouseup: - event_type_dom = corestring_dom_mouseup; - break; - - case JSAPI_PROP_TINYID_onmousewheel: - event_type_dom = corestring_dom_mousewheel; - break; - - case JSAPI_PROP_TINYID_onpause: - event_type_dom = corestring_dom_pause; - break; - - case JSAPI_PROP_TINYID_onplay: - event_type_dom = corestring_dom_play; - break; - - case JSAPI_PROP_TINYID_onplaying: - event_type_dom = corestring_dom_playing; - break; - - case JSAPI_PROP_TINYID_onprogress: - event_type_dom = corestring_dom_progress; - break; - - case JSAPI_PROP_TINYID_onratechange: - event_type_dom = corestring_dom_ratechange; - break; - - case JSAPI_PROP_TINYID_onreset: - event_type_dom = corestring_dom_reset; - break; - - case JSAPI_PROP_TINYID_onscroll: - event_type_dom = corestring_dom_scroll; - break; - - case JSAPI_PROP_TINYID_onseeked: - event_type_dom = corestring_dom_seeked; - break; - - case JSAPI_PROP_TINYID_onseeking: - event_type_dom = corestring_dom_seeking; - break; - - case JSAPI_PROP_TINYID_onselect: - event_type_dom = corestring_dom_select; - break; - - case JSAPI_PROP_TINYID_onshow: - event_type_dom = corestring_dom_show; - break; - - case JSAPI_PROP_TINYID_onstalled: - event_type_dom = corestring_dom_stalled; - break; - - case JSAPI_PROP_TINYID_onsubmit: - event_type_dom = corestring_dom_submit; - break; - - case JSAPI_PROP_TINYID_onsuspend: - event_type_dom = corestring_dom_suspend; - break; - - case JSAPI_PROP_TINYID_ontimeupdate: - event_type_dom = corestring_dom_timeupdate; - break; - - case JSAPI_PROP_TINYID_onvolumechange: - event_type_dom = corestring_dom_volumechange; - break; - - case JSAPI_PROP_TINYID_onwaiting: - event_type_dom = corestring_dom_waiting; - break; - - case JSAPI_PROP_TINYID_onreadystatechange: - event_type_dom = corestring_dom_readystatechange; - break; - - default: - JSLOG("called with unknown tinyid"); - return JS_TRUE; - } - - js_dom_event_add_listener((struct jscontext *)cx, - private->node, - (dom_node *)private->node, - event_type_dom, - vp); -%} diff --git a/javascript/jsapi/htmlelement.bnd b/javascript/jsapi/htmlelement.bnd deleted file mode 100644 index 33b495195..000000000 --- a/javascript/jsapi/htmlelement.bnd +++ /dev/null @@ -1,721 +0,0 @@ -/* Binding to generate HTMLElement interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -webidlfile "html.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "utils/corestrings.h" -#include "javascript/js.h" -#include "javascript/jsapi.h" -#include "render/html_internal.h" - -#include "htmlelement.h" -#include "text.h" -#include "location.h" -#include "nodelist.h" - -%} - -#include "dom.bnd" - -binding htmlelement { - type js_libdom; /* the binding type */ - - interface HTMLElement; /* Web IDL interface to generate */ - /* superclasses - - interface HTMLAnchorElement - interface HTMLAppletElement - interface HTMLAreaElement - interface HTMLBaseElement - interface HTMLBaseFontElement - interface HTMLBodyElement - interface HTMLBRElement - interface HTMLButtonElement - interface HTMLCanvasElement - interface HTMLCommandElement - interface HTMLDataElement - interface HTMLDataListElement - interface HTMLDetailsElement - interface HTMLDialogElement - interface HTMLDirectoryElement - interface HTMLDivElement - interface HTMLDListElement - interface HTMLEmbedElement - interface HTMLFieldSetElement - interface HTMLFontElement - interface HTMLFormElement - interface HTMLFrameElement - interface HTMLFrameSetElement - interface HTMLHeadElement - interface HTMLHeadingElement - interface HTMLHRElement - interface HTMLHtmlElement - interface HTMLIFrameElement - interface HTMLImageElement - interface HTMLInputElement - interface HTMLKeygenElement - interface HTMLLabelElement - interface HTMLLegendElement - interface HTMLLIElement - interface HTMLLinkElement - interface HTMLMapElement - interface HTMLMarqueeElement - interface HTMLMediaElement - interface HTMLMenuElement - interface HTMLMetaElement - interface HTMLMeterElement - interface HTMLModElement - interface HTMLObjectElement - interface HTMLOListElement - interface HTMLOptGroupElement - interface HTMLOptionElement - interface HTMLOutputElement - interface HTMLParagraphElement - interface HTMLParamElement - interface HTMLPreElement - interface HTMLProgressElement - interface HTMLQuoteElement - interface HTMLScriptElement - interface HTMLSelectElement - interface HTMLSourceElement - interface HTMLSpanElement - interface HTMLStyleElement - interface HTMLTableCaptionElement - interface HTMLTableCellElement - interface HTMLTableColElement - interface HTMLTableElement - interface HTMLTableRowElement - interface HTMLTableSectionElement - interface HTMLTextAreaElement - interface HTMLTimeElement - interface HTMLTitleElement - interface HTMLTrackElement - interface HTMLUListElement - interface HTMLUnknownElement - */ - - private "dom_element *" node; - private "struct html_content *" htmlc; - - /* tag name retrieved first time its fetched and doesnt change */ - property unshared tagName; - - /* events through a single interface */ - property unshared type EventHandler; -} - -api finalise %{ - if (private != NULL) { - dom_node_unref(private->node); - } -%} - -/* interface Element in dom idl */ - -/* readonly attribute DOMString Element::tagName; */ -getter tagName %{ - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { - /* already created - return it */ - return JS_TRUE; - } - - dom_exception exc; - dom_string *name; - - exc = dom_element_get_tag_name(private->node, &name); - if (name != NULL) { - jsret = JS_NewStringCopyN(cx, dom_string_data(name), dom_string_length(name)); - dom_string_unref(name); - } -%} - -/* attribute DOMString Element::id; */ -getter id %{ - dom_string *value; - dom_exception exc; - - exc = dom_element_get_attribute(private->node, corestring_dom_id, &value); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (value != NULL) { - jsret = JS_NewStringCopyN(cx, dom_string_data(value), dom_string_length(value)); - dom_string_unref(value); - } -%} - -/* attribute DOMString Element::className; */ -getter className %{ - dom_string *value; - dom_exception exc; - - exc = dom_element_get_attribute(private->node, corestring_dom_class, &value); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (value != NULL) { - jsret = JS_NewStringCopyN(cx, dom_string_data(value), dom_string_length(value)); - dom_string_unref(value); - } -%} - -/* DOMString? Element::getAttribute(DOMString name); */ -operation getAttribute %{ - dom_string *value; - dom_string *name_dom; - dom_exception exc; - - exc = dom_string_create((unsigned char*)name, name_len, &name_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_element_get_attribute(private->node, name_dom, &value); - dom_string_unref(name_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (value != NULL) { - jsret = JS_NewStringCopyN(cx, dom_string_data(value), dom_string_length(value)); - dom_string_unref(value); - } -%} - -/* void Element::setAttribute(DOMString name, DOMString value); */ -operation setAttribute %{ - dom_string *value_dom; - dom_string *name_dom; - dom_exception exc; - - exc = dom_string_create((unsigned char*)name, name_len, &name_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_string_create((unsigned char*)name, name_len, &value_dom); - if (exc != DOM_NO_ERR) { - dom_string_unref(name_dom); - return JS_FALSE; - } - - exc = dom_element_set_attribute(private->node, name_dom, value_dom); - dom_string_unref(name_dom); - dom_string_unref(value_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } -%} - -/* void Element::removeAttribute(DOMString name); */ -operation removeAttribute %{ - dom_string *name_dom; - dom_exception exc; - - exc = dom_string_create((unsigned char*)name, name_len, &name_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_element_remove_attribute(private->node, name_dom); - dom_string_unref(name_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } -%} - -/* boolean Element::hasAttribute(DOMString name); */ -operation hasAttribute %{ - bool result; - dom_string *name_dom; - dom_exception exc; - - exc = dom_string_create((unsigned char*)name, name_len, &name_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_element_has_attribute(private->node, name_dom, &result); - dom_string_unref(name_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (result) { - jsret = JS_TRUE; - } -%} - -/* - * - * Dom 4 says this should return a htmlcollection, libdom currently - * returns DOM 3 spec of a nodelist - */ -/* HTMLCollection Element::getElementsByTagName(DOMString localName); */ -operation getElementsByTagName %{ - dom_string *localName_dom; - /* dom_html_collection *collection;*/ - dom_nodelist *nodelist; - dom_exception exc; - - exc = dom_string_create((uint8_t *)localName, localName_len, &localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - exc = dom_element_get_elements_by_tag_name(private->node, localName_dom, /*&collection*/&nodelist); - dom_string_unref(localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - if (/*collection*/nodelist != NULL) { - /*jsret = jsapi_new_HTMLCollection(cx, - NULL, - NULL, - collection, - private->htmlc);*/ - jsret = jsapi_new_NodeList(cx, - NULL, - NULL, - nodelist, - private->htmlc); - } - -%} - -/* - * DOM 3 has these as the element traversal extension - * - * http://dev.w3.org/2006/webapi/ElementTraversal/publish/ElementTraversal.html - */ - -getter firstElementChild %{ - dom_node *element; - dom_exception exc; - dom_node_type node_type; - dom_node *next_node; - - exc = dom_node_get_first_child(private->node, &element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - while (element != NULL) { - exc = dom_node_get_node_type(element, &node_type); - if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) { - /* found it */ - jsret = jsapi_new_HTMLElement(cx, - NULL, - NULL, - (dom_element *)element, - private->htmlc); - break; - } - - exc = dom_node_get_next_sibling(element, &next_node); - dom_node_unref(element); - if (exc == DOM_NO_ERR) { - element = next_node; - } else { - element = NULL; - } - - } - - - %} - -getter lastElementChild %{ - dom_node *element; - dom_exception exc; - dom_node_type node_type; - dom_node *sib_node; - - exc = dom_node_get_last_child(private->node, &element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - while (element != NULL) { - exc = dom_node_get_node_type(element, &node_type); - if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) { - /* found it */ - jsret = jsapi_new_HTMLElement(cx, - NULL, - NULL, - (dom_element *)element, - private->htmlc); - break; - } - - exc = dom_node_get_previous_sibling(element, &sib_node); - dom_node_unref(element); - if (exc == DOM_NO_ERR) { - element = sib_node; - } else { - element = NULL; - } - - } - %} - -getter previousElementSibling %{ - dom_node *element; - dom_exception exc; - dom_node_type node_type; - dom_node *sib_node; - - exc = dom_node_get_previous_sibling(private->node, &element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - while (element != NULL) { - exc = dom_node_get_node_type(element, &node_type); - if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) { - /* found it */ - jsret = jsapi_new_HTMLElement(cx, - NULL, - NULL, - (dom_element *)element, - private->htmlc); - break; - } - - exc = dom_node_get_previous_sibling(element, &sib_node); - dom_node_unref(element); - if (exc == DOM_NO_ERR) { - element = sib_node; - } else { - element = NULL; - } - } -%} - -getter nextElementSibling %{ - dom_node *element; - dom_exception exc; - dom_node_type node_type; - dom_node *sib_node; - - exc = dom_node_get_next_sibling(private->node, &element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - while (element != NULL) { - exc = dom_node_get_node_type(element, &node_type); - if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) { - /* found it */ - jsret = jsapi_new_HTMLElement(cx, - NULL, - NULL, - (dom_element *)element, - private->htmlc); - break; - } - - exc = dom_node_get_next_sibling(element, &sib_node); - dom_node_unref(element); - if (exc == DOM_NO_ERR) { - element = sib_node; - } else { - element = NULL; - } - } -%} - -getter childElementCount %{ - dom_node *element; - dom_exception exc; - dom_node_type node_type; - dom_node *next_node; - - exc = dom_node_get_first_child(private->node, &element); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } - - while (element != NULL) { - exc = dom_node_get_node_type(element, &node_type); - if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) { - jsret += 1; - } - - exc = dom_node_get_next_sibling(element, &next_node); - dom_node_unref(element); - if (exc == DOM_NO_ERR) { - element = next_node; - } else { - element = NULL; - } - } -%} - -getter EventHandler %{ - JSLOG("propname[%d].name=\"%s\"", - tinyid, - jsclass_properties[tinyid].name); -%} - - -setter EventHandler %{ - dom_string *event_type_dom; - - JSLOG("propname[%d].name=\"%s\"", - tinyid, - jsclass_properties[tinyid].name); - - switch (tinyid) { - case JSAPI_PROP_TINYID_onabort: - event_type_dom = corestring_dom_abort; - break; - - case JSAPI_PROP_TINYID_onblur: - event_type_dom = corestring_dom_blur; - break; - - case JSAPI_PROP_TINYID_oncancel: - event_type_dom = corestring_dom_cancel; - break; - - case JSAPI_PROP_TINYID_oncanplay: - event_type_dom = corestring_dom_canplay; - break; - - case JSAPI_PROP_TINYID_oncanplaythrough: - event_type_dom = corestring_dom_canplaythrough; - break; - - case JSAPI_PROP_TINYID_onchange: - event_type_dom = corestring_dom_change; - break; - - case JSAPI_PROP_TINYID_onclick: - event_type_dom = corestring_dom_click; - break; - - case JSAPI_PROP_TINYID_onclose: - event_type_dom = corestring_dom_close; - break; - - case JSAPI_PROP_TINYID_oncontextmenu: - event_type_dom = corestring_dom_contextmenu; - break; - - case JSAPI_PROP_TINYID_oncuechange: - event_type_dom = corestring_dom_cuechange; - break; - - case JSAPI_PROP_TINYID_ondblclick: - event_type_dom = corestring_dom_dblclick; - break; - - case JSAPI_PROP_TINYID_ondrag: - event_type_dom = corestring_dom_drag; - break; - - case JSAPI_PROP_TINYID_ondragend: - event_type_dom = corestring_dom_dragend; - break; - - case JSAPI_PROP_TINYID_ondragenter: - event_type_dom = corestring_dom_dragenter; - break; - - case JSAPI_PROP_TINYID_ondragleave: - event_type_dom = corestring_dom_dragleave; - break; - - case JSAPI_PROP_TINYID_ondragover: - event_type_dom = corestring_dom_dragover; - break; - - case JSAPI_PROP_TINYID_ondragstart: - event_type_dom = corestring_dom_dragstart; - break; - - case JSAPI_PROP_TINYID_ondrop: - event_type_dom = corestring_dom_drop; - break; - - case JSAPI_PROP_TINYID_ondurationchange: - event_type_dom = corestring_dom_durationchange; - break; - - case JSAPI_PROP_TINYID_onemptied: - event_type_dom = corestring_dom_emptied; - break; - - case JSAPI_PROP_TINYID_onended: - event_type_dom = corestring_dom_ended; - break; - - case JSAPI_PROP_TINYID_onerror: - event_type_dom = corestring_dom_error; - break; - - case JSAPI_PROP_TINYID_onfocus: - event_type_dom = corestring_dom_focus; - break; - - case JSAPI_PROP_TINYID_oninput: - event_type_dom = corestring_dom_input; - break; - - case JSAPI_PROP_TINYID_oninvalid: - event_type_dom = corestring_dom_invalid; - break; - - case JSAPI_PROP_TINYID_onkeydown: - event_type_dom = corestring_dom_keydown; - break; - - case JSAPI_PROP_TINYID_onkeypress: - event_type_dom = corestring_dom_keypress; - break; - - case JSAPI_PROP_TINYID_onkeyup: - event_type_dom = corestring_dom_keyup; - break; - - case JSAPI_PROP_TINYID_onload: - event_type_dom = corestring_dom_load; - break; - - case JSAPI_PROP_TINYID_onloadeddata: - event_type_dom = corestring_dom_loadeddata; - break; - - case JSAPI_PROP_TINYID_onloadedmetadata: - event_type_dom = corestring_dom_loadedmetadata; - break; - - case JSAPI_PROP_TINYID_onloadstart: - event_type_dom = corestring_dom_loadstart; - break; - - case JSAPI_PROP_TINYID_onmousedown: - event_type_dom = corestring_dom_mousedown; - break; - - case JSAPI_PROP_TINYID_onmousemove: - event_type_dom = corestring_dom_mousemove; - break; - - case JSAPI_PROP_TINYID_onmouseout: - event_type_dom = corestring_dom_mouseout; - break; - - case JSAPI_PROP_TINYID_onmouseover: - event_type_dom = corestring_dom_mouseover; - break; - - case JSAPI_PROP_TINYID_onmouseup: - event_type_dom = corestring_dom_mouseup; - break; - - case JSAPI_PROP_TINYID_onmousewheel: - event_type_dom = corestring_dom_mousewheel; - break; - - case JSAPI_PROP_TINYID_onpause: - event_type_dom = corestring_dom_pause; - break; - - case JSAPI_PROP_TINYID_onplay: - event_type_dom = corestring_dom_play; - break; - - case JSAPI_PROP_TINYID_onplaying: - event_type_dom = corestring_dom_playing; - break; - - case JSAPI_PROP_TINYID_onprogress: - event_type_dom = corestring_dom_progress; - break; - - case JSAPI_PROP_TINYID_onratechange: - event_type_dom = corestring_dom_ratechange; - break; - - case JSAPI_PROP_TINYID_onreset: - event_type_dom = corestring_dom_reset; - break; - - case JSAPI_PROP_TINYID_onscroll: - event_type_dom = corestring_dom_scroll; - break; - - case JSAPI_PROP_TINYID_onseeked: - event_type_dom = corestring_dom_seeked; - break; - - case JSAPI_PROP_TINYID_onseeking: - event_type_dom = corestring_dom_seeking; - break; - - case JSAPI_PROP_TINYID_onselect: - event_type_dom = corestring_dom_select; - break; - - case JSAPI_PROP_TINYID_onshow: - event_type_dom = corestring_dom_show; - break; - - case JSAPI_PROP_TINYID_onstalled: - event_type_dom = corestring_dom_stalled; - break; - - case JSAPI_PROP_TINYID_onsubmit: - event_type_dom = corestring_dom_submit; - break; - - case JSAPI_PROP_TINYID_onsuspend: - event_type_dom = corestring_dom_suspend; - break; - - case JSAPI_PROP_TINYID_ontimeupdate: - event_type_dom = corestring_dom_timeupdate; - break; - - case JSAPI_PROP_TINYID_onvolumechange: - event_type_dom = corestring_dom_volumechange; - break; - - case JSAPI_PROP_TINYID_onwaiting: - event_type_dom = corestring_dom_waiting; - break; - - default: - JSLOG("called with unknown tinyid"); - return JS_TRUE; - } - - js_dom_event_add_listener((struct jscontext *)cx, - private->htmlc->document, - (dom_node *)private->node, - event_type_dom, - vp); -%} diff --git a/javascript/jsapi/jsapi.c b/javascript/jsapi/jsapi.c deleted file mode 100644 index 8724d9be8..000000000 --- a/javascript/jsapi/jsapi.c +++ /dev/null @@ -1,613 +0,0 @@ -/* - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * 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 <unistd.h> -#include <signal.h> - -#include "javascript/jsapi.h" -#include "render/html_internal.h" -#include "content/content.h" -#include "javascript/content.h" -#include "javascript/js.h" - -#include "utils/log.h" - -#include "window.h" -#include "event.h" - -#define ENABLE_JS_HEARTBEAT 1 - -static JSRuntime *rt; /* global runtime */ - -void js_initialise(void) -{ - /* Create a JS runtime. */ - -#if JS_VERSION >= 180 - JS_SetCStringsAreUTF8(); /* we prefer our runtime to be utf-8 */ -#endif - - rt = JS_NewRuntime(8L * 1024L * 1024L); - JSLOG("New runtime handle %p", rt); - - if (rt != NULL) { - /* register script content handler */ - javascript_init(); - } -} - -void js_finalise(void) -{ - if (rt != NULL) { - JSLOG("destroying runtime handle %p", rt); - JS_DestroyRuntime(rt); - } - JS_ShutDown(); -} - -/* The error reporter callback. */ -static void -js_reportError(JSContext *cx, const char *message, JSErrorReport *report) -{ - JSLOG("%s:%u:%s", - report->filename ? report->filename : "<no filename>", - (unsigned int) report->lineno, - message); -} - -/* heartbeat routines */ -#ifndef ENABLE_JS_HEARTBEAT - -struct heartbeat; - -/* prepares a context with a heartbeat handler */ -static bool -setup_heartbeat(JSContext *cx, int timeout, jscallback *cb, void *cbctx) -{ - return true; -} - -/* enables the heartbeat on a context */ -static struct heartbeat *enable_heartbeat(JSContext *cx) -{ - return NULL; -} - -/* disables heartbeat on a context */ -static bool -disable_heartbeat(struct heartbeat *hb) -{ - return true; -} - -#else - -/* private context for heartbeats */ -struct jscontext_priv { - int timeout; - jscallback *cb; - void *cbctx; - - unsigned int branch_reset; /**< reset value for branch counter */ - unsigned int branch_count; /**< counter for branch callback */ - time_t last; /**< last time heartbeat happened */ - time_t end; /**< end time for the current script execution */ -}; - -/** execution heartbeat */ -static JSBool heartbeat_callback(JSContext *cx) -{ - struct jscontext_priv *priv = JS_GetContextPrivate(cx); - JSBool ret = JS_TRUE; - time_t now = time(NULL); - - /* dynamically update the branch times to ensure we do not get - * called back more than once a second - */ - if (now == priv->last) { - priv->branch_reset = priv->branch_reset * 2; - } - priv->last = now; - - JSLOG("Running heatbeat at %ld end %ld", (long)now, (long)priv->end); - - if ((priv->cb != NULL) && - (now > priv->end)) { - if (priv->cb(priv->cbctx) == false) { - ret = JS_FALSE; /* abort */ - } else { - priv->end = time(NULL) + priv->timeout; - } - } - - return ret; -} - -#if JS_VERSION >= 180 - -struct heartbeat { - JSContext *cx; - struct sigaction sact; /* signal handler action to restore */ - int alm; /* alarm value to restore */ -}; - -static struct heartbeat *cur_hb; - -static bool -setup_heartbeat(JSContext *cx, int timeout, jscallback *cb, void *cbctx) -{ - struct jscontext_priv *priv; - - if (timeout == 0) { - return true; - } - - priv = calloc(1, sizeof(*priv)); - if (priv == NULL) { - return false; - } - - priv->timeout = timeout; - priv->cb = cb; - priv->cbctx = cbctx; - - JS_SetContextPrivate(cx, priv); - - /* if heartbeat is enabled disable JIT or callbacks do not happen */ - JS_SetOptions(cx, JS_GetOptions(cx) & ~JSOPTION_JIT); - - JS_SetOperationCallback(cx, heartbeat_callback); - - return true; -} - -static void sig_alm_handler(int signum) -{ - JS_TriggerOperationCallback(cur_hb->cx); - alarm(1); - JSDBG("alarm signal handler for context %p", cur_hb->cx); -} - -static struct heartbeat *enable_heartbeat(JSContext *cx) -{ - struct jscontext_priv *priv = JS_GetContextPrivate(cx); - struct sigaction sact; - struct heartbeat *hb; - - if (priv == NULL) { - return NULL; - } - - priv->last = time(NULL); - priv->end = priv->last + priv->timeout; - - hb = malloc(sizeof(*hb)); - if (hb != NULL) { - sigemptyset(&sact.sa_mask); - sact.sa_flags = 0; - sact.sa_handler = sig_alm_handler; - if (sigaction(SIGALRM, &sact, &hb->sact) == 0) { - cur_hb = hb; - hb->cx = cx; - hb->alm = alarm(1); - } else { - free(hb); - hb = NULL; - LOG("Unable to set heartbeat"); - } - } - return hb; -} - -/** disable heartbeat - * - * /param hb heartbeat to disable may be NULL - * /return true on success. - */ -static bool -disable_heartbeat(struct heartbeat *hb) -{ - if (hb != NULL) { - sigaction(SIGALRM, &hb->sact, NULL); /* restore old handler */ - alarm(hb->alm); /* restore alarm signal */ - } - return true; -} - -#else - -/* need to setup callback to prevent long running scripts infinite - * hanging. - * - * old method is to use: - * JSBranchCallback JS_SetBranchCallback(JSContext *cx, JSBranchCallback cb); - * which gets called a *lot* and should only do something every 5k calls - * The callback function - * JSBool (*JSBranchCallback)(JSContext *cx, JSScript *script); - * returns JS_TRUE to carry on and JS_FALSE to abort execution - * single thread of execution on the context - * documented in - * https://developer.mozilla.org/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_SetBranchCallback - * - */ - -#define INITIAL_BRANCH_RESET 5000 - -struct heartbeat; - -static JSBool branch_callback(JSContext *cx, JSScript *script) -{ - struct jscontext_priv *priv = JS_GetContextPrivate(cx); - JSBool ret = JS_TRUE; - - priv->branch_count--; - if (priv->branch_count == 0) { - priv->branch_count = priv->branch_reset; /* reset branch count */ - - ret = heartbeat_callback(cx); - } - return ret; -} - -static bool -setup_heartbeat(JSContext *cx, int timeout, jscallback *cb, void *cbctx) -{ - struct jscontext_priv *priv; - - if (timeout == 0) { - return true; - } - - priv = calloc(1, sizeof(*priv)); - if (priv == NULL) { - return false; - } - - priv->timeout = timeout; - priv->cb = cb; - priv->cbctx = cbctx; - - priv->branch_reset = INITIAL_BRANCH_RESET; - priv->branch_count = priv->branch_reset; - - JS_SetContextPrivate(cx, priv); - - JS_SetBranchCallback(cx, branch_callback); - - return true; -} - -static struct heartbeat *enable_heartbeat(JSContext *cx) -{ - struct jscontext_priv *priv = JS_GetContextPrivate(cx); - - if (priv != NULL) { - priv->last = time(NULL); - priv->end = priv->last + priv->timeout; - } - return NULL; -} - -static bool -disable_heartbeat(struct heartbeat *hb) -{ - return true; -} - -#endif - -#endif - -nserror js_newcontext(int timeout, jscallback *cb, void *cbctx, - jscontext **jsctx) -{ - JSContext *cx; - *jsctx = NULL; - - if (rt == NULL) { - return NSERROR_OK; - } - - cx = JS_NewContext(rt, 8192); - if (cx == NULL) { - return NSERROR_NOMEM; - } - - /* set options on context */ - JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX | JSOPTION_JIT); - - JS_SetVersion(cx, JSVERSION_LATEST); - JS_SetErrorReporter(cx, js_reportError); - - /* run a heartbeat */ - setup_heartbeat(cx, timeout, cb, cbctx); - - /*JS_SetGCZeal(cx, 2); */ - - JSLOG("New Context %p", cx); - - *jsctx = (jscontext *)cx; - return NSERROR_OK; -} - -void js_destroycontext(jscontext *ctx) -{ - JSContext *cx = (JSContext *)ctx; - struct jscontext_priv *priv; - - if (cx != NULL) { - JSLOG("Destroying Context %p", cx); - priv = JS_GetContextPrivate(cx); - - JS_DestroyContext(cx); - - free(priv); - } -} - - -/** Create new compartment to run scripts within - * - * This performs the following actions - * 1. constructs a new global object by initialising a window class - * 2. Instantiate the global a window object - */ -jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv) -{ - JSContext *cx = (JSContext *)ctx; - JSObject *window_proto; - JSObject *window; - - if (cx == NULL) { - return NULL; - } - - window_proto = jsapi_InitClass_Window(cx, NULL); - if (window_proto == NULL) { - JSLOG("Unable to initialise window class"); - return NULL; - } - - window = jsapi_new_Window(cx, window_proto, NULL, win_priv, doc_priv); - - return (jsobject *)window; -} - - - -bool js_exec(jscontext *ctx, const char *txt, size_t txtlen) -{ - JSContext *cx = (JSContext *)ctx; - jsval rval; - JSBool eval_res; - struct heartbeat *hb; - - /* JSLOG("%p \"%s\"",cx ,txt); */ - - if (ctx == NULL) { - return false; - } - - if (txt == NULL) { - return false; - } - - if (txtlen == 0) { - return false; - } - - hb = enable_heartbeat(cx); - - eval_res = JS_EvaluateScript(cx, - JS_GetGlobalObject(cx), - txt, txtlen, - "<head>", 0, &rval); - - disable_heartbeat(hb); - - if (eval_res == JS_TRUE) { - - return true; - } - - return false; -} - -dom_exception _dom_event_create(dom_document *doc, dom_event **evt); -#define dom_event_create(d, e) _dom_event_create((dom_document *)(d), (dom_event **) (e)) - -bool js_fire_event(jscontext *ctx, const char *type, dom_document *doc, dom_node *target) -{ - JSContext *cx = (JSContext *)ctx; - dom_node *node = target; - JSObject *jsevent; - jsval rval; - jsval argv[1]; - JSBool ret = JS_TRUE; - dom_exception exc; - dom_event *event; - dom_string *type_dom; - struct heartbeat *hb; - - if (cx == NULL) { - return false; - } - - if (node == NULL) { - /* deliver manufactured event to window */ - JSLOG("Dispatching event %s at window", type); - - /* create and initialise and event object */ - exc = dom_string_create((unsigned char*)type, - strlen(type), - &type_dom); - if (exc != DOM_NO_ERR) { - return false; - } - - exc = dom_event_create(doc, &event); - if (exc != DOM_NO_ERR) { - return false; - } - - exc = dom_event_init(event, type_dom, false, false); - dom_string_unref(type_dom); - if (exc != DOM_NO_ERR) { - return false; - } - - jsevent = jsapi_new_Event(cx, NULL, NULL, event); - if (jsevent == NULL) { - return false; - } - - hb = enable_heartbeat(cx); - - /* dispatch event at the window object */ - argv[0] = OBJECT_TO_JSVAL(jsevent); - - ret = JS_CallFunctionName(cx, - JS_GetGlobalObject(cx), - "dispatchEvent", - 1, - argv, - &rval); - - disable_heartbeat(hb); - - } else { - JSLOG("Dispatching event %s at %p", type, node); - - /* create and initialise and event object */ - exc = dom_string_create((unsigned char*)type, - strlen(type), - &type_dom); - if (exc != DOM_NO_ERR) { - return false; - } - - exc = dom_event_create(doc, &event); - if (exc != DOM_NO_ERR) { - return false; - } - - exc = dom_event_init(event, type_dom, true, true); - dom_string_unref(type_dom); - if (exc != DOM_NO_ERR) { - return false; - } - - dom_event_target_dispatch_event(node, event, &ret); - - } - - if (ret == JS_TRUE) { - return true; - } - return false; -} - -struct js_dom_event_private { - JSContext *cx; /* javascript context */ - jsval funcval; /* javascript function to call */ - struct dom_node *node; /* dom node event listening on */ - dom_string *type; /* event type */ - dom_event_listener *listener; /* the listener containing this */ -}; - -static void -js_dom_event_listener(struct dom_event *event, void *pw) -{ - struct js_dom_event_private *private = pw; - jsval event_argv[1]; - jsval event_rval; - JSObject *jsevent; - - JSLOG("WOOT dom event with %p", private); - - if (!JSVAL_IS_VOID(private->funcval)) { - jsevent = jsapi_new_Event(private->cx, NULL, NULL, event); - if (jsevent != NULL) { - - /* dispatch event at the window object */ - event_argv[0] = OBJECT_TO_JSVAL(jsevent); - - JS_CallFunctionValue(private->cx, - NULL, - private->funcval, - 1, - event_argv, - &event_rval); - } - } -} - -/* add a listener to a dom node - * - * 1. Create a dom_event_listener From a handle_event function pointer - * and a private word In a document context - * - * 2. Register for your events on a target (dom nodes are targets) - * dom_event_target_add_event_listener(node, evt_name, listener, - * capture_or_not) - * - */ - -bool -js_dom_event_add_listener(jscontext *ctx, - struct dom_document *document, - struct dom_node *node, - struct dom_string *event_type_dom, - void *js_funcval) -{ - JSContext *cx = (JSContext *)ctx; - dom_exception exc; - struct js_dom_event_private *private; - - private = malloc(sizeof(struct js_dom_event_private)); - if (private == NULL) { - return false; - } - - exc = dom_event_listener_create(document, - js_dom_event_listener, - private, - &private->listener); - if (exc != DOM_NO_ERR) { - return false; - } - - private->cx = cx; - private->funcval = *(jsval *)js_funcval; - private->node = node; - private->type = event_type_dom; - - JSLOG("adding %p to listener", private); - - JSAPI_ADD_VALUE_ROOT(cx, &private->funcval); - exc = dom_event_target_add_event_listener(private->node, - private->type, - private->listener, - true); - if (exc != DOM_NO_ERR) { - JSLOG("failed to add listener"); - JSAPI_REMOVE_VALUE_ROOT(cx, &private->funcval); - } - - return true; -} diff --git a/javascript/jsapi/jsapi.h b/javascript/jsapi/jsapi.h deleted file mode 100644 index 7ca8351d6..000000000 --- a/javascript/jsapi/jsapi.h +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * 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 - * spidermonkey jsapi compatability glue. - */ - -#ifndef _NETSURF_JAVASCRIPT_JSAPI_H_ -#define _NETSURF_JAVASCRIPT_JSAPI_H_ - -/* include the correct header */ -#ifdef WITH_MOZJS -#include "js/jsapi.h" -#else -#include "mozjs/jsapi.h" -#endif - -/* logging macros */ -#define JSLOG(args...) LOG(args) -#ifdef ENABLE_VERBOSE_JS_DEBUG -#define JSDBG(args...) LOG(args) -#else -#define JSDBG(args...) -#endif - -#if JS_VERSION < 180 - -/************************** Spidermonkey 1.7.0 **************************/ - -#include <string.h> - -#ifndef JSVERSION_LATEST -#define JSVERSION_LATEST JS_VERSION -#endif - -#ifndef JSOPTION_JIT -#define JSOPTION_JIT 0 -#endif - -/* *CAUTION* these native function macros introduce and use jsapi_this - * and jsapi_rval variables, native function code should not conflict - * with these - */ - -/* native function definition with five parameters */ -#define JSAPI_FUNC(name, cx, argc, vp) \ - jsapi_func_##name(cx, JSObject *jsapi_this, argc, vp, jsval *jsapi_rval) - -/* native function return value - No macro available */ -#define JSAPI_FUNC_RVAL(cx, vp) (jsapi_rval) - -/* native function return value setter - No macro available */ -#define JSAPI_FUNC_SET_RVAL(cx, vp, v) (*jsapi_rval = (v)) - -/* arguments */ -#define JSAPI_FUNC_ARGV(cx, vp) (vp) - -/* check if a jsval is an object */ -#define JSAPI_JSVAL_IS_OBJECT(v) JSVAL_IS_OBJECT(v) - -/* native function specifier with five parameters and no JS_FS macro */ -#define JSAPI_FS(name, nargs, flags) \ - { #name, jsapi_func_##name, nargs, flags, 0 } - -/* native function specifier list end */ -#define JSAPI_FS_END { NULL, NULL, 0, 0, 0 } - - - - -/* native proprty definition */ -#define JSAPI_PROP(name, cx, obj, vp) \ - jsapi_property_##name(cx, obj, jsval jsapi_id, vp) -#define JSAPI_STRICTPROP JSAPI_PROP - -/* native property return value */ -#define JSAPI_PROP_RVAL(cx, vp) (*(vp)) - -/* native property getter return value */ -#define JSAPI_PROP_SET_RVAL(cx, vp, v) (*(vp) = (v)) - -/* native property ID value as a jsval */ -#define JSAPI_PROP_IDVAL(cx, vp) (*(vp) = jsapi_id) - -/* native property specifier */ -#define JSAPI_PS(name, fnname, tinyid, flags) \ - { name , tinyid , flags , jsapi_property_##fnname##_get , jsapi_property_##fnname##_set } - -/* native property specifier with no setter */ -#define JSAPI_PS_RO(name, fnname, tinyid, flags) \ - { name , tinyid , flags | JSPROP_READONLY, jsapi_property_##fnname##_get , NULL } - -/* native property specifier list end */ -#define JSAPI_PS_END { NULL, 0, 0, NULL, NULL } - -#define JS_StrictPropertyStub JS_PropertyStub - - - - -/* The object instance in a native call */ -/* "this" JSObject getter */ -JSObject * js_ComputeThis(JSContext *cx, JSObject *thisp, void *argv); -#define JSAPI_THIS_OBJECT(cx, vp) \ - js_ComputeThis(cx, JSVAL_TO_OBJECT(vp[-1]), vp) - -static inline JSObject * -JS_NewCompartmentAndGlobalObject(JSContext *cx, - JSClass *jsclass, - JSPrincipals *principals) -{ - JSObject *global; - global = JS_NewObject(cx, jsclass, NULL, NULL); - if (global == NULL) { - return NULL; - } - return global; -} - - -#define JSString_to_char(injsstring, outchar, outlen) \ - outchar = JS_GetStringBytes(injsstring); \ - outlen = strlen(outchar) - -/* string type cast */ -#define JSAPI_STRING_TO_JSVAL(str) ((str == NULL)?JSVAL_NULL:STRING_TO_JSVAL(str)) - -#define JSAPI_CLASS_NO_INTERNAL_MEMBERS NULL - -/* Garbage Collector */ - -/* macros for GC marking */ -#define JSAPI_JSCLASS_MARK_IS_TRACE 0 - -#define JSAPI_JSCLASS_MARKOP(x) (x) - -#define JSAPI_MARKOP(name) uint32_t name(JSContext *cx, JSObject *obj, void *arg) - -#define JSAPI_MARKCX cx - -#define JSAPI_GCMARK(thing) JS_MarkGCThing(cx, thing, "object", arg) - -#define JSAPI_MARKOP_RETURN(value) return value - - -/* Macros for manipulating GC root */ -#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj) -#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj) - -#define JSAPI_ADD_VALUE_ROOT(cx, obj) JS_AddRoot(cx, obj) -#define JSAPI_REMOVE_VALUE_ROOT(cx, obj) JS_RemoveRoot(cx, obj) - -#elif JS_VERSION == 180 - -/************************** Spidermonkey 1.8.0 **************************/ - -#include <string.h> - -/* *CAUTION* these macros introduce and use jsapi_this and jsapi_rval - * parameters, native function code should not conflict with these - */ - -/* five parameter jsapi native call */ -#define JSAPI_FUNC(name, cx, argc, vp) \ - jsapi_func_##name(cx, JSObject *jsapi_this, argc, vp, jsval *jsapi_rval) - -/* five parameter function descriptor */ -#define JSAPI_FS(name, nargs, flags) \ - JS_FS(#name, jsapi_func_##name, nargs, flags, 0) - -/* function descriptor end */ -#define JSAPI_FS_END JS_FS_END - -/* return value */ -#define JSAPI_RVAL(cx, vp) JS_RVAL(cx, jsapi_rval) - -/* return value setter */ -#define JSAPI_FUNC_SET_RVAL(cx, vp, v) JS_SET_RVAL(cx, jsapi_rval, v) - -/* arguments */ -#define JSAPI_FUNC_ARGV(cx, vp) (vp) - -/* check if a jsval is an object */ -#define JSAPI_JSVAL_IS_OBJECT(v) JSVAL_IS_OBJECT(v) - -/* The object instance in a native call */ -#define JSAPI_THIS_OBJECT(cx,vp) jsapi_this - - - -/* proprty native calls */ -#define JSAPI_PROP(name, cx, obj, vp) \ - jsapi_property_##name(cx, obj, jsval jsapi_id, vp) -#define JSAPI_STRICTPROP JSAPI_PROP - -/* native property return value */ -#define JSAPI_PROP_RVAL JS_RVAL - -/* native property return value setter */ -#define JSAPI_PROP_SET_RVAL JS_SET_RVAL - -/* native property ID value as a jsval */ -#define JSAPI_PROP_IDVAL(cx, vp) (*(vp) = jsapi_id) - -/* property specifier */ -#define JSAPI_PS(name, fnname, tinyid, flags) \ - { name , tinyid , flags , jsapi_property_##fnname##_get , jsapi_property_##fnname##_set } - -#define JSAPI_PS_RO(name, fnname, tinyid, flags) \ - { name , tinyid , flags | JSPROP_READONLY, jsapi_property_##fnname##_get , NULL } - -#define JSAPI_PS_END { NULL, 0, 0, NULL, NULL } - - - - -static inline JSObject * -JS_NewCompartmentAndGlobalObject(JSContext *cx, - JSClass *jsclass, - JSPrincipals *principals) -{ - JSObject *global; - global = JS_NewObject(cx, jsclass, NULL, NULL); - if (global == NULL) { - return NULL; - } - return global; -} - -#define JS_StrictPropertyStub JS_PropertyStub - -#define JSString_to_char(injsstring, outchar, outlen) \ - outchar = JS_GetStringBytes(injsstring); \ - outlen = strlen(outchar) - -/* string type cast */ -#define JSAPI_STRING_TO_JSVAL(str) ((str == NULL)?JSVAL_NULL:STRING_TO_JSVAL(str)) - -#define JSAPI_CLASS_NO_INTERNAL_MEMBERS NULL - -/* Garbage Collector */ - -/* GC marking */ -#ifdef JSCLASS_MARK_IS_TRACE -/* mark function pointer requires casting */ -#define JSAPI_JSCLASS_MARK_IS_TRACE JSCLASS_MARK_IS_TRACE -#define JSAPI_JSCLASS_MARKOP(x) ((JSMarkOp)x) -#else -/* mark function pointer does not require casting */ -#define JSAPI_JSCLASS_MARK_IS_TRACE 0 -#define JSAPI_JSCLASS_MARKOP(x) (x) -#endif - -#define JSAPI_MARKOP(name) JSBool name(JSTracer *trc, JSObject *obj) - -#define JSAPI_MARKCX trc->context - -#define JSAPI_GCMARK(thing) JS_CallTracer(trc, thing, JSTRACE_OBJECT); - -#define JSAPI_MARKOP_RETURN(value) return value - -/* Macros for manipulating GC root */ -#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj) -#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj) - -#define JSAPI_ADD_VALUE_ROOT(cx, obj) JS_AddRoot(cx, obj) -#define JSAPI_REMOVE_VALUE_ROOT(cx, obj) JS_RemoveRoot(cx, obj) - - -#else /* #if JS_VERSION == 180 */ - -/************************** Spidermonkey 1.8.5 **************************/ - -/* three parameter jsapi native call */ -#define JSAPI_FUNC(name, cx, argc, vp) jsapi_func_##name(cx, argc, vp) - -/* three parameter function descriptor */ -#define JSAPI_FS(name, nargs, flags) \ - JS_FS(#name, jsapi_func_##name, nargs, flags) - -/* function descriptor end */ -#define JSAPI_FS_END JS_FS_END - -/* return value */ -#define JSAPI_RVAL JS_RVAL - -/* return value setter */ -#define JSAPI_FUNC_SET_RVAL JS_SET_RVAL - -/* arguments */ -#define JSAPI_FUNC_ARGV(cx, vp) JS_ARGV(cx,vp) - -/* check if a jsval is an object */ -#define JSAPI_JSVAL_IS_OBJECT(v) JSVAL_IS_OBJECT(v) -/* The docuemntation says this is obsolete and should be - * ((JSVAL_IS_NULL(v)) || (JSVAL_IS_PRIMITIVE(v))) - * which doesnt work - */ - - -/* The object instance in a native call */ -#define JSAPI_THIS_OBJECT(cx,vp) JS_THIS_OBJECT(cx,vp) - -/* proprty native calls */ -#define JSAPI_PROP(name, cx, obj, vp) \ - jsapi_property_##name(cx, obj, jsid jsapi_id, vp) -#define JSAPI_STRICTPROP(name, cx, obj, vp) \ - jsapi_property_##name(cx, obj, jsid jsapi_id, JSBool strict, vp) - -/* native property return value */ -#define JSAPI_PROP_RVAL JS_RVAL - -/* native property getter return value */ -#define JSAPI_PROP_SET_RVAL JS_SET_RVAL - -/* native property ID value as a jsval */ -#define JSAPI_PROP_IDVAL(cx, vp) JS_IdToValue(cx, jsapi_id, vp) - -/* property specifier */ -#define JSAPI_PS(name, fnname, tinyid, flags) { \ - name, \ - tinyid, \ - flags, \ - jsapi_property_##fnname##_get, \ - jsapi_property_##fnname##_set \ - } - -#define JSAPI_PS_RO(name, fnname, tinyid, flags) { \ - name, \ - tinyid, \ - flags | JSPROP_READONLY, \ - jsapi_property_##fnname##_get, \ - NULL \ - } - -#define JSAPI_PS_END { NULL, 0, 0, NULL, NULL } - - -#define JSString_to_char(injsstring, outchar, outlen) \ - outlen = JS_GetStringLength(injsstring); \ - outchar = alloca(sizeof(char)*(outlen+1)); \ - JS_EncodeStringToBuffer(injsstring, outchar, outlen); \ - outchar[outlen] = '\0' - -/* string type cast */ -#define JSAPI_STRING_TO_JSVAL(str) ((str == NULL)?JSVAL_NULL:STRING_TO_JSVAL(str)) - -#define JSAPI_CLASS_NO_INTERNAL_MEMBERS JSCLASS_NO_INTERNAL_MEMBERS - -/* GC marking */ -#ifdef JSCLASS_MARK_IS_TRACE -/* mark function pointer requires casting */ -#define JSAPI_JSCLASS_MARK_IS_TRACE JSCLASS_MARK_IS_TRACE -#define JSAPI_JSCLASS_MARKOP(x) ((JSMarkOp)x) -#else -/* mark function pointer does not require casting */ -#define JSAPI_JSCLASS_MARK_IS_TRACE 0 -#define JSAPI_JSCLASS_MARKOP(x) (x) -#endif - -#define JSAPI_MARKOP(name) void name(JSTracer *trc, JSObject *obj) - -#define JSAPI_MARKCX trc->context - -#define JSAPI_GCMARK(thing) JS_CallTracer(trc, thing, JSTRACE_OBJECT); - -#define JSAPI_MARKOP_RETURN(value) - - -/* Macros for manipulating GC root */ -#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddObjectRoot(cx, obj) -#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveObjectRoot(cx, obj) - -#define JSAPI_ADD_VALUE_ROOT(cx, val) JS_AddValueRoot(cx, val) -#define JSAPI_REMOVE_VALUE_ROOT(cx, val) JS_RemoveValueRoot(cx, val) - -#endif - -/************************** **************************/ - -#endif diff --git a/javascript/jsapi/location.bnd b/javascript/jsapi/location.bnd deleted file mode 100644 index 96c0a30d5..000000000 --- a/javascript/jsapi/location.bnd +++ /dev/null @@ -1,224 +0,0 @@ -/* Binding to generate Location interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -webidlfile "html.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include "netsurf/browser_window.h" - -#include "utils/config.h" -#include "utils/log.h" -#include "javascript/jsapi.h" -#include "render/html_internal.h" - -#include "location.h" - -struct browser_window *jsapi_get_browser_window(JSContext *cx); - -%} - -binding location { - type js_libdom; /* the binding type */ - - interface Location; /* Web IDL interface to generate */ - - private "nsurl *" url; - - property unshared href; - -} - -operation reload %{ - struct browser_window *bw; - bw = jsapi_get_browser_window(cx); - if (bw != NULL) { - browser_window_reload(bw, false); - } else { - JSLOG("failed to get browser context"); - } -%} - -/* void Location::assign(DOMString url); */ -operation assign %{ - nsurl *joined; - struct browser_window *bw; - - bw = jsapi_get_browser_window(cx); - if (bw != NULL) { - nsurl_join(private->url, url, &joined); - browser_window_navigate(bw, - joined, - NULL, - BW_NAVIGATE_HISTORY, - NULL, - NULL, - NULL); - nsurl_unref(joined); - } else { - JSLOG("failed to get browser context"); - } -%} - -/* void Location::replace(DOMString url); */ -operation replace %{ - nsurl *joined; - struct browser_window *bw; - - bw = jsapi_get_browser_window(cx); - if (bw != NULL) { - nsurl_join(private->url, url, &joined); - browser_window_navigate(bw, - joined, - NULL, - BW_NAVIGATE_NONE, - NULL, - NULL, - NULL); - nsurl_unref(joined); - } else { - JSLOG("failed to get browser context"); - } -%} - -getter href %{ - char *url_s = NULL; - size_t url_l; - - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx,vp))) { - /* already created - return it */ - return JS_TRUE; - } - - nsurl_get(private->url, NSURL_COMPLETE, &url_s, &url_l); - if (url_s != NULL) { - jsret = JS_NewStringCopyN(cx, url_s, url_l); - free(url_s); - } -%} - -setter href %{ - JSString *url_jsstr = NULL; - int url_len = 0; - char *url = NULL; - struct browser_window *bw; - nsurl *joined; - - bw = jsapi_get_browser_window(cx); - - if (bw != NULL) { - url_jsstr = JS_ValueToString(cx, *vp); - if (url_jsstr != NULL) { - JSString_to_char(url_jsstr, url, url_len); - - nsurl_join(private->url, url, &joined); - - browser_window_navigate(bw, - joined, - NULL, - BW_NAVIGATE_NONE, - NULL, - NULL, - NULL); - - nsurl_unref(joined); - } else { - JSLOG("failed to convert string value"); - } - } else { - JSLOG("failed to get browser context"); - } -%} - -getter protocol %{ - lwc_string *component; - component = nsurl_get_component(private->url, NSURL_SCHEME); - if (component != NULL) { - jsret = JS_NewStringCopyN(cx, - lwc_string_data(component), - lwc_string_length(component)); - lwc_string_unref(component); - } -%} - -getter host %{ - lwc_string *component; - component = nsurl_get_component(private->url, NSURL_HOST); - if (component != NULL) { - jsret = JS_NewStringCopyN(cx, - lwc_string_data(component), - lwc_string_length(component)); - lwc_string_unref(component); - } -%} - -getter hostname %{ - lwc_string *component; - component = nsurl_get_component(private->url, NSURL_HOST); - if (component != NULL) { - jsret = JS_NewStringCopyN(cx, - lwc_string_data(component), - lwc_string_length(component)); - lwc_string_unref(component); - } - -%} - -getter port %{ - lwc_string *component; - component = nsurl_get_component(private->url, NSURL_PORT); - if (component != NULL) { - jsret = JS_NewStringCopyN(cx, - lwc_string_data(component), - lwc_string_length(component)); - lwc_string_unref(component); - } - -%} - -getter pathname %{ - lwc_string *component; - component = nsurl_get_component(private->url, NSURL_PATH); - if (component != NULL) { - jsret = JS_NewStringCopyN(cx, - lwc_string_data(component), - lwc_string_length(component)); - lwc_string_unref(component); - } - -%} - -getter search %{ - lwc_string *component; - component = nsurl_get_component(private->url, NSURL_QUERY); - if (component != NULL) { - jsret = JS_NewStringCopyN(cx, - lwc_string_data(component), - lwc_string_length(component)); - lwc_string_unref(component); - } - -%} - -getter hash %{ - lwc_string *component; - component = nsurl_get_component(private->url, NSURL_FRAGMENT); - if (component != NULL) { - jsret = JS_NewStringCopyN(cx, - lwc_string_data(component), - lwc_string_length(component)); - lwc_string_unref(component); - } -%} diff --git a/javascript/jsapi/navigator.bnd b/javascript/jsapi/navigator.bnd deleted file mode 100644 index dee2cc23f..000000000 --- a/javascript/jsapi/navigator.bnd +++ /dev/null @@ -1,121 +0,0 @@ -/* Binding to generate Navigator interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - - -webidlfile "html.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <assert.h> -#include <stdlib.h> - -#include "desktop/version.h" -#include "utils/config.h" -#include "utils/nsoption.h" -#include "utils/useragent.h" -#include "utils/log.h" -#include "utils/utsname.h" -#include "javascript/jsapi.h" - -#include "navigator.h" - -/* - * navigator properties for netsurf - * - * Property | Everyone else | NetSurf | Notes - * ------------+-----------------+--------------+------------------------------ - * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless - * | | | constant as everyone returns - * | | | "Mozilla" which is dumb - * ------------+-----------------+--------------+------------------------------ - * appName | "<Browsername>" | "NetSurf" | Browsers named other than - * | | | "Netscape", "Mozilla", - * | | | "Netscape Navigator", - * | | | "Microsoft Internet Explorer" - * | | | often other browser have - * | | | "(compatible with Netscape)" - * | | | append. - * ------------+-----------------+--------------+------------------------------ - * appVersion | "<ver> (<type>)"| "<ver>" | Actually just the version - * | | | number e.g "3.0". - * ------------+-----------------+--------------+------------------------------ - * language | "<lang>" | "<lang>" | The language the frontend is - * | | | configured for - * ------------+-----------------+--------------+------------------------------ - * platform | "<krn> <hw>" | "<krn> <hw>" | Efectively uname -s -i, - * | | | eg "Linux x86_64" - * ------------+-----------------+--------------+------------------------------ - * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string - * | | | with excessive lies - * ------------+-----------------+--------------+------------------------------ - */ - -#define NAVIGATOR_APPNAME "NetSurf" -#define NAVIGATOR_APPCODENAME "NetSurf" -%} - -binding navigator { - type js_libdom; /* the binding type */ - - interface Navigator; /* Web IDL interface to generate */ - -} - -getter appName %{ - jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME); -%} - -getter appCodeName %{ - jsret = JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME); -%} - -getter appVersion %{ - jsret = JS_NewStringCopyZ(cx, netsurf_version); -%} - -getter language %{ - const char *alang = nsoption_charp(accept_language); - - if (alang != NULL) { - jsret = JS_NewStringCopyZ(cx, alang); - } - -%} - -getter platform %{ - struct utsname *cutsname; - - cutsname = malloc(sizeof(struct utsname)); - - if (cutsname != NULL) { - if (uname(cutsname) >= 0) { - char *platstr; - int platstrlen; - - platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2; - platstr = malloc(platstrlen); - if (platstr != NULL) { - snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine); - jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1); - free(platstr); - } - } - free(cutsname); - } -%} - -getter userAgent %{ - jsret = JS_NewStringCopyZ(cx, user_agent_string()); -%} diff --git a/javascript/jsapi/node.bnd b/javascript/jsapi/node.bnd deleted file mode 100644 index 49fd06bc5..000000000 --- a/javascript/jsapi/node.bnd +++ /dev/null @@ -1,35 +0,0 @@ -/* Binding to generate Node interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -webidlfile "dom.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" - -#include "javascript/jsapi.h" - -#include "node.h" - -%} - -binding node { - type js_libdom; /* the binding type */ - - interface Node; /* Web IDL interface to generate */ -} diff --git a/javascript/jsapi/nodelist.bnd b/javascript/jsapi/nodelist.bnd deleted file mode 100644 index 379809659..000000000 --- a/javascript/jsapi/nodelist.bnd +++ /dev/null @@ -1,99 +0,0 @@ -/* Binding to generate NodeList interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - -/* The hdrcomment are added into the geenrated output comment header */ -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "javascript/jsapi.h" -#include "render/html_internal.h" - -#include "nodelist.h" -#include "htmlelement.h" - -%} - -webidlfile "dom.idl"; - -binding nodelist { - type js_libdom; /* the binding type */ - - interface NodeList; /* The WebIDL interface to generate a binding for */ - - private "dom_nodelist *" nodelist; - private "struct html_content *" htmlc; -} - -api finalise %{ - if (private != NULL) { - dom_nodelist_unref(private->nodelist); - } -%} - -/* default handler for numericaly indexed property values */ -api getproperty %{ - jsval queryprop; - int idx; - JSObject *jsret = NULL; /* Node */ - dom_exception err; - dom_node *domnode; - - JSAPI_PROP_IDVAL(cx, &queryprop); - if (JSVAL_IS_INT(queryprop)) { - idx = JSVAL_TO_INT(queryprop); - JSDBG("Index was %d", idx); - - - err = dom_nodelist_item(private->nodelist, idx, &domnode); - if (err != DOM_NO_ERR) { - return JS_FALSE; - } - - if (domnode != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc); - - JSDBG("return object:%p", jsret); - - JSAPI_PROP_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsret)); - } - } -%} - -getter length %{ - dom_exception err; - - err = dom_nodelist_get_length(private->nodelist, &jsret); - if (err != DOM_NO_ERR) { - return JS_FALSE; - } -%} - -operation item %{ - dom_exception err; - dom_node *domnode; - - err = dom_nodelist_item(private->nodelist, index, &domnode); - if (err != DOM_NO_ERR) { - return JS_FALSE; - } - - if (domnode != NULL) { - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, (dom_element *)domnode, private->htmlc); - } -%} - diff --git a/javascript/jsapi/text.bnd b/javascript/jsapi/text.bnd deleted file mode 100644 index eb17a943e..000000000 --- a/javascript/jsapi/text.bnd +++ /dev/null @@ -1,47 +0,0 @@ -/* Binding to generate Text interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - - -webidlfile "html.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "render/html_internal.h" -#include "javascript/jsapi.h" - -#include "text.h" - -%} - -#include "dom.bnd" - -binding text { - type js_libdom; /* the binding type */ - - interface Text; /* Web IDL interface to generate */ - - private "dom_text *" node; - private "struct html_content *" htmlc; -} - -api finalise %{ - if (private != NULL) { - dom_node_unref(private->node); - } -%} diff --git a/javascript/jsapi/window.bnd b/javascript/jsapi/window.bnd deleted file mode 100644 index 0439bc0a1..000000000 --- a/javascript/jsapi/window.bnd +++ /dev/null @@ -1,402 +0,0 @@ -/* Binding to generate window interface - * - * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * Released under the terms of the MIT License, - * http://www.opensource.org/licenses/mit-license - */ - - -webidlfile "html.idl"; -webidlfile "dom.idl"; -webidlfile "console.idl"; - -hdrcomment "Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>"; -hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; -hdrcomment "Released under the terms of the MIT License,"; -hdrcomment " http://www.opensource.org/licenses/mit-license"; - -preamble %{ - -#include <dom/dom.h> - -#include "utils/config.h" -#include "utils/log.h" -#include "utils/corestrings.h" -#include "render/html_internal.h" -#include "javascript/jsapi.h" - -#include "console.h" -#include "navigator.h" -#include "event.h" -#include "node.h" -#include "htmlcollection.h" -#include "nodelist.h" -#include "htmldocument.h" -#include "text.h" -#include "comment.h" -#include "htmlelement.h" -#include "window.h" -#include "location.h" - -struct browser_window *jsapi_get_browser_window(JSContext *cx); - -%} - -prologue %{ - -struct browser_window *jsapi_get_browser_window(JSContext *cx) -{ - struct jsclass_private *private; - - private = JS_GetInstancePrivate(cx, - JS_GetGlobalObject(cx), - &JSClass_Window, - NULL); - if (private != NULL) { - return private->bw; - } - - return NULL; -} - -static bool -init_user_prototypes(JSContext *cx, - struct jsclass_private *private, - JSObject *parent) -{ - /* Initialises all the user javascript classes to make their - * prototypes available. - */ - /** @todo should we be managing these prototype objects ourselves */ - private->prototype_Document = jsapi_InitClass_Document(cx, parent); - if (private->prototype_Document == NULL) { - return false; - } - - private->prototype_Navigator = jsapi_InitClass_Navigator(cx, parent); - if (private->prototype_Navigator == NULL) { - return false; - } - - private->prototype_Location = jsapi_InitClass_Location(cx, parent); - if (private->prototype_Location == NULL) { - return false; - } - - private->prototype_Console = jsapi_InitClass_Console(cx, parent); - if (private->prototype_Console == NULL) { - return false; - } - - private->prototype_HTMLElement = jsapi_InitClass_HTMLElement(cx, parent); - if (private->prototype_HTMLElement == NULL) { - return false; - } - - private->prototype_HTMLCollection = jsapi_InitClass_HTMLCollection(cx, parent); - if (private->prototype_HTMLCollection == NULL) { - return false; - } - - private->prototype_NodeList = jsapi_InitClass_NodeList(cx, parent); - if (private->prototype_NodeList == NULL) { - return false; - } - - private->prototype_Text = jsapi_InitClass_Text(cx, parent); - if (private->prototype_Text == NULL) { - return false; - } - - private->prototype_Comment = jsapi_InitClass_Comment(cx, parent); - if (private->prototype_Comment == NULL) { - return false; - } - - private->prototype_Node = jsapi_InitClass_Node(cx, parent); - if (private->prototype_Node == NULL) { - return false; - } - - private->prototype_Event = jsapi_InitClass_Event(cx, parent); - if (private->prototype_Event == NULL) { - return false; - } - return true; -} - -%} - -binding window { - type js_libdom; /* the binding type */ - - interface Window; /* Web IDL interface to generate */ - - private "struct browser_window *" bw; - private "struct html_content *" htmlc; - - /* prototypes held in this object */ - internal "JSObject *" prototype_Document; - internal "JSObject *" prototype_Navigator; - internal "JSObject *" prototype_Location; - internal "JSObject *" prototype_Console; - internal "JSObject *" prototype_HTMLElement; - internal "JSObject *" prototype_HTMLCollection; - internal "JSObject *" prototype_NodeList; - internal "JSObject *" prototype_Text; - internal "JSObject *" prototype_Comment; - internal "JSObject *" prototype_Node; - internal "JSObject *" prototype_Event; - - /** document instantiated on first use */ - property unshared document; - - /** navigator instantiated on first use */ - property unshared navigator; - - /** console instantiated on first use */ - property unshared console; - - /** location is unshared */ - property unshared location; - - /** @todo instantiate forms, history etc. attributes */ - - /* events through a single interface */ - property unshared type EventHandler; -} - -api mark %{ - - if (private != NULL) { - if (private->prototype_Document != NULL) { - JSAPI_GCMARK(private->prototype_Document); - } - - if (private->prototype_Navigator != NULL) { - JSAPI_GCMARK(private->prototype_Navigator); - } - - if (private->prototype_Location != NULL) { - JSAPI_GCMARK(private->prototype_Location); - } - - if (private->prototype_Console != NULL) { - JSAPI_GCMARK(private->prototype_Console); - } - - if (private->prototype_HTMLElement != NULL) { - JSAPI_GCMARK(private->prototype_HTMLElement); - } - - if (private->prototype_HTMLCollection != NULL) { - JSAPI_GCMARK(private->prototype_HTMLCollection); - } - - if (private->prototype_NodeList != NULL) { - JSAPI_GCMARK(private->prototype_NodeList); - } - - if (private->prototype_Text != NULL) { - JSAPI_GCMARK(private->prototype_Text); - } - - if (private->prototype_Comment != NULL) { - JSAPI_GCMARK(private->prototype_Comment); - } - - if (private->prototype_Node != NULL) { - JSAPI_GCMARK(private->prototype_Node); - } - - if (private->prototype_Event != NULL) { - JSAPI_GCMARK(private->prototype_Event); - } - } -%} - -api global %{ -%} - -api init %{ - prototype = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL); - if (prototype == NULL) { - return NULL; - } - - /** @todo reconsider global object handling. future - * editions of spidermonkey appear to be removing the - * idea of a global so we probably need to handle - * global object references internally - */ - - /* set the contexts global */ - JS_SetGlobalObject(cx, prototype); - - /* Populate the global object with the standard globals, like - * Object and Array. - */ - if (!JS_InitStandardClasses(cx, prototype)) { - return NULL; - } - - /* add functions to prototype */ - if (!JS_DefineFunctions(cx, prototype, jsclass_functions)) { - return NULL; - } - - /* add properties to prototype */ - if (!JS_DefineProperties(cx, prototype, jsclass_properties)) - return NULL; - - /* as the global just got changed, force a GC run */ - JS_GC(cx); -%} - -api new %{ - /* @todo sort out windows that are not globals */ - assert(parent == NULL); - - /* the window object is the global so its prototype *is* the instance */ - newobject = prototype; - - if (init_user_prototypes(cx, private, prototype) == false) { - /* prototype initialisation failed */ - free(private); - return NULL; - } - - LOG("Created new window object %p", newobject); -%} - -getter document %{ - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { - /* already created - return it */ - return JS_TRUE; - } - - /* instantiate the subclasses off the window global */ - jsret = jsapi_new_Document(cx, - NULL, - NULL, - (dom_document *)dom_node_ref(private->htmlc->document), - private->htmlc); -%} - -getter navigator %{ - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { - /* already created - return it */ - return JS_TRUE; - } - - jsret = jsapi_new_Navigator(cx, NULL, NULL); -%} - -getter console %{ - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { - /* already created - return it */ - return JS_TRUE; - } - - jsret = jsapi_new_Console(cx, NULL, NULL); -%} - -operation confirm %{ - warn_user(message, NULL); -%} - -operation alert %{ - warn_user(message, NULL); -%} - -operation prompt %{ - warn_user(message, NULL); -%} - -/* boolean dispatchEvent(Event event); */ -operation dispatchEvent %{ - /* this implementation is unique to the window object as it is - * not a "real" dom node. - */ - - /* caution, this must match the struct generated from event.bnd */ - struct { - dom_event *event; - } *event_private; - dom_string *type_dom = NULL; - dom_exception exc; - jsval eventval = JSVAL_VOID; - jsval event_argv[1]; - jsval event_rval; - - event_private = JS_GetInstancePrivate(cx, event, &JSClass_Event, NULL); - if (event_private->event == NULL) { - /** @todo type error? */ - jsret = JS_FALSE; - } else { - exc = dom_event_get_type(event_private->event, &type_dom); - if (exc == DOM_NO_ERR) { - - if (dom_string_isequal(type_dom, corestring_dom_load)) { - JS_GetProperty(cx, JSAPI_THIS_OBJECT(cx, vp), "onload", &eventval); - } - - if (!JSVAL_IS_VOID(eventval)) { - event_argv[0] = eventval; - jsret = JS_CallFunctionValue(cx, NULL, eventval, 1, event_argv, &event_rval); - } - } - } -%} - -getter location %{ - if (!JSVAL_IS_VOID(JSAPI_PROP_RVAL(cx, vp))) { - /* already created - return it */ - return JS_TRUE; - } - -/* should get the docuemnts location - jsval loc; - JS_GetProperty(cx, private->document, "location", &loc); - jsret = JSVAL_TO_OBJECT(loc); -*/ - - jsret = jsapi_new_Location(cx, - NULL, - NULL, - llcache_handle_get_url(private->htmlc->base.llcache)); -%} - -getter window %{ - jsret = obj; -%} - -getter self %{ - jsret = obj; -%} - -/* very iffy implementation */ -getter top %{ - jsret = obj; -%} - -getter EventHandler %{ - /* this implementation is unique to the window object as it is - * not a dom node. - */ - JSLOG("propname[%d]=\"%s\"", - tinyid, - jsclass_properties[tinyid].name); -%} - -setter EventHandler %{ - /* this implementation is unique to the window object as it is - * not a dom node. - */ - JSLOG("propname[%d]=\"%s\"", - tinyid, - jsclass_properties[tinyid].name); -%} |