added first cut of Level-1 DOM (not layout or XML dependent)

This commit is contained in:
shaver%netscape.com 1998-08-27 00:02:31 +00:00
Родитель 4eb0f47840
Коммит 4ff8b8dd14
9 изменённых файлов: 1734 добавлений и 0 удалений

35
lib/libdom/Makefile Normal file
Просмотреть файл

@ -0,0 +1,35 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../..
MODULE = dom
LIBRARY_NAME = dom
REQUIRES = js
EXPORTS = dom.h
CSRCS = domattr.c \
domcore.c \
domdoc.c \
domelement.c \
domnode.c \
domtext.c \
$(NULL)
include $(DEPTH)/config/rules.mk

253
lib/libdom/dom.h Normal file
Просмотреть файл

@ -0,0 +1,253 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* JSAPI DOM stuff, distinct from any HTML/XML embedding.
* See http://www.w3.org/DOM/ for details.
*/
#include "jsapi.h"
#ifndef DOM_H
#define DOM_H
typedef enum DOM_NodeType {
NODE_TYPE_ELEMENT = 1,
NODE_TYPE_ATTRIBUTE,
NODE_TYPE_TEXT,
NODE_TYPE_CDATA,
NODE_TYPE_ENTITY_REF,
NODE_TYPE_ENTITY,
NODE_TYPE_PI,
NODE_TYPE_COMMENT,
NODE_TYPE_DOCUMENT,
NODE_TYPE_DOCTYPE,
NODE_TYPE_DOCFRAGMENT,
NODE_TYPE_NOTATION
} DOM_NodeType;
typedef enum DOM_ExceptionCode {
DOM_NONE = 0,
DOM_INDEX_SIZE_ERR,
DOM_WSTRING_SIZE_ERR,
DOM_HIERARCHY_REQUEST_ERR,
DOM_WRONG_DOCUMENT_ERR,
DOM_INVALID_NAME_ERR,
DOM_NO_DATA_ALLOWED_ERR,
DOM_NO_MODIFICATION_ALLOWED_ERR,
DOM_NOT_FOUND_ERR,
DOM_NOT_SUPPORTED_ERR,
DOM_INUSE_ATTRIBUTE_ERR,
DOM_UNSUPPORTED_DOCUMENT_ERR
} DOM_ExceptionCode;
/* struct typedefs */
typedef struct DOM_Node DOM_Node;
typedef struct DOM_NodeOps DOM_NodeOps;
typedef struct DOM_Element DOM_Element;
typedef struct DOM_ElementOps DOM_ElementOps;
typedef struct DOM_AttributeList DOM_AttributeList;
typedef struct DOM_Attribute DOM_Attribute;
typedef struct DOM_Document DOM_Document;
typedef struct DOM_CharacterData DOM_CharacterData;
typedef struct DOM_Text DOM_Text;
/*
* All of these handlers are called _after_ the DOM tree is manipulated,
* and will never be called in error conditions (DOM_NOT_CHILD, etc.).
*/
struct DOM_NodeOps {
JSBool (*insertBefore)(JSContext *cx, DOM_Node *node, DOM_Node *child,
DOM_Node *ref);
JSBool (*replaceChild)(JSContext *cx, DOM_Node *node, DOM_Node *child,
DOM_Node *old);
JSBool (*removeChild) (JSContext *cx, DOM_Node *node, DOM_Node *old);
JSBool (*appendChild) (JSContext *cx, DOM_Node *node,
DOM_Node *child);
/* free up Node-private data */
void (*destroyNode) (JSContext *cx, DOM_Node *node);
/* construct a JSObject and fill in Node-private data as appropriate. */
JSObject * (*reflectNode) (JSContext *cx, DOM_Node *node);
};
/* stubs */
JSBool
DOM_InsertBeforeStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
DOM_Node *ref);
JSBool
DOM_ReplaceChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
DOM_Node *old);
JSBool
DOM_RemoveChildStub(JSContext *cx, DOM_Node *node, DOM_Node *old);
JSBool
DOM_AppendChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child);
void
DOM_DestroyNodeStub(JSContext *cx, DOM_Node *node);
JSObject *
DOM_ReflectNodeStub(JSContext *cx, DOM_Node *node);
/*
* ElementOps are called before any JS or DOM reflection occurs,
* and an error return (JS_FALSE or NULL) will prevent such
* manipulation.
*/
struct DOM_ElementOps {
/*
* if this succeeds, pre-existing JS reflections (DOM_Attributes)
* will be updated as well.
*/
JSBool (*setAttribute)(JSContext *cx, DOM_Element *element,
const char *name, const char *value);
/* returns attribute value (caller must copy) or NULL if not found */
const char * (*getAttribute)(JSContext *cx, DOM_Element *element,
const char *name, JSBool *cacheable);
/* returns number of attributes, or -1 if the number isn't known */
intN (*getNumAttrs)(JSContext *cx, DOM_Element *element,
JSBool *cacheable);
};
/* stubs */
JSBool
DOM_SetAttributeStub(JSContext *cx, DOM_Element *element, const char *name,
const char *value);
const char *
DOM_GetAttributeStub(JSContext *cx, DOM_Element *element, const char *name,
JSBool *cacheable);
intN
DOM_GetNumAttrsStub(JSContext *cx, DOM_Element *element, JSBool *cacheable);
/* convenience structure for stable attribute storage */
struct DOM_AttributeList {
char ** attr_names;
char ** attr_values;
int32 nattrs;
};
JSBool
DOM_SignalException(JSContext *cx, DOM_ExceptionCode exception);
/* The basic node */
struct DOM_Node {
DOM_NodeType type;
DOM_NodeOps *ops;
char *name;
struct DOM_Node *sibling;
struct DOM_Node *prev_sibling;
struct DOM_Node *child;
struct DOM_Node *parent;
JSObject *mocha_object;
void *data; /* embedding-private data */
};
JSBool
DOM_Init(JSContext *cx, JSObject *scope);
JSBool
DOM_DestroyNode(JSContext *cx, DOM_Node *node);
JSObject *
DOM_NewNodeObject(JSContext *cx, DOM_Node *node);
JSObject *
DOM_ObjectForNode(JSContext *cx, DOM_Node *node);
JSBool
DOM_PushNode(DOM_Node *node, DOM_Node *parent);
DOM_Node *
DOM_PopNode(DOM_Node *node);
struct DOM_Element {
DOM_Node node;
DOM_ElementOps *ops;
const char *tagName;
JSObject *attr_objs; /* XXX needed? */
};
DOM_Element *
DOM_NewElement(void);
JSObject *
DOM_NewElementObject(JSContext *cx, DOM_Element *element);
JSObject *
DOM_ObjectForElement(JSContext *cx, DOM_Element *element);
struct DOM_Attribute {
DOM_Node node;
char * value;
DOM_Element *element;
};
DOM_Attribute *
DOM_NewAttribute(const char *name, const char *value, DOM_Element *element);
JSObject *
DOM_NewAttributeObject(JSContext *cx, DOM_Attribute *attr);
JSObject *
DOM_ObjectForAttribute(JSContext *cx, DOM_Attribute *attr);
JSBool
DOM_SignalException(JSContext *cx, DOM_ExceptionCode code);
JSObject *
DOM_ObjectForNodeDowncast(JSContext *cx, DOM_Node *node);
struct DOM_Document {
DOM_Node node;
};
struct DOM_CharacterData {
DOM_Node node;
char *data;
uintN len;
};
struct DOM_Text {
DOM_CharacterData cdata;
};
DOM_Text *
DOM_NewText(const char *data, int64 len);
JSObject *
DOM_NewTextObject(JSContext *cx, DOM_Text *text);
JSObject *
DOM_ObjectForText(JSContext *cx, DOM_Text *text);
struct DOM_Comment {
DOM_CharacterData cdata;
};
#endif /* DOM_H */

