Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/135aae3921322afc7241185080e0dfc8a2de4fd4
...commit
http://git.netsurf-browser.org/netsurf.git/commit/135aae3921322afc7241185080e0dfc8a2de4fd4
...tree
http://git.netsurf-browser.org/netsurf.git/tree/135aae3921322afc7241185080e0dfc8a2de4fd4
The branch, master has been updated
via 135aae3921322afc7241185080e0dfc8a2de4fd4 (commit)
from e1b37918e8f6a54d708720c6925e2ef27c0e8119 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commitdiff/135aae3921322afc7241185080e0dfc8a2de4fd4
commit 135aae3921322afc7241185080e0dfc8a2de4fd4
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>
add element object
diff --git a/Makefile.sources b/Makefile.sources
index 95695f7..f7f05ca 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -31,7 +31,7 @@ S_DESKTOP := cookies.c history_global_core.c hotlist.c
knockout.c \
# Javascript sources
ifeq ($(NETSURF_USE_JS),YES)
-S_JSAPI = window.c document.c navigator.c console.c
+S_JSAPI = window.c document.c navigator.c console.c element.c
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
else
S_JAVASCRIPT += none.c
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index a44323f..b23b4d3 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -136,6 +136,9 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
#endif
+typedef struct dom_element dom_element;
+typedef struct html_content html_content;
+
/** Create a new javascript window object
*
* @param cx The javascript context.
@@ -170,4 +173,13 @@ JSObject *jsapi_new_console(JSContext *cx, JSObject
*parent);
*/
JSObject *jsapi_new_navigator(JSContext *cx, JSObject *parent);
+/** Create a new javascript element object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @param doc_priv The private context to set on the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_element(JSContext *cx, JSObject *parent, struct
html_content *htmlc, struct dom_element *domelement);
+
#endif
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index 49144c4..41d8898 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -144,11 +144,7 @@ static JSBool JSAPI_NATIVE(getElementById, JSContext *cx,
uintN argc, jsval *vp)
dom_document_get_element_by_id(htmlc->document, idstr, &idelement);
- if (idelement==NULL) {
- JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
- } else {
- /* create element object and return it*/
- }
+ JSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsapi_new_element(cx,
JS_GetGlobalObject(cx), htmlc, idelement)));
return JS_TRUE;
}
diff --git a/javascript/jsapi/element.c b/javascript/jsapi/element.c
new file mode 100644
index 0000000..11d8b1a
--- /dev/null
+++ b/javascript/jsapi/element.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2012 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dom/dom.h>
+
+
+#include "javascript/jsapi.h"
+#include "utils/config.h"
+#include "render/html_internal.h"
+#include "utils/log.h"
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj);
+
+typedef struct {
+ struct html_content *htmlc;
+ struct dom_element *dom_element;
+} elementp;
+
+static JSClass jsclass_element =
+{
+ "element",
+ JSCLASS_HAS_PRIVATE,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_StrictPropertyStub,
+ JS_EnumerateStub,
+ JS_ResolveStub,
+ JS_ConvertStub,
+ jsfinalize_element,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj)
+{
+ elementp *element;
+ element = JS_GetInstancePrivate(cx, obj, &jsclass_element, NULL);
+ if (element != NULL) {
+ free(element);
+ }
+}
+
+
+
+static JSFunctionSpec jsfunctions_element[] = {
+ JSAPI_FS_END
+};
+
+
+JSObject *
+jsapi_new_element(JSContext *cx,
+ JSObject *parent,
+ struct html_content *htmlc,
+ struct dom_element *domelement)
+{
+ /* create element object and return it*/
+ JSObject *jselement;
+ elementp *element;
+
+ element = malloc(sizeof(element));
+ if (element == NULL) {
+ return NULL;
+ }
+ element->htmlc = htmlc;
+ element->dom_element = domelement;
+
+ jselement = JS_InitClass(cx,
+ parent,
+ NULL,
+ &jsclass_element,
+ NULL,
+ 0,
+ NULL,
+ jsfunctions_element,
+ NULL,
+ NULL);
+ if (jselement == NULL) {
+ free(element);
+ return NULL;
+ }
+
+ LOG(("setting element private to %p", element));
+ /* private pointer to browsing context */
+ if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
+ LOG(("failed to set content"));
+ free(element);
+ return NULL;
+ }
+
+ return jselement;
+}
-----------------------------------------------------------------------
Summary of changes:
Makefile.sources | 2 +-
javascript/jsapi.h | 12 +++++
javascript/jsapi/document.c | 6 +--
javascript/jsapi/element.c | 106 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 120 insertions(+), 6 deletions(-)
create mode 100644 javascript/jsapi/element.c
diff --git a/Makefile.sources b/Makefile.sources
index 95695f7..f7f05ca 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -31,7 +31,7 @@ S_DESKTOP := cookies.c history_global_core.c hotlist.c
knockout.c \
# Javascript sources
ifeq ($(NETSURF_USE_JS),YES)
-S_JSAPI = window.c document.c navigator.c console.c
+S_JSAPI = window.c document.c navigator.c console.c element.c
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
else
S_JAVASCRIPT += none.c
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index a44323f..b23b4d3 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -136,6 +136,9 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
#endif
+typedef struct dom_element dom_element;
+typedef struct html_content html_content;
+
/** Create a new javascript window object
*
* @param cx The javascript context.
@@ -170,4 +173,13 @@ JSObject *jsapi_new_console(JSContext *cx, JSObject
*parent);
*/
JSObject *jsapi_new_navigator(JSContext *cx, JSObject *parent);
+/** Create a new javascript element object
+ *
+ * @param cx The javascript context.
+ * @param parent The parent object, usually a global window object
+ * @param doc_priv The private context to set on the object
+ * @return new javascript object or NULL on error
+ */
+JSObject *jsapi_new_element(JSContext *cx, JSObject *parent, struct
html_content *htmlc, struct dom_element *domelement);
+
#endif
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index 49144c4..41d8898 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -144,11 +144,7 @@ static JSBool JSAPI_NATIVE(getElementById, JSContext *cx,
uintN argc, jsval *vp)
dom_document_get_element_by_id(htmlc->document, idstr, &idelement);
- if (idelement==NULL) {
- JSAPI_SET_RVAL(cx, vp, JSVAL_NULL);
- } else {
- /* create element object and return it*/
- }
+ JSAPI_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsapi_new_element(cx,
JS_GetGlobalObject(cx), htmlc, idelement)));
return JS_TRUE;
}
diff --git a/javascript/jsapi/element.c b/javascript/jsapi/element.c
new file mode 100644
index 0000000..11d8b1a
--- /dev/null
+++ b/javascript/jsapi/element.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2012 Vincent Sanders <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dom/dom.h>
+
+
+#include "javascript/jsapi.h"
+#include "utils/config.h"
+#include "render/html_internal.h"
+#include "utils/log.h"
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj);
+
+typedef struct {
+ struct html_content *htmlc;
+ struct dom_element *dom_element;
+} elementp;
+
+static JSClass jsclass_element =
+{
+ "element",
+ JSCLASS_HAS_PRIVATE,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_StrictPropertyStub,
+ JS_EnumerateStub,
+ JS_ResolveStub,
+ JS_ConvertStub,
+ jsfinalize_element,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+static void jsfinalize_element(JSContext *cx, JSObject *obj)
+{
+ elementp *element;
+ element = JS_GetInstancePrivate(cx, obj, &jsclass_element, NULL);
+ if (element != NULL) {
+ free(element);
+ }
+}
+
+
+
+static JSFunctionSpec jsfunctions_element[] = {
+ JSAPI_FS_END
+};
+
+
+JSObject *
+jsapi_new_element(JSContext *cx,
+ JSObject *parent,
+ struct html_content *htmlc,
+ struct dom_element *domelement)
+{
+ /* create element object and return it*/
+ JSObject *jselement;
+ elementp *element;
+
+ element = malloc(sizeof(element));
+ if (element == NULL) {
+ return NULL;
+ }
+ element->htmlc = htmlc;
+ element->dom_element = domelement;
+
+ jselement = JS_InitClass(cx,
+ parent,
+ NULL,
+ &jsclass_element,
+ NULL,
+ 0,
+ NULL,
+ jsfunctions_element,
+ NULL,
+ NULL);
+ if (jselement == NULL) {
+ free(element);
+ return NULL;
+ }
+
+ LOG(("setting element private to %p", element));
+ /* private pointer to browsing context */
+ if (JS_SetPrivate(cx, jselement, element) != JS_TRUE) {
+ LOG(("failed to set content"));
+ free(element);
+ return NULL;
+ }
+
+ return jselement;
+}
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org