- Use 8 space hard tabstops like god and IBM intended, but indent-tabs-mode:nil
should eliminate hard tabs anyway (so 8 is just in case one gets thru -- LXR was not displaying this source well with 4). - Don't nest jsapi.h outside the idempotent-include #ifndef in dom.h. - Include xp.h to get this code working on Windows (to cope with some kind of compiled header problem). - Fix bad JS_GetEmptyStringValue calls that were treated as returning JSString* rather than jsval, and fed into STRING_TO_JSVAL. - Avoid tagging and untagging a jsval to test for a null JSString* return. - Fiddle formatting in a couple of places. - Avoid leaving cdata->data null after realloc failure. Use of a local temp (data2) also improves generated code by eliminating memory ambiguity. git-svn-id: svn://10.0.0.236/trunk@9883 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -21,10 +21,11 @@
|
||||
* See http://www.w3.org/DOM/ for details.
|
||||
*/
|
||||
|
||||
#include "jsapi.h"
|
||||
#ifndef DOM_H
|
||||
#define DOM_H
|
||||
|
||||
#include "jsapi.h"
|
||||
|
||||
typedef enum DOM_NodeType {
|
||||
NODE_TYPE_ELEMENT = 1,
|
||||
NODE_TYPE_ATTRIBUTE,
|
||||
@@ -56,16 +57,16 @@ typedef enum DOM_ExceptionCode {
|
||||
} DOM_ExceptionCode;
|
||||
|
||||
/* struct typedefs */
|
||||
typedef struct DOM_Node DOM_Node;
|
||||
typedef struct DOM_NodeOps DOM_NodeOps;
|
||||
typedef struct DOM_AttributeEntry DOM_AttributeEntry;
|
||||
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;
|
||||
typedef struct DOM_Node DOM_Node;
|
||||
typedef struct DOM_NodeOps DOM_NodeOps;
|
||||
typedef struct DOM_AttributeEntry DOM_AttributeEntry;
|
||||
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 before the DOM tree is manipulated, with
|
||||
@@ -84,20 +85,20 @@ typedef struct DOM_Text DOM_Text;
|
||||
* at this point, or signal an exception and return false.
|
||||
*/
|
||||
struct DOM_NodeOps {
|
||||
JSBool (*insertBefore)(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *ref, JSBool before);
|
||||
JSBool (*replaceChild)(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *old, JSBool before);
|
||||
JSBool (*removeChild) (JSContext *cx, DOM_Node *node, DOM_Node *old,
|
||||
JSBool before);
|
||||
JSBool (*appendChild) (JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
JSBool before);
|
||||
JSBool (*insertBefore)(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *ref, JSBool before);
|
||||
JSBool (*replaceChild)(JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
DOM_Node *old, JSBool before);
|
||||
JSBool (*removeChild) (JSContext *cx, DOM_Node *node, DOM_Node *old,
|
||||
JSBool before);
|
||||
JSBool (*appendChild) (JSContext *cx, DOM_Node *node, DOM_Node *child,
|
||||
JSBool before);
|
||||
|
||||
/* free up Node-private data */
|
||||
void (*destroyNode) (JSContext *cx, DOM_Node *node);
|
||||
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);
|
||||
JSObject * (*reflectNode) (JSContext *cx, DOM_Node *node);
|
||||
|
||||
};
|
||||
|
||||
@@ -138,18 +139,18 @@ struct DOM_ElementOps {
|
||||
* DOM_SignalException(cx, DOM_INVALID_NAME_ERR) if it's an
|
||||
* invalid name. (The DOM_NO_MODIFICATION_ALLOWED_ERR case is
|
||||
* handled in the DOM code itself, and no call will be made to the
|
||||
* setAttribute handler in that case.)
|
||||
* setAttribute handler in that case.)
|
||||
*/
|
||||
JSBool (*setAttribute)(JSContext *cx, DOM_Element *element,
|
||||
const char *name, const char *value);
|
||||
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);
|
||||
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);
|
||||
intN (*getNumAttrs)(JSContext *cx, DOM_Element *element,
|
||||
JSBool *cacheable);
|
||||
};
|
||||
|
||||
/* stubs */
|
||||
@@ -171,15 +172,15 @@ 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 */
|
||||
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
|
||||
@@ -219,10 +220,10 @@ struct DOM_AttributeEntry {
|
||||
};
|
||||
|
||||
struct DOM_Element {
|
||||
DOM_Node node;
|
||||
DOM_ElementOps *ops;
|
||||
const char *tagName;
|
||||
uintN nattrs;
|
||||
DOM_Node node;
|
||||
DOM_ElementOps *ops;
|
||||
const char *tagName;
|
||||
uintN nattrs;
|
||||
DOM_AttributeEntry *attrs;
|
||||
void *style; /* later, later... */
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -26,9 +26,7 @@
|
||||
#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 */
|
||||
#include "xp.h"
|
||||
|
||||
JSObject *
|
||||
dom_NodeInit(JSContext *cx, JSObject *obj);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -50,9 +50,9 @@ enum {
|
||||
};
|
||||
|
||||
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},
|
||||
{"specified", ATTRIBUTE_SPECIFIED, JSPROP_ENUMERATE, 0, 0},
|
||||
{"name", ATTRIBUTE_NAME, JSPROP_ENUMERATE, 0, 0},
|
||||
{"value", ATTRIBUTE_VALUE, JSPROP_ENUMERATE, 0, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
@@ -68,9 +68,8 @@ DOM_NewAttributeObject(JSContext *cx, DOM_Attribute *attr)
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
if (!JS_SetPrivate(cx, obj, attr)) {
|
||||
if (!JS_SetPrivate(cx, obj, attr))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str = JS_NewStringCopyZ(cx, node->name);
|
||||
v = STRING_TO_JSVAL(str);
|
||||
@@ -91,8 +90,8 @@ DOM_NewAttribute(const char *name, const char *value, DOM_Element *element)
|
||||
DOM_Attribute *attr;
|
||||
attr = XP_NEW_ZAP(DOM_Attribute);
|
||||
if (!attr)
|
||||
return NULL;
|
||||
|
||||
return NULL;
|
||||
|
||||
attr->node.name = XP_STRDUP(name);
|
||||
attr->element = element;
|
||||
return attr;
|
||||
@@ -102,7 +101,7 @@ JSObject *
|
||||
DOM_ObjectForAttribute(JSContext *cx, DOM_Attribute *attr)
|
||||
{
|
||||
if (!attr)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if (attr->node.mocha_object)
|
||||
return attr->node.mocha_object;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -183,7 +183,7 @@ dom_hasFeature(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
*rval = JSVAL_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static JSFunctionSpec dom_methods[] = {
|
||||
{"hasFeature", dom_hasFeature, 2},
|
||||
{0}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -172,7 +172,7 @@ doc_getElementsByTagName(JSContext *cx, JSObject* obj, uintN argc,
|
||||
JSString *tagName;
|
||||
if (!JS_ConvertArguments(cx, argc, argv, "S", &tagName))
|
||||
return JS_FALSE;
|
||||
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "dom_priv.h"
|
||||
|
||||
static JSPropertySpec element_props[] = {
|
||||
{"tagName", DOM_ELEMENT_TAGNAME, JSPROP_READONLY, 0, 0},
|
||||
{"tagName", DOM_ELEMENT_TAGNAME, JSPROP_READONLY, 0, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ element_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
slot = JSVAL_TO_INT(id);
|
||||
|
||||
/*
|
||||
/*
|
||||
* Look, ma! Inheritance!
|
||||
* We handle .attributes ourselves because we return something other
|
||||
* than null, unlike every other Node subclass.
|
||||
@@ -56,15 +56,15 @@ element_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
if (slot == DOM_ELEMENT_TAGNAME) {
|
||||
JSString *tagName;
|
||||
#ifdef DEBUG_shaver_0
|
||||
fprintf(stderr, "getting tagName %s",
|
||||
element->tagName ? element->tagName : "#tag");
|
||||
tagName = JS_InternString(cx, element->tagName ?
|
||||
element->tagName : "#tag");
|
||||
fprintf(stderr, ": %x\n", tagName);
|
||||
fprintf(stderr, "getting tagName %s",
|
||||
element->tagName ? element->tagName : "#tag");
|
||||
tagName = JS_InternString(cx, element->tagName ?
|
||||
element->tagName : "#tag");
|
||||
fprintf(stderr, ": %x\n", tagName);
|
||||
#else
|
||||
|
||||
tagName = JS_NewStringCopyZ(cx,
|
||||
element->tagName ? element->tagName : "#tag");
|
||||
tagName = JS_NewStringCopyZ(cx, element->tagName
|
||||
? element->tagName
|
||||
: "#tag");
|
||||
#endif
|
||||
if (!tagName)
|
||||
return JS_FALSE;
|
||||
@@ -106,11 +106,12 @@ element_getAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_FALSE;
|
||||
|
||||
if (entry && entry->value) {
|
||||
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, entry->value));
|
||||
if (!JSVAL_TO_STRING(*rval))
|
||||
JSString *valstr = JS_NewStringCopyZ(cx, entry->value);
|
||||
if (!valstr)
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(valstr);
|
||||
} else {
|
||||
*rval = STRING_TO_JSVAL(JS_GetEmptyStringValue(cx));
|
||||
*rval = JS_GetEmptyStringValue(cx);
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
@@ -176,11 +177,11 @@ element_removeAttributeNode(JSContext *cx, JSObject *obj, uintN argc,
|
||||
}
|
||||
|
||||
static JSFunctionSpec element_methods[] = {
|
||||
{"setAttribute", element_setAttribute, 2},
|
||||
{"getAttribute", element_getAttribute, 1},
|
||||
{"removeAttribute", element_removeAttribute, 1},
|
||||
{"setAttributeNode", element_setAttributeNode, 1},
|
||||
{"getAttributeNode", element_getAttributeNode, 1},
|
||||
{"setAttribute", element_setAttribute, 2},
|
||||
{"getAttribute", element_getAttribute, 1},
|
||||
{"removeAttribute", element_removeAttribute, 1},
|
||||
{"setAttributeNode", element_setAttributeNode, 1},
|
||||
{"getAttributeNode", element_getAttributeNode, 1},
|
||||
{"removeAttributeNode", element_removeAttributeNode, 1},
|
||||
{0}
|
||||
};
|
||||
@@ -208,7 +209,7 @@ JSObject *
|
||||
DOM_NewElementObject(JSContext *cx, DOM_Element *element)
|
||||
{
|
||||
JSObject *obj;
|
||||
|
||||
|
||||
obj = JS_ConstructObject(cx, &DOM_ElementClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
@@ -342,9 +343,9 @@ JSObject *
|
||||
dom_ElementInit(JSContext *cx, JSObject *scope, JSObject *node_proto)
|
||||
{
|
||||
JSObject *proto = JS_InitClass(cx, scope, node_proto, &DOM_ElementClass,
|
||||
Element, 0,
|
||||
element_props, element_methods,
|
||||
NULL, NULL);
|
||||
Element, 0,
|
||||
element_props, element_methods,
|
||||
NULL, NULL);
|
||||
if (!JS_DefineProperties(cx, proto, dom_node_props))
|
||||
return NULL;
|
||||
return proto;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -160,7 +160,7 @@ DOM_NewNodeObject(JSContext *cx, DOM_Node *node)
|
||||
obj = JS_ConstructObject(cx, &DOM_NodeClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
|
||||
if (!JS_SetPrivate(cx, obj, node)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -285,15 +285,15 @@ node_insertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
newNode->sibling = refNode;
|
||||
newNode->prev_sibling = refNode->prev_sibling;
|
||||
|
||||
|
||||
refNode->prev_sibling = newNode;
|
||||
|
||||
|
||||
return node->ops->insertBefore(cx, node, newNode, refNode, JS_TRUE);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
node_replaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *vp)
|
||||
jsval *vp)
|
||||
{
|
||||
JSObject *oldChild, *newChild;
|
||||
DOM_Node *oldNode, *newNode, *node;
|
||||
@@ -317,19 +317,19 @@ node_replaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (!node->ops->replaceChild(cx, node, newNode, oldNode, JS_TRUE))
|
||||
return JS_FALSE;
|
||||
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, JS_FALSE);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
node_removeChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *vp)
|
||||
jsval *vp)
|
||||
{
|
||||
JSObject *deadChild;
|
||||
DOM_Node *deadNode, *node;
|
||||
@@ -354,11 +354,11 @@ node_removeChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
static JSBool
|
||||
node_appendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *vp)
|
||||
jsval *vp)
|
||||
{
|
||||
JSObject *newChild;
|
||||
DOM_Node *newNode, *node, *iter;
|
||||
|
||||
|
||||
if (!JS_ConvertArguments(cx, argc, argv, "o", &newChild))
|
||||
return JS_FALSE;
|
||||
|
||||
@@ -389,7 +389,7 @@ node_appendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
static JSBool
|
||||
node_cloneNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *vp)
|
||||
jsval *vp)
|
||||
{
|
||||
JSBool deep;
|
||||
if (!JS_ConvertArguments(cx, argc, argv, "b", &deep))
|
||||
@@ -416,43 +416,43 @@ node_equals(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
|
||||
}
|
||||
|
||||
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},
|
||||
{"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},
|
||||
{"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"},
|
||||
{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}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
static DOM_StyleSelector *
|
||||
GetBaseSelector(JSContext *cx, DOM_StyleDatabase *db, DOM_StyleToken type,
|
||||
DOM_StyleToken pseudo)
|
||||
DOM_StyleToken pseudo)
|
||||
{
|
||||
DOM_StyleSelector *sel = NULL;
|
||||
/* sel = HASH_LOOKUP(db->hashtable, type); */
|
||||
@@ -32,17 +32,17 @@ DestroySelector(JSContext *cx, DOM_StyleSelector *sel)
|
||||
{
|
||||
XP_FREE(sel->selector);
|
||||
if (sel->pseudo)
|
||||
XP_FREE(sel->pseudo);
|
||||
XP_FREE(sel->pseudo);
|
||||
if (sel->rules) {
|
||||
DOM_StyleRule *iter, *next;
|
||||
iter = sel->rules;
|
||||
do {
|
||||
next = iter->next;
|
||||
XP_FREE(iter->entry.name);
|
||||
XP_FREE(iter->entry.value);
|
||||
XP_FREE(iter);
|
||||
iter = next;
|
||||
} while (iter);
|
||||
DOM_StyleRule *iter, *next;
|
||||
iter = sel->rules;
|
||||
do {
|
||||
next = iter->next;
|
||||
XP_FREE(iter->entry.name);
|
||||
XP_FREE(iter->entry.value);
|
||||
XP_FREE(iter);
|
||||
iter = next;
|
||||
} while (iter);
|
||||
}
|
||||
XP_FREE(sel);
|
||||
}
|
||||
@@ -53,29 +53,29 @@ NewSelector(JSContext *cx, DOM_StyleToken selector, DOM_StyleToken pseudo)
|
||||
DOM_StyleSelector *sel;
|
||||
sel = XP_NEW_ZAP(DOM_StyleSelector);
|
||||
if (!sel)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if (selector[0] == '.') {
|
||||
sel->type = SELECTOR_CLASS;
|
||||
selector++;
|
||||
sel->type = SELECTOR_CLASS;
|
||||
selector++;
|
||||
} else if (selector[0] == '#') {
|
||||
sel->type = SELECTOR_ID;
|
||||
selector++;
|
||||
sel->type = SELECTOR_ID;
|
||||
selector++;
|
||||
} else {
|
||||
sel->type = SELECTOR_TAG;
|
||||
sel->type = SELECTOR_TAG;
|
||||
}
|
||||
|
||||
sel->selector = XP_STRDUP(selector);
|
||||
if (!sel->selector) {
|
||||
DestroySelector(cx, sel);
|
||||
return NULL;
|
||||
DestroySelector(cx, sel);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pseudo) {
|
||||
sel->pseudo = XP_STRDUP(pseudo);
|
||||
if (!sel->pseudo) {
|
||||
DestroySelector(cx, sel);
|
||||
return NULL;
|
||||
}
|
||||
sel->pseudo = XP_STRDUP(pseudo);
|
||||
if (!sel->pseudo) {
|
||||
DestroySelector(cx, sel);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return sel;
|
||||
@@ -88,8 +88,8 @@ GetPseudo(JSContext *cx, DOM_Element *element)
|
||||
DOM_AttributeEntry *entry;
|
||||
|
||||
if (!DOM_GetElementAttribute(cx, element, ":pseudoclass", &entry))
|
||||
/* report error? */
|
||||
return NULL;
|
||||
/* report error? */
|
||||
return NULL;
|
||||
return entry ? entry->value : NULL;
|
||||
}
|
||||
|
||||
@@ -98,23 +98,23 @@ GetPseudo(JSContext *cx, DOM_Element *element)
|
||||
|
||||
#define PSEUDO_MATCHES(p1, p2) (!XP_STRCMP((p1), (p2)))
|
||||
|
||||
#define MATCH() \
|
||||
#ifdef DEBUG_shaver \
|
||||
fprintf(stderr, "selector %s:%s matches element %s\n", \
|
||||
sel->selector, sel->pseudo ? sel->pseudo : "", \
|
||||
element->tagName); \
|
||||
#define MATCH() \
|
||||
#ifdef DEBUG_shaver \
|
||||
fprintf(stderr, "selector %s:%s matches element %s\n", \
|
||||
sel->selector, sel->pseudo ? sel->pseudo : "", \
|
||||
element->tagName); \
|
||||
#endif
|
||||
|
||||
#define NO_MATCH() \
|
||||
#ifdef DEBUG_shaver \
|
||||
fprintf(stderr, "selector %s:%s doesn't match element %s\n", \
|
||||
sel->selector, sel->pseudo ? sel->pseudo : "", \
|
||||
element->tagName); \
|
||||
#define NO_MATCH() \
|
||||
#ifdef DEBUG_shaver \
|
||||
fprintf(stderr, "selector %s:%s doesn't match element %s\n", \
|
||||
sel->selector, sel->pseudo ? sel->pseudo : "", \
|
||||
element->tagName); \
|
||||
#endif
|
||||
|
||||
static JSBool
|
||||
SelectorMatchesToken(JSContext *cx, DOM_StyleSelector *sel,
|
||||
DOM_StyleToken token, DOM_StyleToken pseudo)
|
||||
DOM_StyleToken token, DOM_StyleToken pseudo)
|
||||
{
|
||||
/* XXX handle #ID and .class */
|
||||
return !XPSTRCMP(sel->type, token);
|
||||
@@ -122,21 +122,21 @@ SelectorMatchesToken(JSContext *cx, DOM_StyleSelector *sel,
|
||||
|
||||
static JSBool
|
||||
SelectorMatchesElement(JSContext *cx, DOM_Element *element,
|
||||
DOM_StyleSelector *sel)
|
||||
DOM_StyleSelector *sel)
|
||||
{
|
||||
/* XXX handle class and ID */
|
||||
if (ELEMENT_IS_TYPE(element, sel->selector)) {
|
||||
/* check pseudo, if any */
|
||||
if (sel->pseudo) {
|
||||
DOM_StyleToken elementPseudo = GetPseudo(element);
|
||||
if (PSEUDO_MATCHES(sel->pseudo, elementPseudo)) {
|
||||
MATCH();
|
||||
return JS_TRUE;
|
||||
}
|
||||
} else {
|
||||
MATCH();
|
||||
return JS_TRUE;
|
||||
}
|
||||
/* check pseudo, if any */
|
||||
if (sel->pseudo) {
|
||||
DOM_StyleToken elementPseudo = GetPseudo(element);
|
||||
if (PSEUDO_MATCHES(sel->pseudo, elementPseudo)) {
|
||||
MATCH();
|
||||
return JS_TRUE;
|
||||
}
|
||||
} else {
|
||||
MATCH();
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -148,9 +148,9 @@ RuleValueFor(JSContext *cx, DOM_StyleRule *rule, DOM_StyleToken property)
|
||||
{
|
||||
DOM_StyleRule *iter = rule;
|
||||
do {
|
||||
if (!XP_STRCMP(iter->entry.name, property))
|
||||
return &iter->entry;
|
||||
iter = iter->next;
|
||||
if (!XP_STRCMP(iter->entry.name, property))
|
||||
return &iter->entry;
|
||||
iter = iter->next;
|
||||
} while (iter);
|
||||
return NULL;
|
||||
}
|
||||
@@ -160,10 +160,10 @@ static DOM_Element *
|
||||
AncestorOfType(JSContext *cx, DOM_Element *element, DOM_StyleSelector *sel)
|
||||
{
|
||||
do {
|
||||
/* check type */
|
||||
if (SelectorMatchesElement(cx, element, sel))
|
||||
return element;
|
||||
element = (DOM_Element *)element.node->parent;
|
||||
/* check type */
|
||||
if (SelectorMatchesElement(cx, element, sel))
|
||||
return element;
|
||||
element = (DOM_Element *)element.node->parent;
|
||||
} while (element);
|
||||
|
||||
return NULL;
|
||||
@@ -175,70 +175,70 @@ AncestorOfType(JSContext *cx, DOM_Element *element, DOM_StyleSelector *sel)
|
||||
*/
|
||||
static JSBool
|
||||
CheckSelector(JSContext *cx, DOM_Element *element, DOM_StyleSelector *sel,
|
||||
DOM_StyleToken property, DOM_AttributeEntry **entryp,
|
||||
uintN *best, uintN specificity)
|
||||
DOM_StyleToken property, DOM_AttributeEntry **entryp,
|
||||
uintN *best, uintN specificity)
|
||||
{
|
||||
DOM_AttributeEntry *entry;
|
||||
DOM_Element *next;
|
||||
|
||||
/* check self */
|
||||
if (SelectorMatchesElement(cx, element, sel)) {
|
||||
/* if we have rules, maybe get an entry from them */
|
||||
if (sel->rules) {
|
||||
uintN score = SELECTOR_SCORE(sel, specificity);
|
||||
if (score > *best) { /* are we the best so far? */
|
||||
entry = RuleValueFor(sel, property);
|
||||
if (entry) { /* do we have a value for this property? */
|
||||
/* if we have rules, maybe get an entry from them */
|
||||
if (sel->rules) {
|
||||
uintN score = SELECTOR_SCORE(sel, specificity);
|
||||
if (score > *best) { /* are we the best so far? */
|
||||
entry = RuleValueFor(sel, property);
|
||||
if (entry) { /* do we have a value for this property? */
|
||||
#ifdef DEBUG_shaver
|
||||
fprintf(stderr, "- score %d, value %s\n",
|
||||
score, entry->value);
|
||||
fprintf(stderr, "- score %d, value %s\n",
|
||||
score, entry->value);
|
||||
#endif
|
||||
*best = score;
|
||||
*entryp = entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
*best = score;
|
||||
*entryp = entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* now, check our enclosing selector */
|
||||
if (sel->enclosing) {
|
||||
next = AncestorOfType(cx, element, sel->enclosing);
|
||||
if (next)
|
||||
if (!CheckSelector(cx, next, sel->enclosing, property, entryp,
|
||||
best, specificity + 1))
|
||||
return JS_FALSE;
|
||||
}
|
||||
/* now, check our enclosing selector */
|
||||
if (sel->enclosing) {
|
||||
next = AncestorOfType(cx, element, sel->enclosing);
|
||||
if (next)
|
||||
if (!CheckSelector(cx, next, sel->enclosing, property, entryp,
|
||||
best, specificity + 1))
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* check our sibling */
|
||||
if (sel->sibling)
|
||||
if (!CheckSelector(cx, element, sel->sibling, property, entryp,
|
||||
best, specificity))
|
||||
return JS_FALSE;
|
||||
if (!CheckSelector(cx, element, sel->sibling, property, entryp,
|
||||
best, specificity))
|
||||
return JS_FALSE;
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
DOM_StyleGetProperty(JSContext *cx, DOM_StyleDatabase *db,
|
||||
DOM_Node *node, DOM_StyleToken property.
|
||||
DOM_StyleToken pseudo, DOM_AttributeEntry **entryp)
|
||||
DOM_Node *node, DOM_StyleToken property.
|
||||
DOM_StyleToken pseudo, DOM_AttributeEntry **entryp)
|
||||
{
|
||||
DOM_StyleSelector *sel;
|
||||
DOM_Element *element;
|
||||
uintN best = 0;
|
||||
|
||||
if (node->type != NODE_TYPE_ELEMENT) {
|
||||
element = (DOM_Element *)node->parent;
|
||||
XP_ASSERT(element->node.type == NODE_TYPE_ELEMENT);
|
||||
element = (DOM_Element *)node->parent;
|
||||
XP_ASSERT(element->node.type == NODE_TYPE_ELEMENT);
|
||||
} else {
|
||||
element = (DOM_Element *)node;
|
||||
element = (DOM_Element *)node;
|
||||
}
|
||||
|
||||
*entryp = NULL;
|
||||
|
||||
sel = GetBaseSelector(db, element->tagName);
|
||||
if (!sel)
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
|
||||
/*
|
||||
* CheckSelector will recursively find the best match for a given
|
||||
@@ -249,41 +249,41 @@ DOM_StyleGetProperty(JSContext *cx, DOM_StyleDatabase *db,
|
||||
|
||||
DOM_StyleSelector *
|
||||
DOM_StyleFindSelector(JSContext *cx, DOM_StyleDatabase *db,
|
||||
DOM_StyleSelector *base, DOM_StyleToken enclosing,
|
||||
DOM_StyleToken pseudo)
|
||||
DOM_StyleSelector *base, DOM_StyleToken enclosing,
|
||||
DOM_StyleToken pseudo)
|
||||
{
|
||||
DOM_StyleSelector *sel;
|
||||
|
||||
/* looking for the base one */
|
||||
if (!base) {
|
||||
sel = GetBaseSelector(cx, db, enclosing, pseudo);
|
||||
if (!sel)
|
||||
sel = NewSelector(cx, enclosing, pseudo);
|
||||
if (sel)
|
||||
InsertBaseSelector(cx, db, sel);
|
||||
return sel;
|
||||
sel = GetBaseSelector(cx, db, enclosing, pseudo);
|
||||
if (!sel)
|
||||
sel = NewSelector(cx, enclosing, pseudo);
|
||||
if (sel)
|
||||
InsertBaseSelector(cx, db, sel);
|
||||
return sel;
|
||||
}
|
||||
|
||||
if (!base->enclosing) {
|
||||
sel = NewSelector(cx, enclosing, pseudo);
|
||||
if (!sel)
|
||||
return NULL;
|
||||
base->enclosing = sel;
|
||||
return sel;
|
||||
sel = NewSelector(cx, enclosing, pseudo);
|
||||
if (!sel)
|
||||
return NULL;
|
||||
base->enclosing = sel;
|
||||
return sel;
|
||||
}
|
||||
|
||||
/* check existing enclosing selectors */
|
||||
sel = base->enclosing;
|
||||
do {
|
||||
if (SelectorMatchesToken(cx, sel, enclosing, pseudo))
|
||||
return sel;
|
||||
sel = sel->sibling;
|
||||
if (SelectorMatchesToken(cx, sel, enclosing, pseudo))
|
||||
return sel;
|
||||
sel = sel->sibling;
|
||||
} while (sel);
|
||||
|
||||
/* nothing found that matches, so create a new one */
|
||||
sel = NewSelector(cx, enclosing, pseudo);
|
||||
if (!sel)
|
||||
return NULL;
|
||||
return NULL;
|
||||
sel->sibling = base->enclosing;
|
||||
base->enclosing = sel;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -39,10 +39,10 @@ typedef struct DOM_StyleRule DOM_StyleRule;
|
||||
/* this may become int or something later, for speed */
|
||||
typedef const char *DOM_StyleToken;
|
||||
|
||||
#define DOM_STYLE_PSEUDO_TAG (1 << 7)
|
||||
#define DOM_SELECTOR_IS_PSEUDO(sel) ((sel) & DOM_STYLE_PSEUDO_TAG)
|
||||
#define DOM_STYLE_SELECTOR_TYPE(sel) ((sel) & ~DOM_STYLE_PSEUDO_TAG)
|
||||
#define DOM_PSEUDOIZE(sel) ((sel) | DOM_STYLE_PSEUDO_TAG)
|
||||
#define DOM_STYLE_PSEUDO_TAG (1 << 7)
|
||||
#define DOM_SELECTOR_IS_PSEUDO(sel) ((sel) & DOM_STYLE_PSEUDO_TAG)
|
||||
#define DOM_STYLE_SELECTOR_TYPE(sel) ((sel) & ~DOM_STYLE_PSEUDO_TAG)
|
||||
#define DOM_PSEUDOIZE(sel) ((sel) | DOM_STYLE_PSEUDO_TAG)
|
||||
|
||||
enum {
|
||||
SELECTOR_UNKNOWN = 0
|
||||
@@ -110,7 +110,7 @@ struct DOM_StyleRule {
|
||||
|
||||
JSBool
|
||||
DOM_StyleAddRule(JSContext *cx, DOM_StyleDatabase *db, const char *rule,
|
||||
uintN len, intN baseWeight);
|
||||
uintN len, intN baseWeight);
|
||||
|
||||
/*
|
||||
* Get a style property for a node.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; 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
|
||||
@@ -37,14 +37,14 @@ cdata_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
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;
|
||||
@@ -73,17 +73,17 @@ cdata_setter(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_setter(cx, obj, id, vp);
|
||||
}
|
||||
|
||||
|
||||
cdata = (DOM_CharacterData *)JS_GetPrivate(cx, obj);
|
||||
if (!cdata)
|
||||
return JS_TRUE;
|
||||
@@ -118,7 +118,7 @@ cdata_substringData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
cdata = (DOM_CharacterData *)JS_GetPrivate(cx, obj);
|
||||
if (!cdata) {
|
||||
*vp = STRING_TO_JSVAL(JS_GetEmptyStringValue(cx));
|
||||
*vp = JS_GetEmptyStringValue(cx);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -129,11 +129,11 @@ cdata_substringData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
if (offset + count > cdata->len)
|
||||
count = cdata->len - offset;
|
||||
|
||||
|
||||
substr = JS_NewStringCopyN(cx, cdata->data + offset, count);
|
||||
if (!substr)
|
||||
return JS_FALSE;
|
||||
|
||||
|
||||
*vp = STRING_TO_JSVAL(substr);
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -143,8 +143,9 @@ cdata_appendData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *vp)
|
||||
{
|
||||
JSString *newData;
|
||||
uint32 newlen;
|
||||
DOM_CharacterData *cdata;
|
||||
uint32 newlen;
|
||||
char *data2;
|
||||
|
||||
if (!JS_ConvertArguments(cx, argc, argv, "S", &newData))
|
||||
return JS_FALSE;
|
||||
@@ -155,14 +156,14 @@ cdata_appendData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
newlen = JS_GetStringLength(newData);
|
||||
|
||||
cdata->data = XP_REALLOC(cdata->data, cdata->len + newlen);
|
||||
if (!cdata->data)
|
||||
data2 = XP_REALLOC(cdata->data, cdata->len + newlen);
|
||||
if (!data2)
|
||||
return JS_FALSE;
|
||||
|
||||
XP_MEMCPY(cdata->data + cdata->len, JS_GetStringBytes(newData),
|
||||
newlen);
|
||||
XP_MEMCPY(data2 + cdata->len, JS_GetStringBytes(newData), newlen);
|
||||
cdata->data = data2;
|
||||
cdata->len += newlen;
|
||||
|
||||
|
||||
return cdata->notify(cx, cdata, CDATA_APPEND);
|
||||
}
|
||||
|
||||
@@ -289,8 +290,8 @@ static JSClass DOM_CDataClass = {
|
||||
};
|
||||
|
||||
static JSPropertySpec cdata_props[] = {
|
||||
{"data", DOM_CDATA_DATA, JSPROP_ENUMERATE, 0, 0},
|
||||
{"length", DOM_CDATA_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY,
|
||||
{"data", DOM_CDATA_DATA, JSPROP_ENUMERATE, 0, 0},
|
||||
{"length", DOM_CDATA_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY,
|
||||
0, 0},
|
||||
{0}
|
||||
};
|
||||
@@ -299,7 +300,7 @@ static JSFunctionSpec cdata_methods[] = {
|
||||
{"substringData", cdata_substringData, 2},
|
||||
{"appendData", cdata_appendData, 1},
|
||||
{"insertData", cdata_insertData, 2},
|
||||
{"deleteData", cdata_deleteData, 2},
|
||||
{"deleteData", cdata_deleteData, 2},
|
||||
{"replaceData", cdata_replaceData, 3},
|
||||
{0}
|
||||
};
|
||||
@@ -316,9 +317,9 @@ 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);
|
||||
CharacterData, 0,
|
||||
cdata_props, cdata_methods,
|
||||
NULL, NULL);
|
||||
return proto;
|
||||
}
|
||||
|
||||
@@ -388,7 +389,7 @@ DOM_ObjectForText(JSContext *cx, DOM_Text *text)
|
||||
|
||||
if (text->cdata.node.mocha_object)
|
||||
return text->cdata.node.mocha_object;
|
||||
|
||||
|
||||
return DOM_NewTextObject(cx, text);
|
||||
}
|
||||
|
||||
@@ -403,9 +404,9 @@ dom_TextInit(JSContext *cx, JSObject *scope, JSObject *cdata_proto)
|
||||
{
|
||||
JSObject *proto;
|
||||
proto = JS_InitClass(cx, scope, cdata_proto, &DOM_TextClass,
|
||||
Text, 0,
|
||||
cdata_props, text_methods,
|
||||
NULL, NULL);
|
||||
Text, 0,
|
||||
cdata_props, text_methods,
|
||||
NULL, NULL);
|
||||
return proto;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user