From 71014793667dbaef2ce4c2cc9184cdf2d2bfb6c6 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 24 Jun 2007 11:48:28 +0200 Subject: [PATCH] DOM, ecmascript: Export jsrt. It will be used by DOM. Nothing special else. I have no inspiration to do more. --- src/document/dom/ecmascript/spidermonkey.c | 40 +++++++++++-------- .../spidermonkey/html/HTMLElement.c | 5 ++- .../spidermonkey/html/HTMLElement.h | 2 + .../dom/ecmascript/spidermonkey/html/html.c | 4 +- .../dom/ecmascript/spidermonkey/html/html.h | 4 +- src/dom/Makefile | 1 + src/dom/node.h | 1 + src/ecmascript/spidermonkey.c | 2 +- 8 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/document/dom/ecmascript/spidermonkey.c b/src/document/dom/ecmascript/spidermonkey.c index 3f1570c5..2caa0022 100644 --- a/src/document/dom/ecmascript/spidermonkey.c +++ b/src/document/dom/ecmascript/spidermonkey.c @@ -34,8 +34,12 @@ #include "document/dom/ecmascript/spidermonkey/Text.h" #include "document/dom/ecmascript/spidermonkey/TypeInfo.h" #include "document/dom/ecmascript/spidermonkey/UserDataHandler.h" +#include "document/dom/ecmascript/spidermonkey/html/HTMLElement.h" +#include "document/dom/ecmascript/spidermonkey/html/html.h" #include "dom/node.h" +extern JSRuntime *jsrt; + void done_dom_node_ecmascript_obj(struct dom_node *node) { @@ -45,24 +49,10 @@ done_dom_node_ecmascript_obj(struct dom_node *node) assert(ctx && obj && JS_GetPrivate(ctx, obj) == node); JS_SetPrivate(ctx, obj, NULL); + JS_RemoveRoot(ctx, obj); node->ecmascript_obj = NULL; } -JSObject * -make_new_object(JSContext *ctx, struct dom_node *node) -{ -#if 0 - JSObject *obj = create_new_object[node->data.element.type](ctx); - - if (obj) { - JS_SetPrivate(ctx, obj, node); - node->ecmascript_obj = obj; - } - return obj; -#endif - return NULL; -} - void dom_add_attribute(struct dom_node *root, struct dom_node *node, struct dom_string *attr, struct dom_string *value) { @@ -73,7 +63,8 @@ dom_add_attribute(struct dom_node *root, struct dom_node *node, struct dom_strin unsigned char tmp; if (!obj) { - obj = make_new_object(ctx, node); + make_dom_node_html_data(ctx, node); + obj = node->ecmascript_obj; if (!obj) return; } if (value) { @@ -87,3 +78,20 @@ dom_add_attribute(struct dom_node *root, struct dom_node *node, struct dom_strin JS_SetProperty(ctx, obj, attr->string, &vp); attr->string[attr->length] = tmp; } + +void +dom_add_document(struct dom_node *root) +{ + JSContext *ctx = JS_NewContext(jsrt, 8192); + struct html_objects *o; + + if (!ctx) + return; + o = mem_calloc(1, sizeof(*o)); + if (!o) { + JS_DestroyContext(ctx); + return; + } + JS_SetContextPrivate(ctx, o); + /* Write me! */ +} diff --git a/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.c b/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.c index 2714ef12..be8232b7 100644 --- a/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.c +++ b/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.c @@ -115,9 +115,12 @@ const JSClass HTMLElement_class = { void make_HTMLElement(JSContext *ctx, struct dom_node *node) { + struct html_objects *o = JS_GetContextPrivate(ctx); + node->data.element.html_data = mem_calloc(1, sizeof(struct HTMLElement_struct)); if (node->data.element.html_data) { - node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLElement_class, NULL, NULL); + node->ecmascript_obj = JS_NewObject(ctx, (JSClass *)&HTMLElement_class, o->Element_object, NULL); + o->HTMLElement_object = node->ecmascript_obj; } } diff --git a/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.h b/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.h index e491af0b..62882a1b 100644 --- a/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.h +++ b/src/document/dom/ecmascript/spidermonkey/html/HTMLElement.h @@ -20,6 +20,8 @@ struct HTMLElement_struct { }; struct html_objects { /* FIXME: Better name for this type. */ + JSObject *Node_object; + JSObject *Element_object; JSObject *HTMLElement_object; }; diff --git a/src/document/dom/ecmascript/spidermonkey/html/html.c b/src/document/dom/ecmascript/spidermonkey/html/html.c index 2c18877d..fe020e42 100644 --- a/src/document/dom/ecmascript/spidermonkey/html/html.c +++ b/src/document/dom/ecmascript/spidermonkey/html/html.c @@ -92,13 +92,11 @@ done_dom_node_html_data(struct dom_node *node) mem_free(data); } -#if 0 void -make_dom_node_html_data(, struct dom_node *node) +make_dom_node_html_data(JSContext *ctx, struct dom_node *node) { int type = node->data.element.type; if (func[type].make) func[type].make(ctx, node); } -#endif diff --git a/src/document/dom/ecmascript/spidermonkey/html/html.h b/src/document/dom/ecmascript/spidermonkey/html/html.h index bc2271b2..42e09924 100644 --- a/src/document/dom/ecmascript/spidermonkey/html/html.h +++ b/src/document/dom/ecmascript/spidermonkey/html/html.h @@ -1,12 +1,10 @@ #ifndef EL__DOCUMENT_DOM_ECMASCRIPT_SPIDERMONKEY_HTML_HTML_H #define EL__DOCUMENT_DOM_ECMASCRIPT_SPIDERMONKEY_HTML_HTML_H +#include "ecmascript/spidermonkey/util.h" struct dom_node; void done_dom_node_html_data(struct dom_node *node); - -#if 0 void make_dom_node_html_data(JSContext *ctx, struct dom_node *node); -#endif #endif diff --git a/src/dom/Makefile b/src/dom/Makefile index e86f3433..3f8f9ec3 100644 --- a/src/dom/Makefile +++ b/src/dom/Makefile @@ -1,6 +1,7 @@ top_builddir=../.. include $(top_builddir)/Makefile.config +INCLUDES += $(SPIDERMONKEY_CFLAGS) SUBDIRS = css sgml test OBJS = configuration.o node.o select.o stack.o scanner.o diff --git a/src/dom/node.h b/src/dom/node.h index eb7c022d..046b2b99 100644 --- a/src/dom/node.h +++ b/src/dom/node.h @@ -261,6 +261,7 @@ struct dom_node { struct dom_node *parent; #ifdef CONFIG_ECMASCRIPT + void *ctx; /** The ECMAScript object related to this node. * NULL when the object was not used yet. */ void *ecmascript_obj; diff --git a/src/ecmascript/spidermonkey.c b/src/ecmascript/spidermonkey.c index 84d5e06c..3147f96f 100644 --- a/src/ecmascript/spidermonkey.c +++ b/src/ecmascript/spidermonkey.c @@ -55,7 +55,7 @@ /* TODO? Are there any which need to be implemented? */ -static JSRuntime *jsrt; +JSRuntime *jsrt; static void error_reporter(JSContext *ctx, const char *message, JSErrorReport *report)