75
lib/libdom/dom_priv.h Normal file
Просмотреть файл

@ -0,0 +1,75 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* Module-private stuff for the DOM lib.
*/
#ifndef DOM_PRIV_H
#define DOM_PRIV_H
#include "dom.h"
#include "xp_mem.h" /* XP_NEW_ZAP, XP_FREE */
#include "xpassert.h" /* XP_ASSERT */
#include "xp_str.h" /* XP_STRDUP */
JSObject *
dom_NodeInit(JSContext *cx, JSObject *obj);
JSObject *
dom_ElementInit(JSContext *cx, JSObject *obj, JSObject *node_proto);
JSObject *
dom_AttributeInit(JSContext *cx, JSObject *scope, JSObject *node_proto);
JSObject *
dom_CharacterDataInit(JSContext *cx, JSObject *scope, JSObject *node_proto);
JSObject *
dom_TextInit(JSContext *cx, JSObject *scope, JSObject *data_proto);
JSObject *
dom_CommentInit(JSContext *cx, JSObject *scope, JSObject *data_proto);
JSBool
dom_node_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
JSBool
dom_node_setter(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
/* if you adjust these enums, be sure to adjust the various setters */
enum {
DOM_NODE_NODENAME = -1,
DOM_NODE_NODEVALUE = -2,
DOM_NODE_NODETYPE = -3,
DOM_NODE_PARENTNODE = -4,
DOM_NODE_CHILDNODES = -5,
DOM_NODE_FIRSTCHILD = -6,
DOM_NODE_LASTCHILD = -7,
DOM_NODE_PREVIOUSSIBLING = -8,
DOM_NODE_NEXTSIBLING = -9,
DOM_NODE_ATTRIBUTES = -10,
DOM_NODE_HASCHILDNODES = -11,
DOM_ELEMENT_TAGNAME = -12,
};
extern JSPropertySpec dom_node_props[];
#endif /* DOM_PRIV_H */

135
lib/libdom/domattr.c Normal file
Просмотреть файл

@ -0,0 +1,135 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* DOM Attribute implementation.
*/
#include "dom_priv.h"
static JSBool
attribute_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSBool
attribute_setter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSClass DOM_AttributeClass = {
"Attribute", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, attribute_getter, attribute_setter,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
/* must start after the DOM_NODE tinyids */
enum {
ATTRIBUTE_SPECIFIED = -1,
ATTRIBUTE_NAME = -2,
ATTRIBUTE_VALUE = -3,
};
static JSPropertySpec attribute_props[] = {
{"specified", ATTRIBUTE_SPECIFIED, JSPROP_ENUMERATE, 0, 0},
{"name", ATTRIBUTE_NAME, JSPROP_ENUMERATE, 0, 0},
{"value", ATTRIBUTE_VALUE, JSPROP_ENUMERATE, 0, 0},
{0}
};
JSObject *
DOM_NewAttributeObject(JSContext *cx, DOM_Attribute *attr)
{
DOM_Node *node = (DOM_Node *)attr;
JSObject *obj;
JSString *str;
jsval v;
obj = JS_ConstructObject(cx, &DOM_AttributeClass, NULL, NULL);
if (!obj)
return NULL;
if (!JS_SetPrivate(cx, obj, attr)) {
return NULL;
}
str = JS_InternString(cx, node->name);
v = STRING_TO_JSVAL(str);
if (!str ||
!JS_SetProperty(cx, obj, "name", &v))
return NULL;
str = JS_NewStringCopyZ(cx, attr->value);
v = STRING_TO_JSVAL(str);
if (!str ||
!JS_SetProperty(cx, obj, "value", &v))
return NULL;
v = JSVAL_TRUE;
if (!JS_SetProperty(cx, obj, "specified", &v))
return NULL;
node->mocha_object = obj;
return obj;
}
DOM_Attribute *
DOM_NewAttribute(const char *name, const char *value, DOM_Element *element)
{
DOM_Attribute *attr;
attr = XP_NEW_ZAP(DOM_Attribute);
if (!attr)
return NULL;
attr->node.name = XP_STRDUP(name);
attr->value = XP_STRDUP(value);
attr->element = element;
return attr;
}
JSObject *
DOM_ObjectForAttribute(JSContext *cx, DOM_Attribute *attr)
{
if (!attr)
return NULL;
if (attr->node.mocha_object)
return attr->node.mocha_object;
return DOM_NewAttributeObject(cx, attr);
}
static JSBool
Attribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
JSObject *
dom_AttributeInit(JSContext *cx, JSObject *scope, JSObject *node_proto)
{
JSObject *proto;
proto = JS_InitClass(cx, scope, node_proto, &DOM_AttributeClass,
Attribute, 0,
attribute_props, NULL,
NULL, NULL);
return proto;
}

170
lib/libdom/domcore.c Normal file
Просмотреть файл

@ -0,0 +1,170 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* Core DOM stuff -- initialization, stub functions, DOMImplementation, etc.
*/
#include "dom_priv.h"
JSBool
DOM_Init(JSContext *cx, JSObject *scope) {
JSObject *node, *cdata;
return (( node = dom_NodeInit(cx, scope)) &&
dom_AttributeInit(cx, scope, node) &&
dom_ElementInit(cx, scope, node) &&
( cdata = dom_CharacterDataInit(cx, scope, node)) &&
dom_TextInit(cx, scope, cdata) &&
dom_CommentInit(cx, scope, cdata));
}
static char *exception_names[] = {
"NO_ERR",
"INDEX_SIZE_ERR",
"WSTRING_SIZE_ERR",
"HIERARCHY_REQUEST_ERR",
"WRONG_DOCUMENT_ERR",
"INVALID_NAME_ERR",
"NO_DATA_ALLOWED_ERR",
"NO_MODIFICATION_ALLOWED_ERR",
"NOT_FOUND_ERR",
"NOT_SUPPORTED_ERR",
"INUSE_ATTRIBUTE_ERR",
"UNSUPPORTED_DOCUMENT_ERR"
};
JSBool
DOM_SignalException(JSContext *cx, DOM_ExceptionCode exception)
{
JS_ReportError(cx, "DOM Exception: %s", exception_names[exception]);
return JS_TRUE;
}
JSBool
DOM_InsertBeforeStub(JSContext *cx, DOM_Node *node,
DOM_Node *child, DOM_Node *ref)
{
return JS_TRUE;
}
JSBool
DOM_ReplaceChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child,
DOM_Node *old)
{
return JS_TRUE;
}
JSBool
DOM_RemoveChildStub(JSContext *cx, DOM_Node *node, DOM_Node *old)
{
return JS_TRUE;
}
JSBool
DOM_AppendChildStub(JSContext *cx, DOM_Node *node, DOM_Node *child)
{
return JS_TRUE;
}
void
DOM_DestroyNodeStub(JSContext *cx, DOM_Node *node)
{
if (node->data)
JS_free(cx, node->data);
}
JSObject *
DOM_ReflectNodeStub(JSContext *cx, DOM_Node *node)
{
return NULL;
}
JSBool
DOM_SetAttributeStub(JSContext *cx, DOM_Element *element, const char *name,
const char *value)
{
return JS_TRUE;
}
const char *
DOM_GetAttributeStub(JSContext *cx, DOM_Element *element, const char *name,
JSBool *cacheable)
{
*cacheable = JS_FALSE;
return "#none";
}
intN
DOM_GetNumAttrsStub(JSContext *cx, DOM_Element *element, JSBool *cacheable)
{
*cacheable = JS_FALSE;
return -1;
}
#ifdef DEBUG_shaver
int LM_Node_indent = 0;
#endif
JSObject *
DOM_ObjectForNodeDowncast(JSContext *cx, DOM_Node *node)
{
if (!node)
return NULL;
if (node->mocha_object)
return node->mocha_object;
return node->ops->reflectNode(cx, node);
}
/*
* DOMImplementation
*/
static void
dom_finalize(JSContext *cx, JSObject *obj)
{
}
JSClass DOM_DOMClass = {
"DOM", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, dom_finalize
};
static JSBool
dom_hasFeature(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
char *feature, *version;
if (!JS_ConvertArguments(cx, argc, argv, "ss", &feature, &version))
return JS_TRUE;
if (!strcmp(feature, "HTML") &&
!strcmp(version, "1"))
*rval = JSVAL_TRUE;
else
*rval = JSVAL_FALSE;
return JS_TRUE;
}
static JSFunctionSpec dom_methods[] = {
{"hasFeature", dom_hasFeature, 2},
{0}
};

226
lib/libdom/domdoc.c Normal file
Просмотреть файл

@ -0,0 +1,226 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* DOM Document, DocumentFragment implementation.
*/
#include "dom_priv.h"
typedef struct DOM_DocumentFragmentStruct {
DOM_Node node;
void *data;
} DOM_DocumentFragmentStruct;
static JSBool
docfrag_masterDoc_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSPropertySpec docfrag_props[] = {
{"masterDoc", -1, 0, docfrag_masterDoc_get},
{0}
};
/*
* Document
*
* XXX mush this stuff into existing "document" in lm_doc.c?
*/
typedef struct DOM_DocumentStruct {
DOM_DocumentFragmentStruct fragment;
} DOM_DocumentStruct;
static void
document_finalize(JSContext *cx, JSObject *obj)
{
/* chain destructors */
/* node_finalize(cx, obj); */
}
static JSBool
document_setter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSBool
document_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
JSClass DOM_DocumentClass = {
"Document", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, document_getter, document_setter,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, document_finalize
};
static JSBool
doc_createEntity(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
/* new Entity */
return JS_TRUE;
}
static JSBool
doc_createEntityReference(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
/* new EntityReference */
return JS_TRUE;
}
static JSBool
doc_createDocumentFragment(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
/* new DocumentFragment */
return JS_TRUE;
}
static JSBool
doc_createElement(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *tagName;
if (!JS_ConvertArguments(cx, argc, argv, "S", &tagName))
return JS_FALSE;
/* new Element */
return JS_TRUE;
}
static JSBool
doc_createTextNode(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *text;
if (!JS_ConvertArguments(cx, argc, argv, "S", &text))
return JS_FALSE;
/* new TextNode */
return JS_TRUE;
}
static JSBool
doc_createComment(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *comment;
if (!JS_ConvertArguments(cx, argc, argv, "S", &comment))
return JS_FALSE;
/* new Comment */
return JS_TRUE;
}
static JSBool
doc_createCDATASection(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *cdata;
if (!JS_ConvertArguments(cx, argc, argv, "S", &cdata))
return JS_FALSE;
/* new CDATA */
return JS_TRUE;
}
static JSBool
doc_createProcessingInstruction(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
JSString *target, *data;
if (!JS_ConvertArguments(cx, argc, argv, "SS", &target, &data))
return JS_FALSE;
/* new PI */
return JS_TRUE;
}
static JSBool
doc_createAttribute(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *name;
if (!JS_ConvertArguments(cx, argc, argv, "S", &name))
return JS_FALSE;
/* new attr */
return JS_TRUE;
}
static JSBool
doc_getElementsByTagName(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
JSString *tagName;
if (!JS_ConvertArguments(cx, argc, argv, "S", &tagName))
return JS_FALSE;
return JS_TRUE;
}
static JSFunctionSpec document_methods[] = {
{"createEntity", doc_createEntity, 0},
{"createEntityReference", doc_createEntityReference, 0},
{"createDocumentFragment", doc_createDocumentFragment, 0},
{"createElement", doc_createElement, 1},
{"createTextNode", doc_createTextNode, 1},
{"createComment", doc_createComment, 1},
{"createCDATASection", doc_createCDATASection, 1},
{"createProcessingInstruction", doc_createProcessingInstruction, 2},
{"createAttribute", doc_createAttribute, 1},
{"getElementsByTagName", doc_getElementsByTagName, 1},
{0}
};
enum {
DOCUMENT_DOCTYPE = -1,
DOCUMENT_IMPLEMENTATION = -2,
DOCUMENT_DOCUMENTELEMENT = -3
};
static JSPropertySpec document_props[] = {
{"doctype", DOCUMENT_DOCTYPE},
{"implementation", DOCUMENT_IMPLEMENTATION},
{"documentElement", DOCUMENT_DOCUMENTELEMENT},
{0}
};
/* XXXXXXXX should be decoder->document_prototype! */
static JSObject *documentProto;
static JSBool
Document(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
{
return JS_TRUE;
}
JSObject *
DOM_DocumentInit(JSContext *cx, JSObject *scope, JSObject *docfrag_prototype)
{
JSObject *documentProto;
documentProto = JS_InitClass(cx, scope, docfrag_prototype,
&DOM_DocumentClass, Document, 0,
document_props, document_methods,
NULL, NULL);
if (!documentProto)
return NULL;
return documentProto;
}

136
lib/libdom/domelement.c Normal file
Просмотреть файл

@ -0,0 +1,136 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* DOM Element implementation.
*/
#include "dom_priv.h"
DOM_Element *
DOM_NewElement(void)
{
DOM_Element *element = XP_NEW_ZAP(DOM_Element);
if (!element)
return NULL;
element->node.type = NODE_TYPE_ELEMENT;
return element;
}
static JSPropertySpec element_props[] = {
{"tagName", DOM_ELEMENT_TAGNAME, JSPROP_READONLY, 0, 0},
{0}
};
static JSBool
element_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
intN slot;
DOM_Element *element;
if (!JSVAL_IS_INT(id))
return JS_TRUE;
slot = JSVAL_TO_INT(id);
/*
* Look, ma! Inheritance!
* We handle .attributes ourselves because we return something other
* than null, unlike every other Node subclass.
*/
if (slot != DOM_NODE_ATTRIBUTES &&
slot <= DOM_NODE_NODENAME &&
slot >= DOM_NODE_HASCHILDNODES) {
return dom_node_getter(cx, obj, id, vp);
}
element = (DOM_Element *)JS_GetPrivate(cx, obj);
if (!element)
return JS_TRUE;
if (slot == DOM_ELEMENT_TAGNAME) {
JSString *tagName =
JS_InternString(cx, element->tagName ? element->tagName : "#tag");
if (!tagName)
return JS_FALSE;
*vp = STRING_TO_JSVAL(tagName);
}
return JS_TRUE;
}
static JSBool
element_setter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static void
element_finalize(JSContext *cx, JSObject *obj)
{
return;
}
static JSClass DOM_ElementClass = {
"Element", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, element_getter, element_setter,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, element_finalize
};
JSObject *
DOM_NewElementObject(JSContext *cx, DOM_Element *element)
{
JSObject *obj;
obj = JS_ConstructObject(cx, &DOM_ElementClass, NULL, NULL);
if (!obj)
return NULL;
if (!JS_SetPrivate(cx, obj, element))
return NULL;
element->node.mocha_object = obj;
return obj;
}
JSObject *
DOM_ObjectForElement(JSContext *cx, DOM_Element *element)
{
if (!element)
return NULL;
if (element->node.mocha_object)
return element->node.mocha_object;
return DOM_NewElementObject(cx, element);
}
static JSBool
Element(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *vp)
{
return JS_TRUE;
}
JSObject *
dom_ElementInit(JSContext *cx, JSObject *scope, JSObject *node_proto)
{
JSObject *proto = JS_InitClass(cx, scope, node_proto, &DOM_ElementClass,
Element, 0,
element_props, NULL,
NULL, NULL);
if (!JS_DefineProperties(cx, proto, dom_node_props))
return NULL;
return proto;
}

515
lib/libdom/domnode.c Normal file
Просмотреть файл

@ -0,0 +1,515 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* DOM Node, NodeList, NamedNodeMap implementation.
*/
#include "dom_priv.h"
#ifdef DEBUG_shaver
int DOM_node_indent = 0;
#endif
DOM_Node *
DOM_PopNode(DOM_Node *node)
{
return node->parent;
}
JSBool
DOM_PushNode(DOM_Node *node, DOM_Node *parent)
{
DOM_Node *iter;
node->parent = parent;
node->sibling = NULL;
node->prev_sibling = NULL;
node->child = NULL;
/* First child */
if (!parent->child) {
parent->child = node;
return JS_TRUE;
}
/*
* XXX optimize by using parent->mocha_object to cache last child, and
* XXX NULLing parent->mocha_object on PopNode?
*/
for (iter = parent->child; iter->sibling; iter = iter->sibling)
; /* empty */
XP_ASSERT(iter);
iter->sibling = node;
node->prev_sibling = iter;
return JS_TRUE;
}
JSObject *
DOM_ObjectForNode(JSContext *cx, DOM_Node *node)
{
if (!node)
return NULL;
if (node->mocha_object)
return node->mocha_object;
return DOM_NewNodeObject(cx, node);
}
JSBool
dom_node_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
intN slot;
DOM_Node *node;
JSString *str;
if (!JSVAL_IS_INT(id))
return JS_TRUE;
node = (DOM_Node *)JS_GetPrivate(cx, obj);
if (!node)
return JS_TRUE;
slot = JSVAL_TO_INT(id);
switch(slot) {
case DOM_NODE_NODENAME:
if (!node->name) {
*vp = JSVAL_NULL; /* XXX '#nameless' or some such? */
return JS_TRUE;
}
str = JS_InternString(cx, node->name);
if (!str)
return JS_FALSE;
*vp = STRING_TO_JSVAL(str);
return JS_TRUE;
case DOM_NODE_NODETYPE:
*vp = INT_TO_JSVAL(node->type);
return JS_TRUE;
case DOM_NODE_FIRSTCHILD:
*vp = OBJECT_TO_JSVAL(DOM_ObjectForNodeDowncast(cx, node->child));
return JS_TRUE;
case DOM_NODE_NEXTSIBLING:
*vp = OBJECT_TO_JSVAL(DOM_ObjectForNodeDowncast(cx, node->sibling));
return JS_TRUE;
case DOM_NODE_PREVIOUSSIBLING:
*vp = OBJECT_TO_JSVAL(DOM_ObjectForNodeDowncast(cx,
node->prev_sibling));
return JS_TRUE;
case DOM_NODE_PARENTNODE:
*vp = OBJECT_TO_JSVAL(DOM_ObjectForNodeDowncast(cx, node->parent));
return JS_TRUE;
case DOM_NODE_HASCHILDNODES:
*vp = BOOLEAN_TO_JSVAL((JSBool)(node->child != NULL));
return JS_TRUE;
case DOM_NODE_ATTRIBUTES:
/* only elements have non-null attributes */
*vp = JSVAL_NULL;
return JS_TRUE;
default:
XP_ASSERT(0);
break;
}
return JS_TRUE;
}
JSBool
dom_node_setter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static void
node_finalize(JSContext *cx, JSObject *obj)
{
DOM_Node *priv = (DOM_Node *)JS_GetPrivate(cx, obj);
if (!priv)
return;
priv->mocha_object = NULL;
/* XXX walk tree, freeing until we find an object rooting a subgraph */
}
static JSClass DOM_NodeClass = {
"Node", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, dom_node_getter, dom_node_setter,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, node_finalize
};
JSObject *
DOM_NewNodeObject(JSContext *cx, DOM_Node *node)
{
JSObject *obj;
obj = JS_ConstructObject(cx, &DOM_NodeClass, NULL, NULL);
if (!obj)
return NULL;
if (!JS_SetPrivate(cx, obj, node)) {
return NULL;
}
node->mocha_object = obj;
return obj;
}
#define REMOVE_FROM_TREE(node) \
PR_BEGIN_MACRO \
if (node->prev_sibling) \
node->prev_sibling->sibling = node->sibling; \
if (node->sibling) \
node->sibling->prev_sibling = newNode->prev_sibling; \
node->sibling = node->prev_sibling = node->parent = NULL; \
PR_END_MACRO
#define FAIL_UNLESS_CHILD(node, refNode) \
PR_BEGIN_MACRO \
if (refNode->parent != node) { \
/* XXX walk the tree looking for it? */ \
DOM_SignalException(cx, DOM_NOT_FOUND_ERR); \
return JS_FALSE; \
} \
PR_END_MACRO
static JSBool
node_insertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *vp)
{
JSObject *newChild, *refChild;
DOM_Node *newNode, *refNode, *node;
if (!JS_ConvertArguments(cx, argc, argv, "oo", &newChild, &refChild))
return JS_FALSE;
node = (DOM_Node *)JS_GetPrivate(cx, obj);
if (!node)
return JS_TRUE;
newNode = (DOM_Node *)JS_GetPrivate(cx, newChild);
refNode = (DOM_Node *)JS_GetPrivate(cx, refChild);
*vp = argv[0]; /* newChild */
if (!newNode || !refNode) {
return JS_TRUE;
}
FAIL_UNLESS_CHILD(node, refNode);
REMOVE_FROM_TREE(newNode);
newNode->parent = node;
newNode->sibling = refNode;
newNode->prev_sibling = refNode->prev_sibling;
refNode->prev_sibling = newNode;
return node->ops->insertBefore(cx, node, newNode, refNode);
}
static JSBool
node_replaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *vp)
{
JSObject *oldChild, *newChild;
DOM_Node *oldNode, *newNode, *node;
if (!JS_ConvertArguments(cx, argc, argv, "oo", &newChild, &oldChild))
return JS_FALSE;
node = (DOM_Node *)JS_GetPrivate(cx, obj);
if (!node)
return JS_TRUE;
newNode = (DOM_Node *)JS_GetPrivate(cx, newChild);
oldNode = (DOM_Node *)JS_GetPrivate(cx, oldChild);
*vp = argv[1]; /* oldChild */
if (newNode == oldNode ||
!newNode || !oldNode)
return JS_TRUE;
FAIL_UNLESS_CHILD(node, oldNode);
REMOVE_FROM_TREE(newNode);
newNode->parent = node;
oldNode->sibling->prev_sibling = newNode;
oldNode->prev_sibling->sibling = newNode;
oldNode->parent = oldNode->sibling = oldNode->prev_sibling = NULL;
return node->ops->replaceChild(cx, node, newNode, oldNode);
}
static JSBool
node_removeChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *vp)
{
JSObject *deadChild;
DOM_Node *deadNode, *iter, *node;
if (!JS_ConvertArguments(cx, argc, argv, "o", &deadChild))
return JS_FALSE;
*vp = argv[0]; /* deadChild */
node = (DOM_Node *)JS_GetPrivate(cx, obj);
deadNode = (DOM_Node *)JS_GetPrivate(cx, deadChild);
if (!deadNode || !node)
return JS_TRUE;
FAIL_UNLESS_CHILD(node, deadNode);
REMOVE_FROM_TREE(deadNode);
return node->ops->removeChild(cx, node, deadNode);
}
static JSBool
node_appendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *vp)
{
JSObject *newChild;
DOM_Node *newNode, *node, *iter;
if (!JS_ConvertArguments(cx, argc, argv, "o", &newChild))
return JS_FALSE;
*vp = argv[0]; /* newChild */
node = (DOM_Node *)JS_GetPrivate(cx, obj);
newNode = (DOM_Node *)JS_GetPrivate(cx, obj);
if (!node || !newNode)
return JS_TRUE;
REMOVE_FROM_TREE(newNode);
newNode->parent = node;
iter = node->child;
if (iter) {
while (iter->sibling)
iter = iter->sibling;
iter->sibling = newNode;
newNode->prev_sibling = iter;
} else {
node->child = newNode;
}
return node->ops->appendChild(cx, node, newNode);
}
static JSBool
node_cloneNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *vp)
{
JSBool deep;
if (!JS_ConvertArguments(cx, argc, argv, "b", &deep))
return JS_FALSE;
DOM_SignalException(cx, DOM_NOT_SUPPORTED_ERR);
/* clone */
return JS_TRUE;
}
static JSBool
node_equals(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
{
JSObject *node;
DOM_Node *node1, *node2;
if (!JS_ConvertArguments(cx, argc, argv, "o", &node))
return JS_FALSE;
node1 = (DOM_Node *)JS_GetPrivate(cx, obj);
node2 = (DOM_Node *)JS_GetPrivate(cx, node);
*vp = (JSBool)(node1 == node2);
return JS_TRUE;
}
static JSFunctionSpec node_methods[] = {
{"insertBefore", node_insertBefore, 2},
{"replaceChild", node_replaceChild, 2},
{"removeChild", node_removeChild, 1},
{"appendChild", node_appendChild, 1},
{"cloneNode", node_cloneNode, 1},
{"equals", node_equals, 2},
{0}
};
JSPropertySpec dom_node_props[] = {
{"nodeName", DOM_NODE_NODENAME},
{"nodeValue", DOM_NODE_NODEVALUE},
{"nodeType", DOM_NODE_NODETYPE},
{"parentNode", DOM_NODE_PARENTNODE},
{"childNodes", DOM_NODE_CHILDNODES},
{"firstChild", DOM_NODE_FIRSTCHILD},
{"lastChild", DOM_NODE_LASTCHILD},
{"previousSibling", DOM_NODE_PREVIOUSSIBLING},
{"nextSibling", DOM_NODE_NEXTSIBLING},
{"attributes", DOM_NODE_ATTRIBUTES},
{"hasChildNodes", DOM_NODE_HASCHILDNODES},
{0}
};
static JSConstDoubleSpec node_static_props[] = {
{NODE_TYPE_ELEMENT, "ELEMENT"},
{NODE_TYPE_ATTRIBUTE, "ATTRIBUTE"},
{NODE_TYPE_PI, "PROCESSING_INSTRUCTION"},
{NODE_TYPE_CDATA, "CDATA_SECTION"},
{NODE_TYPE_TEXT, "TEXT"},
{NODE_TYPE_ENTITY_REF, "ENTITY_REFERENCE"},
{NODE_TYPE_ENTITY, "ENTITY"},
{NODE_TYPE_COMMENT, "COMMENT"},
{NODE_TYPE_DOCUMENT, "DOCUMENT"},
{NODE_TYPE_DOCTYPE, "DOCUMENT_TYPE"},
{NODE_TYPE_DOCFRAGMENT, "DOCUMENT_FRAGMENT"},
{NODE_TYPE_NOTATION, "NOTATION"},
{0}
};
static JSBool
Node(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
{
return JS_TRUE;
}
JSObject *
dom_NodeInit(JSContext *cx, JSObject *scope)
{
JSObject *proto, *ctor;
proto = JS_InitClass(cx, scope, NULL, &DOM_NodeClass,
Node, 0,
dom_node_props, node_methods,
NULL, NULL);
if (!proto || !(ctor = JS_GetConstructor(cx, proto)))
return NULL;
if (!JS_DefineConstDoubles(cx, ctor, node_static_props))
return NULL;
return proto;
}
/*
* NodeList
*
* Basically an Array with magic methods.
*/
#if 0
static JSClass DOM_NodeListClass = {
"NodeList", 0,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
static JSBool
nodelist_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
uint32 index;
if (!JS_ConvertArguments(cx, argc, argv, "j", &index))
return JS_TRUE;
/* JS_GetElement */
return JS_TRUE;
}
static JSFunctionSpec nodelist_methods[] = {
{"item", nodelist_item, 1},
{0},
};
static JSBool
nodelist_size_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSPropertySpec nodelist_props[] = {
{"size", -1, 0, nodelist_size_get},
{0}
};
/*
* NamedNodeMap
*
* Basically an Object with magic resolve and helper methods.
*/
static JSBool
nnm_resolve(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSClass DOM_NamedNodeMapClass = {
"NamedNodeMap", 0,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
static JSBool
nnm_getNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
/* JS_GetProperty */
return JS_TRUE;
}
static JSBool
nnm_setNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
return JS_TRUE;
/* JS_SetProperty */
}
static JSBool
nnm_removeNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
/* JS_DeleteProperty */
return JS_TRUE;
}
static JSBool
nnm_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
/* return given slot -- OBJ_GET_SLOT? */
return JS_TRUE;
}
static JSFunctionSpec nnm_methods[] = {
{"getNamedItem", nnm_getNamedItem, 1},
{"setNamedItem", nnm_setNamedItem, 1},
{"removeNamedItem", nnm_removeNamedItem,1},
{"item", nnm_item, 1},
{0}
};
static JSBool
nnm_get_size(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
/* return __count__ */
return JS_FALSE;
}
enum {
NNM_SIZE = -1
};
static JSPropertySpec nnm_props[] = {
{"size", NNM_SIZE, 0, nnm_get_size},
{0}
};
#endif /* 0 */

