1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

DOM, ecmascript: Export jsrt. It will be used by DOM.

Nothing special else. I have no inspiration to do more.
This commit is contained in:
Witold Filipczyk 2007-06-24 11:48:28 +02:00 committed by Witold Filipczyk
parent 0668b4fd5c
commit 7101479366
8 changed files with 35 additions and 24 deletions

View File

@ -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! */
}

View File

@ -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;
}
}

View File

@ -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;
};

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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)