189
lib/libdom/domtext.c Normal file
Просмотреть файл

@ -0,0 +1,189 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "dom_priv.h"
/*
* DOM CharacterData, Text and Comment implementations.
*/
/* must start after the DOM_NODE tinyids */
enum {
DOM_CDATA_DATA = -14,
DOM_CDATA_LENGTH = -15
};
static JSBool
cdata_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
intN slot;
DOM_CharacterData *cdata;
JSString *str;
if (!JSVAL_IS_INT(id))
return JS_TRUE;
slot = JSVAL_TO_INT(id);
/* Look, ma! Inheritance! */
if (slot <= DOM_NODE_NODENAME &&
slot >= DOM_NODE_HASCHILDNODES) {
return dom_node_getter(cx, obj, id, vp);
}
cdata = (DOM_CharacterData *)JS_GetPrivate(cx, obj);
if (!cdata)
return JS_TRUE;
switch (slot) {
case DOM_CDATA_DATA:
str = JS_NewStringCopyN(cx, cdata->data, cdata->len);
if (!str)
return JS_FALSE;
*vp = STRING_TO_JSVAL(str);
/* XXX cache the string */
break;
case DOM_CDATA_LENGTH:
/* XXX it's a long, see... */
*vp = INT_TO_JSVAL(cdata->len);
break;
default:;
}
return JS_TRUE;
}
static JSBool
cdata_setter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSClass DOM_CDataClass = {
"CharacterData", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, cdata_getter, cdata_setter,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
static JSPropertySpec cdata_props[] = {
{"data", DOM_CDATA_DATA, JSPROP_ENUMERATE | JSPROP_READONLY,
0, 0},
{"length", DOM_CDATA_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY,
0, 0},
{0}
};
static JSFunctionSpec cdata_methods[] = {
{0}
};
static JSBool
CharacterData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
return JS_TRUE;
}
JSObject *
dom_CharacterDataInit(JSContext *cx, JSObject *scope, JSObject *node_proto)
{
JSObject *proto;
proto = JS_InitClass(cx, scope, node_proto, &DOM_CDataClass,
CharacterData, 0,
cdata_props, cdata_methods,
NULL, NULL);
return proto;
}
/*
* Text
*/
static JSClass DOM_TextClass = {
"Text", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, cdata_getter, cdata_setter,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
};
static JSFunctionSpec text_methods[] = {
{0}
};
JSObject *
DOM_NewTextObject(JSContext *cx, DOM_Text *text)
{
DOM_Node *node = (DOM_Node *)text;
JSObject *obj;
obj = JS_ConstructObject(cx, &DOM_TextClass, NULL, NULL);
if (!obj)
return NULL;
if (!JS_SetPrivate(cx, obj, text)) {
return NULL;
}
node->mocha_object = obj;
return obj;
}
DOM_Text *
DOM_NewText(const char *data, int64 length)
{
XP_ASSERT((0 && "DOM_NewText NYI"));
return NULL;
}
JSObject *
DOM_ObjectForText(JSContext *cx, DOM_Text *text)
{
if (!text)
return NULL;
if (text->cdata.node.mocha_object)
return text->cdata.node.mocha_object;
return DOM_NewTextObject(cx, text);
}
static JSBool
Text(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
JSObject *
dom_TextInit(JSContext *cx, JSObject *scope, JSObject *cdata_proto)
{
JSObject *proto;
proto = JS_InitClass(cx, scope, cdata_proto, &DOM_TextClass,
Text, 0,
NULL, text_methods,
NULL, NULL);
return proto;
}
/*
* Comment
*/
JSObject *
dom_CommentInit(JSContext *cx, JSObject *scope, JSObject *cdata_proto)
{
/* Do we need a custom proto here? */
return cdata_proto;
}