This commit is contained in:
Andreas Gal 2010-04-23 20:49:28 -07:00
commit 73003f00f7
9 changed files with 130 additions and 203 deletions

View File

@ -1377,7 +1377,7 @@ js_InternNonIntElementId(JSContext *cx, JSObject *obj, jsval idval, jsid *idp)
#if JS_HAS_XML_SUPPORT
if (!JSVAL_IS_PRIMITIVE(idval)) {
if (obj->isXML()) {
if (OBJECT_IS_XML(cx, obj)) {
*idp = OBJECT_JSVAL_TO_JSID(idval);
return JS_TRUE;
}

View File

@ -111,7 +111,7 @@ CloseNativeIterator(JSContext *cx, JSObject *iterobj)
if (iterable) {
#if JS_HAS_XML_SUPPORT
uintN flags = JSVAL_TO_INT(iterobj->getSlot(JSSLOT_ITER_FLAGS));
if ((flags & JSITER_FOREACH) && iterable->isXML()) {
if ((flags & JSITER_FOREACH) && OBJECT_IS_XML(cx, iterable)) {
js_EnumerateXMLValues(cx, iterable, JSENUMERATE_DESTROY, &state,
NULL, NULL);
} else
@ -173,7 +173,7 @@ InitNativeIterator(JSContext *cx, JSObject *iterobj, JSObject *obj, uintN flags)
ok =
#if JS_HAS_XML_SUPPORT
((flags & JSITER_FOREACH) && obj->isXML())
((flags & JSITER_FOREACH) && OBJECT_IS_XML(cx, obj))
? js_EnumerateXMLValues(cx, obj, JSENUMERATE_INIT, &state, NULL, NULL)
:
#endif
@ -250,7 +250,7 @@ IteratorNextImpl(JSContext *cx, JSObject *obj, jsval *rval)
foreach = (flags & JSITER_FOREACH) != 0;
ok =
#if JS_HAS_XML_SUPPORT
(foreach && iterable->isXML())
(foreach && OBJECT_IS_XML(cx, iterable))
? js_EnumerateXMLValues(cx, iterable, JSENUMERATE_NEXT, &state,
&id, rval)
:
@ -265,7 +265,7 @@ IteratorNextImpl(JSContext *cx, JSObject *obj, jsval *rval)
if (foreach) {
#if JS_HAS_XML_SUPPORT
if (!iterable->isXML() &&
if (!OBJECT_IS_XML(cx, iterable) &&
!iterable->getProperty(cx, id, rval)) {
return JS_FALSE;
}
@ -501,7 +501,7 @@ CallEnumeratorNext(JSContext *cx, JSObject *iterobj, uintN flags, jsval *rval)
* Treat an XML object specially only when it starts the prototype chain.
* Otherwise we need to do the usual deleted and shadowed property checks.
*/
if (obj == origobj && obj->isXML()) {
if (obj == origobj && OBJECT_IS_XML(cx, obj)) {
if (foreach) {
if (!js_EnumerateXMLValues(cx, obj, JSENUMERATE_NEXT, &state,
&id, rval)) {
@ -524,7 +524,7 @@ CallEnumeratorNext(JSContext *cx, JSObject *iterobj, uintN flags, jsval *rval)
iterobj->setSlot(JSSLOT_ITER_STATE, state);
if (JSVAL_IS_NULL(state)) {
#if JS_HAS_XML_SUPPORT
if (obj->isXML()) {
if (OBJECT_IS_XML(cx, obj)) {
/*
* We just finished enumerating an XML obj that is present on
* the prototype chain of a non-XML origobj. Stop further
@ -532,7 +532,7 @@ CallEnumeratorNext(JSContext *cx, JSObject *iterobj, uintN flags, jsval *rval)
* enumerate prototypes.
*/
JS_ASSERT(origobj != obj);
JS_ASSERT(!origobj->isXML());
JS_ASSERT(!OBJECT_IS_XML(cx, origobj));
} else
#endif
{

View File

@ -4896,7 +4896,7 @@ js_GetMethod(JSContext *cx, JSObject *obj, jsid id, uintN getHow, jsval *vp)
}
JS_ASSERT_IF(getHow & JSGET_CACHE_RESULT, obj->isDenseArray());
#if JS_HAS_XML_SUPPORT
if (obj->isXML())
if (OBJECT_IS_XML(cx, obj))
return js_GetXMLMethod(cx, obj, id, vp);
#endif
return obj->getProperty(cx, id, vp);

View File

@ -493,41 +493,6 @@ struct JSObject {
inline jsval *addressOfRegExpLastIndex();
inline void zeroRegExpLastIndex();
/*
* XML-related getters and setters.
*/
/*
* Slots for XML-related classes are as follows:
* - js_NamespaceClass.base reserves the *_NAME_* and *_NAMESPACE_* slots.
* - js_QNameClass.base, js_AttributeNameClass, js_AnyNameClass reserve
* the *_NAME_* and *_QNAME_* slots.
* - Others (js_XMLClass, js_XMLFilterClass) don't reserve any slots.
*/
private:
static const uint32 JSSLOT_NAME_PREFIX = JSSLOT_PRIVATE; // shared
static const uint32 JSSLOT_NAME_URI = JSSLOT_PRIVATE + 1; // shared
static const uint32 JSSLOT_NAMESPACE_DECLARED = JSSLOT_PRIVATE + 2;
static const uint32 JSSLOT_QNAME_LOCAL_NAME = JSSLOT_PRIVATE + 2;
public:
static const uint32 NAMESPACE_FIXED_RESERVED_SLOTS = 3;
static const uint32 QNAME_FIXED_RESERVED_SLOTS = 3;
inline jsval getNamePrefix() const;
inline void setNamePrefix(jsval prefix);
inline jsval getNameURI() const;
inline void setNameURI(jsval uri);
inline jsval getNamespaceDeclared() const;
inline void setNamespaceDeclared(jsval decl);
inline jsval getQNameLocalName() const;
inline void setQNameLocalName(jsval decl);
/*
* Back to generic stuff.
*/
@ -640,8 +605,6 @@ struct JSObject {
inline bool isFunction() const;
inline bool isRegExp() const;
inline bool isXML() const;
inline bool isNamespace() const;
inline bool isQName() const;
inline bool unbrand(JSContext *cx);
};

View File

@ -46,7 +46,6 @@
#include "jsiter.h"
#include "jsobj.h"
#include "jsscope.h"
#include "jsxml.h"
#ifdef INCLUDE_MOZILLA_DTRACE
#include "jsdtracef.h"
@ -285,62 +284,6 @@ JSObject::zeroRegExpLastIndex()
fslots[JSSLOT_REGEXP_LAST_INDEX] = JSVAL_ZERO;
}
inline jsval
JSObject::getNamePrefix() const
{
JS_ASSERT(isNamespace() || isQName());
return fslots[JSSLOT_NAME_PREFIX];
}
inline void
JSObject::setNamePrefix(jsval prefix)
{
JS_ASSERT(isNamespace() || isQName());
fslots[JSSLOT_NAME_PREFIX] = prefix;
}
inline jsval
JSObject::getNameURI() const
{
JS_ASSERT(isNamespace() || isQName());
return fslots[JSSLOT_NAME_URI];
}
inline void
JSObject::setNameURI(jsval uri)
{
JS_ASSERT(isNamespace() || isQName());
fslots[JSSLOT_NAME_URI] = uri;
}
inline jsval
JSObject::getNamespaceDeclared() const
{
JS_ASSERT(isNamespace());
return fslots[JSSLOT_NAMESPACE_DECLARED];
}
inline void
JSObject::setNamespaceDeclared(jsval decl)
{
JS_ASSERT(isNamespace());
fslots[JSSLOT_NAMESPACE_DECLARED] = decl;
}
inline jsval
JSObject::getQNameLocalName() const
{
JS_ASSERT(isQName());
return fslots[JSSLOT_QNAME_LOCAL_NAME];
}
inline void
JSObject::setQNameLocalName(jsval name)
{
JS_ASSERT(isQName());
fslots[JSSLOT_QNAME_LOCAL_NAME] = name;
}
inline void
JSObject::initSharingEmptyScope(JSClass *clasp, JSObject *proto, JSObject *parent,
jsval privateSlotValue)

View File

@ -498,7 +498,7 @@ Str(JSContext *cx, jsid id, JSObject *holder, StringifyContext *scx, jsval *vp,
return scx->cb.append(dstr, dbufSize);
}
if (JSVAL_IS_OBJECT(*vp) && !VALUE_IS_FUNCTION(cx, *vp) && !VALUE_IS_XML(*vp)) {
if (JSVAL_IS_OBJECT(*vp) && !VALUE_IS_FUNCTION(cx, *vp) && !VALUE_IS_XML(cx, *vp)) {
JSBool ok;
scx->depth++;

View File

@ -785,10 +785,10 @@ END_CASE(JSOP_BITAND)
#define XML_EQUALITY_OP(OP) \
if ((ltmp == JSVAL_OBJECT && \
(obj2 = JSVAL_TO_OBJECT(lval)) && \
obj2->isXML()) || \
OBJECT_IS_XML(cx, obj2)) || \
(rtmp == JSVAL_OBJECT && \
(obj2 = JSVAL_TO_OBJECT(rval)) && \
obj2->isXML())) { \
OBJECT_IS_XML(cx, obj2))) { \
if (JSVAL_IS_OBJECT(rval) && obj2 == JSVAL_TO_OBJECT(rval)) \
rval = lval; \
if (!js_TestXMLEquality(cx, obj2, rval, &cond)) \
@ -963,8 +963,8 @@ BEGIN_CASE(JSOP_ADD)
lval = FETCH_OPND(-2);
#if JS_HAS_XML_SUPPORT
if (!JSVAL_IS_PRIMITIVE(lval) &&
(obj2 = JSVAL_TO_OBJECT(lval), obj2->isXML()) &&
VALUE_IS_XML(rval)) {
(obj2 = JSVAL_TO_OBJECT(lval), OBJECT_IS_XML(cx, obj2)) &&
VALUE_IS_XML(cx, rval)) {
if (!js_ConcatenateXML(cx, obj2, rval, &rval))
goto error;
regs.sp--;
@ -3828,7 +3828,7 @@ BEGIN_CASE(JSOP_ENDFILTER)
* Decrease sp after EnterWith returns as we use sp[-1] there to root
* temporaries.
*/
JS_ASSERT(VALUE_IS_XML(regs.sp[-1]));
JS_ASSERT(VALUE_IS_XML(cx, regs.sp[-1]));
if (!js_EnterWith(cx, -2))
goto error;
regs.sp--;
@ -3865,7 +3865,7 @@ END_CASE(JSOP_XMLTAGEXPR)
BEGIN_CASE(JSOP_XMLELTEXPR)
rval = FETCH_OPND(-1);
if (VALUE_IS_XML(rval)) {
if (VALUE_IS_XML(cx, rval)) {
str = js_ValueToXMLString(cx, rval);
} else {
str = js_ValueToString(cx, rval);

View File

@ -125,37 +125,66 @@ const char js_leftcurly_entity_str[] = "{";
#define IS_STAR(str) ((str)->length() == 1 && *(str)->chars() == '*')
/* Slot indexes shared between Namespace and QName objects. */
const uint32 JSSLOT_PREFIX = JSSLOT_PRIVATE;
const uint32 JSSLOT_URI = JSSLOT_PRIVATE + 1;
/* Namespace-specific slot. */
const uint32 JSSLOT_DECLARED = JSSLOT_PRIVATE + 2;
/* QName-specific slot. */
const uint32 JSSLOT_LOCAL_NAME = JSSLOT_PRIVATE + 2;
const uint32 NAMESPACE_RESERVED_SLOTS = 3;
const uint32 QNAME_RESERVED_SLOTS = 3;
static JSBool
GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
static JS_INLINE JSString *
GetPrefix(const JSObject *obj)
static JSBool
IsQNameClass(JSClass *clasp)
{
jsval v = obj->getNamePrefix();
return clasp == &js_QNameClass.base ||
clasp == &js_AttributeNameClass ||
clasp == &js_AnyNameClass;
}
static JSString *
GetSlotString(const JSObject *obj, uint32 slot)
{
jsval v;
JS_ASSERT(slot == JSSLOT_PREFIX ||
slot == JSSLOT_URI ||
slot == JSSLOT_LOCAL_NAME);
JS_ASSERT(obj->getClass() == &js_NamespaceClass.base ||
IsQNameClass(obj->getClass()));
JS_ASSERT_IF(obj->getClass() == &js_NamespaceClass.base,
slot != JSSLOT_LOCAL_NAME);
v = obj->fslots[slot];
if (JSVAL_IS_VOID(v))
return NULL;
JS_ASSERT(JSVAL_IS_STRING(v));
return JSVAL_TO_STRING(v);
}
static JS_INLINE JSString *
GetPrefix(const JSObject *obj)
{
return GetSlotString(obj, JSSLOT_PREFIX);
}
static JSString *
GetURI(const JSObject *obj)
{
jsval v = obj->getNameURI();
if (JSVAL_IS_VOID(v))
return NULL;
JS_ASSERT(JSVAL_IS_STRING(v));
return JSVAL_TO_STRING(v);
return GetSlotString(obj, JSSLOT_URI);
}
static JSString *
GetLocalName(const JSObject *obj)
{
jsval v = obj->getQNameLocalName();
if (JSVAL_IS_VOID(v))
return NULL;
JS_ASSERT(JSVAL_IS_STRING(v));
return JSVAL_TO_STRING(v);
return GetSlotString(obj, JSSLOT_LOCAL_NAME);
}
static JSBool
@ -164,7 +193,7 @@ IsDeclared(const JSObject *obj)
jsval v;
JS_ASSERT(obj->getClass() == &js_NamespaceClass.base);
v = obj->getNamespaceDeclared();
v = obj->fslots[JSSLOT_DECLARED];
JS_ASSERT(JSVAL_IS_VOID(v) || v == JSVAL_TRUE);
return v == JSVAL_TRUE;
}
@ -204,10 +233,10 @@ namespace_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
switch (JSVAL_TO_INT(id)) {
case NAMESPACE_PREFIX:
*vp = obj->getNamePrefix();
*vp = obj->fslots[JSSLOT_PREFIX];
break;
case NAMESPACE_URI:
*vp = obj->getNameURI();
*vp = obj->fslots[JSSLOT_URI];
break;
}
return JS_TRUE;
@ -236,7 +265,7 @@ namespace_equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
JS_FRIEND_DATA(JSExtendedClass) js_NamespaceClass = {
{ "Namespace",
JSCLASS_CONSTRUCT_PROTOTYPE | JSCLASS_IS_EXTENDED |
JSCLASS_HAS_RESERVED_SLOTS(JSObject::NAMESPACE_FIXED_RESERVED_SLOTS) |
JSCLASS_HAS_RESERVED_SLOTS(NAMESPACE_RESERVED_SLOTS) |
JSCLASS_MARK_IS_TRACE | JSCLASS_HAS_CACHED_PROTO(JSProto_Namespace),
JS_PropertyStub, JS_PropertyStub, namespace_getProperty, NULL,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, namespace_finalize,
@ -263,7 +292,7 @@ namespace_toString(JSContext *cx, uintN argc, jsval *vp)
obj = JS_THIS_OBJECT(cx, vp);
if (!JS_InstanceOf(cx, obj, &js_NamespaceClass.base, vp))
return JS_FALSE;
*vp = obj->getNameURI();
*vp = obj->fslots[JSSLOT_URI];
return JS_TRUE;
}
@ -280,15 +309,15 @@ NewXMLNamespace(JSContext *cx, JSString *prefix, JSString *uri, JSBool declared)
obj = NewObject(cx, &js_NamespaceClass.base, NULL, NULL);
if (!obj)
return JS_FALSE;
JS_ASSERT(JSVAL_IS_VOID(obj->getNamePrefix()));
JS_ASSERT(JSVAL_IS_VOID(obj->getNameURI()));
JS_ASSERT(JSVAL_IS_VOID(obj->getNamespaceDeclared()));
JS_ASSERT(JSVAL_IS_VOID(obj->fslots[JSSLOT_PREFIX]));
JS_ASSERT(JSVAL_IS_VOID(obj->fslots[JSSLOT_URI]));
JS_ASSERT(JSVAL_IS_VOID(obj->fslots[JSSLOT_DECLARED]));
if (prefix)
obj->setNamePrefix(STRING_TO_JSVAL(prefix));
obj->fslots[JSSLOT_PREFIX] = STRING_TO_JSVAL(prefix);
if (uri)
obj->setNameURI(STRING_TO_JSVAL(uri));
obj->fslots[JSSLOT_URI] = STRING_TO_JSVAL(uri);
if (declared)
obj->setNamespaceDeclared(JSVAL_TRUE);
obj->fslots[JSSLOT_DECLARED] = JSVAL_TRUE;
METER(xml_stats.xmlnamespace);
return obj;
}
@ -312,12 +341,12 @@ qname_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
switch (JSVAL_TO_INT(id)) {
case QNAME_URI:
*vp = obj->getNameURI();
*vp = obj->fslots[JSSLOT_URI];
if (*vp == JSVAL_VOID)
*vp = JSVAL_NULL;
break;
case QNAME_LOCALNAME:
*vp = obj->getQNameLocalName();
*vp = obj->fslots[JSSLOT_LOCAL_NAME];
break;
}
return JS_TRUE;
@ -360,7 +389,7 @@ qname_equality(JSContext *cx, JSObject *qn, jsval v, JSBool *bp)
JS_FRIEND_DATA(JSExtendedClass) js_QNameClass = {
{ "QName",
JSCLASS_CONSTRUCT_PROTOTYPE | JSCLASS_IS_EXTENDED |
JSCLASS_HAS_RESERVED_SLOTS(JSObject::QNAME_FIXED_RESERVED_SLOTS) |
JSCLASS_HAS_RESERVED_SLOTS(QNAME_RESERVED_SLOTS) |
JSCLASS_MARK_IS_TRACE | JSCLASS_HAS_CACHED_PROTO(JSProto_QName),
JS_PropertyStub, JS_PropertyStub, qname_getProperty, NULL,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
@ -379,7 +408,7 @@ JS_FRIEND_DATA(JSExtendedClass) js_QNameClass = {
JS_FRIEND_DATA(JSClass) js_AttributeNameClass = {
js_AttributeName_str,
JSCLASS_CONSTRUCT_PROTOTYPE |
JSCLASS_HAS_RESERVED_SLOTS(JSObject::QNAME_FIXED_RESERVED_SLOTS) |
JSCLASS_HAS_RESERVED_SLOTS(QNAME_RESERVED_SLOTS) |
JSCLASS_MARK_IS_TRACE | JSCLASS_HAS_CACHED_PROTO(JSProto_AttributeName),
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
@ -390,7 +419,7 @@ JS_FRIEND_DATA(JSClass) js_AttributeNameClass = {
JS_FRIEND_DATA(JSClass) js_AnyNameClass = {
js_AnyName_str,
JSCLASS_CONSTRUCT_PROTOTYPE |
JSCLASS_HAS_RESERVED_SLOTS(JSObject::QNAME_FIXED_RESERVED_SLOTS) |
JSCLASS_HAS_RESERVED_SLOTS(QNAME_RESERVED_SLOTS) |
JSCLASS_MARK_IS_TRACE | JSCLASS_HAS_CACHED_PROTO(JSProto_AnyName),
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, anyname_finalize,
@ -472,15 +501,15 @@ static void
InitXMLQName(JSObject *obj, JSString *uri, JSString *prefix,
JSString *localName)
{
JS_ASSERT(JSVAL_IS_VOID(obj->getNamePrefix()));
JS_ASSERT(JSVAL_IS_VOID(obj->getNameURI()));
JS_ASSERT(JSVAL_IS_VOID(obj->getQNameLocalName()));
JS_ASSERT(JSVAL_IS_VOID(obj->fslots[JSSLOT_PREFIX]));
JS_ASSERT(JSVAL_IS_VOID(obj->fslots[JSSLOT_URI]));
JS_ASSERT(JSVAL_IS_VOID(obj->fslots[JSSLOT_LOCAL_NAME]));
if (uri)
obj->setNameURI(STRING_TO_JSVAL(uri));
obj->fslots[JSSLOT_URI] = STRING_TO_JSVAL(uri);
if (prefix)
obj->setNamePrefix(STRING_TO_JSVAL(prefix));
obj->fslots[JSSLOT_PREFIX] = STRING_TO_JSVAL(prefix);
if (localName)
obj->setQNameLocalName(STRING_TO_JSVAL(localName));
obj->fslots[JSSLOT_LOCAL_NAME] = STRING_TO_JSVAL(localName);
}
static JSObject *
@ -489,8 +518,8 @@ NewXMLQName(JSContext *cx, JSString *uri, JSString *prefix, JSString *localName,
{
JSObject *obj;
JS_ASSERT(IsQNameClass(clasp));
obj = NewObject(cx, clasp, NULL, NULL);
JS_ASSERT(obj->isQName());
if (!obj)
return NULL;
InitXMLQName(obj, uri, prefix, localName);
@ -549,7 +578,7 @@ js_IsXMLName(JSContext *cx, jsval v)
* See ECMA-357 13.1.2.1 step 1 and 13.3.2.
*/
if (!JSVAL_IS_PRIMITIVE(v) &&
JSVAL_TO_OBJECT(v)->isQName()) {
IsQNameClass(JSVAL_TO_OBJECT(v)->getClass())) {
name = GetLocalName(JSVAL_TO_OBJECT(v));
} else {
older = JS_SetErrorReporter(cx, NULL);
@ -610,23 +639,23 @@ NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
METER(xml_stats.xmlnamespace);
empty = cx->runtime->emptyString;
obj->setNamePrefix(STRING_TO_JSVAL(empty));
obj->setNameURI(STRING_TO_JSVAL(empty));
obj->fslots[JSSLOT_PREFIX] = STRING_TO_JSVAL(empty);
obj->fslots[JSSLOT_URI] = STRING_TO_JSVAL(empty);
if (argc == 1 || argc == -1) {
if (isNamespace) {
obj->setNameURI(uriobj->getNameURI());
obj->setNamePrefix(uriobj->getNamePrefix());
obj->fslots[JSSLOT_URI] = uriobj->fslots[JSSLOT_URI];
obj->fslots[JSSLOT_PREFIX] = uriobj->fslots[JSSLOT_PREFIX];
} else if (isQName && (uri = GetURI(uriobj))) {
obj->setNameURI(STRING_TO_JSVAL(uri));
obj->setNamePrefix(uriobj->getNamePrefix());
obj->fslots[JSSLOT_URI] = STRING_TO_JSVAL(uri);
obj->fslots[JSSLOT_PREFIX] = uriobj->fslots[JSSLOT_PREFIX];
} else {
uri = js_ValueToString(cx, urival);
if (!uri)
return JS_FALSE;
obj->setNameURI(STRING_TO_JSVAL(uri));
obj->fslots[JSSLOT_URI] = STRING_TO_JSVAL(uri);
if (!uri->empty())
obj->setNamePrefix(JSVAL_VOID);
obj->fslots[JSSLOT_PREFIX] = JSVAL_VOID;
}
} else if (argc == 2) {
if (!isQName || !(uri = GetURI(uriobj))) {
@ -634,7 +663,7 @@ NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
if (!uri)
return JS_FALSE;
}
obj->setNameURI(STRING_TO_JSVAL(uri));
obj->fslots[JSSLOT_URI] = STRING_TO_JSVAL(uri);
prefixval = argv[0];
if (uri->empty()) {
@ -651,12 +680,12 @@ NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
}
}
} else if (JSVAL_IS_VOID(prefixval) || !js_IsXMLName(cx, prefixval)) {
obj->setNamePrefix(JSVAL_VOID);
obj->fslots[JSSLOT_PREFIX] = JSVAL_VOID;
} else {
prefix = js_ValueToString(cx, prefixval);
if (!prefix)
return JS_FALSE;
obj->setNamePrefix(STRING_TO_JSVAL(prefix));
obj->fslots[JSSLOT_PREFIX] = STRING_TO_JSVAL(prefix);
}
}
@ -727,7 +756,7 @@ QNameHelper(JSContext *cx, JSObject *obj, JSClass *clasp, intN argc,
}
/* Namespace and qname were passed -- use the qname's localName. */
nameval = qn->getQNameLocalName();
nameval = qn->fslots[JSSLOT_LOCAL_NAME];
}
if (argc == 0) {
@ -1864,7 +1893,7 @@ OrphanXMLChild(JSContext *cx, JSXML *xml, uint32 i)
if (xml->xml_class == JSXML_CLASS_ELEMENT) {
if (!XMLARRAY_APPEND(cx, &xml->xml_namespaces, ns))
return NULL;
ns->setNamespaceDeclared(JSVAL_VOID);
ns->fslots[JSSLOT_DECLARED] = JSVAL_VOID;
}
xml->parent = NULL;
return xml;
@ -1884,7 +1913,7 @@ ToXML(JSContext *cx, jsval v)
goto bad;
} else {
obj = JSVAL_TO_OBJECT(v);
if (obj->isXML()) {
if (OBJECT_IS_XML(cx, obj)) {
xml = (JSXML *) obj->getPrivate();
if (xml->xml_class == JSXML_CLASS_LIST) {
if (xml->xml_kids.length != 1)
@ -1965,7 +1994,7 @@ ToXMLList(JSContext *cx, jsval v)
goto bad;
} else {
obj = JSVAL_TO_OBJECT(v);
if (obj->isXML()) {
if (OBJECT_IS_XML(cx, obj)) {
xml = (JSXML *) obj->getPrivate();
if (xml->xml_class != JSXML_CLASS_LIST) {
listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
@ -2693,7 +2722,7 @@ XMLToXMLString(JSContext *cx, JSXML *xml, const JSXMLArray *ancestorNSes,
prefix = GeneratePrefix(cx, GetURI(ns3), &ancdecls);
if (!prefix)
goto out;
ns3->setNamePrefix(STRING_TO_JSVAL(prefix));
ns3->fslots[JSSLOT_PREFIX] = STRING_TO_JSVAL(prefix);
}
/* 17(c)(iii). */
@ -2803,7 +2832,7 @@ ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
}
obj = JSVAL_TO_OBJECT(v);
if (!obj->isXML()) {
if (!OBJECT_IS_XML(cx, obj)) {
if (!obj->defaultValue(cx, JSTYPE_STRING, &v))
return NULL;
str = js_ValueToString(cx, v);
@ -3011,7 +3040,7 @@ AddInScopeNamespace(JSContext *cx, JSXML *xml, JSObject *ns)
ns2 = XMLARRAY_DELETE(cx, &xml->xml_namespaces, m, JS_TRUE,
JSObject);
JS_ASSERT(ns2 == match);
match->setNamePrefix(JSVAL_VOID);
match->fslots[JSSLOT_PREFIX] = JSVAL_VOID;
if (!AddInScopeNamespace(cx, xml, match))
return JS_FALSE;
}
@ -3454,7 +3483,7 @@ Equals(JSContext *cx, JSXML *xml, jsval v, JSBool *bp)
}
} else {
vobj = JSVAL_TO_OBJECT(v);
if (!vobj->isXML()) {
if (!OBJECT_IS_XML(cx, vobj)) {
*bp = JS_FALSE;
} else {
vxml = (JSXML *) vobj->getPrivate();
@ -3497,7 +3526,7 @@ Insert(JSContext *cx, JSXML *xml, uint32 i, jsval v)
vxml = NULL;
if (!JSVAL_IS_PRIMITIVE(v)) {
vobj = JSVAL_TO_OBJECT(v);
if (vobj->isXML()) {
if (OBJECT_IS_XML(cx, vobj)) {
vxml = (JSXML *) vobj->getPrivate();
if (vxml->xml_class == JSXML_CLASS_LIST) {
n = vxml->xml_kids.length;
@ -3591,7 +3620,7 @@ Replace(JSContext *cx, JSXML *xml, uint32 i, jsval v)
vxml = NULL;
if (!JSVAL_IS_PRIMITIVE(v)) {
vobj = JSVAL_TO_OBJECT(v);
if (vobj->isXML())
if (OBJECT_IS_XML(cx, vobj))
vxml = (JSXML *) vobj->getPrivate();
}
@ -3912,7 +3941,7 @@ PutProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
vxml = NULL;
if (!JSVAL_IS_PRIMITIVE(*vp)) {
vobj = JSVAL_TO_OBJECT(*vp);
if (vobj->isXML())
if (OBJECT_IS_XML(cx, vobj))
vxml = (JSXML *) vobj->getPrivate();
}
@ -5138,7 +5167,7 @@ js_TestXMLEquality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
vxml = NULL;
if (!JSVAL_IS_PRIMITIVE(v)) {
vobj = JSVAL_TO_OBJECT(v);
if (vobj->isXML())
if (OBJECT_IS_XML(cx, vobj))
vxml = (JSXML *) vobj->getPrivate();
}
@ -5223,7 +5252,7 @@ js_ConcatenateXML(JSContext *cx, JSObject *obj, jsval v, jsval *vp)
if (!ok)
goto out;
if (VALUE_IS_XML(v)) {
if (VALUE_IS_XML(cx, v)) {
rxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
} else {
robj = ToXML(cx, v);
@ -5339,7 +5368,7 @@ xml_addNamespace(JSContext *cx, uintN argc, jsval *vp)
ns = JSVAL_TO_OBJECT(*vp);
if (!AddInScopeNamespace(cx, xml, ns))
return JS_FALSE;
ns->setNamespaceDeclared(JSVAL_TRUE);
ns->fslots[JSSLOT_DECLARED] = JSVAL_TRUE;
done:
*vp = OBJECT_TO_JSVAL(obj);
@ -5366,7 +5395,7 @@ xml_appendChild(JSContext *cx, uintN argc, jsval *vp)
JS_ASSERT(!JSVAL_IS_PRIMITIVE(v));
vobj = JSVAL_TO_OBJECT(v);
JS_ASSERT(vobj->isXML());
JS_ASSERT(OBJECT_IS_XML(cx, vobj));
vxml = (JSXML *) vobj->getPrivate();
JS_ASSERT(vxml->xml_class == JSXML_CLASS_LIST);
@ -5917,7 +5946,7 @@ xml_insertChildAfter(JSContext *cx, uintN argc, jsval *vp)
kid = NULL;
i = 0;
} else {
if (!VALUE_IS_XML(arg))
if (!VALUE_IS_XML(cx, arg))
return JS_TRUE;
kid = (JSXML *) JSVAL_TO_OBJECT(arg)->getPrivate();
i = XMLARRAY_FIND_MEMBER(&xml->xml_kids, kid, NULL);
@ -5949,7 +5978,7 @@ xml_insertChildBefore(JSContext *cx, uintN argc, jsval *vp)
kid = NULL;
i = xml->xml_kids.length;
} else {
if (!VALUE_IS_XML(arg))
if (!VALUE_IS_XML(cx, arg))
return JS_TRUE;
kid = (JSXML *) JSVAL_TO_OBJECT(arg)->getPrivate();
i = XMLARRAY_FIND_MEMBER(&xml->xml_kids, kid, NULL);
@ -5981,7 +6010,7 @@ static JSBool
xml_localName(JSContext *cx, uintN argc, jsval *vp)
{
NON_LIST_XML_METHOD_PROLOG;
*vp = xml->name ? xml->name->getQNameLocalName() : JSVAL_NULL;
*vp = xml->name ? xml->name->fslots[JSSLOT_LOCAL_NAME] : JSVAL_NULL;
return JS_TRUE;
}
@ -6416,7 +6445,7 @@ xml_replace(JSContext *cx, uintN argc, jsval *vp)
typeAtoms[JSTYPE_VOID]));
} else {
value = vp[3];
vxml = VALUE_IS_XML(value)
vxml = VALUE_IS_XML(cx, value)
? (JSXML *) JSVAL_TO_OBJECT(value)->getPrivate()
: NULL;
if (!vxml) {
@ -6517,7 +6546,9 @@ xml_setLocalName(JSContext *cx, uintN argc, jsval *vp)
xml = CHECK_COPY_ON_WRITE(cx, xml, obj);
if (!xml)
return JS_FALSE;
xml->name->setQNameLocalName(namestr ? STRING_TO_JSVAL(namestr) : JSVAL_VOID);
xml->name->fslots[JSSLOT_LOCAL_NAME] = namestr
? STRING_TO_JSVAL(namestr)
: JSVAL_VOID;
return JS_TRUE;
}
@ -6543,7 +6574,7 @@ xml_setName(JSContext *cx, uintN argc, jsval *vp)
if (!JSVAL_IS_PRIMITIVE(name) &&
JSVAL_TO_OBJECT(name)->getClass() == &js_QNameClass.base &&
!GetURI(nameqn = JSVAL_TO_OBJECT(name))) {
name = vp[2] = nameqn->getQNameLocalName();
name = vp[2] = nameqn->fslots[JSSLOT_LOCAL_NAME];
}
}
@ -6553,7 +6584,7 @@ xml_setName(JSContext *cx, uintN argc, jsval *vp)
/* ECMA-357 13.4.4.35 Step 4. */
if (xml->xml_class == JSXML_CLASS_PROCESSING_INSTRUCTION)
nameqn->setNameURI(STRING_TO_JSVAL(cx->runtime->emptyString));
nameqn->fslots[JSSLOT_URI] = STRING_TO_JSVAL(cx->runtime->emptyString);
xml = CHECK_COPY_ON_WRITE(cx, xml, obj);
if (!xml)
@ -6614,7 +6645,7 @@ xml_setName(JSContext *cx, uintN argc, jsval *vp)
for (i = 0, n = nsarray->length; i < n; i++) {
ns = XMLARRAY_MEMBER(nsarray, i, JSObject);
if (ns && js_EqualStrings(GetURI(ns), GetURI(nameqn))) {
nameqn->setNamePrefix(ns->getNamePrefix());
nameqn->fslots[JSSLOT_PREFIX] = ns->fslots[JSSLOT_PREFIX];
return JS_TRUE;
}
}
@ -6651,7 +6682,7 @@ xml_setNamespace(JSContext *cx, uintN argc, jsval *vp)
if (!ns)
return JS_FALSE;
vp[0] = OBJECT_TO_JSVAL(ns);
ns->setNamespaceDeclared(JSVAL_TRUE);
ns->fslots[JSSLOT_DECLARED] = JSVAL_TRUE;
qnargv[0] = vp[2] = OBJECT_TO_JSVAL(ns);
qnargv[1] = OBJECT_TO_JSVAL(xml->name);
@ -7012,7 +7043,7 @@ XMLList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (cx->isConstructing() && !JSVAL_IS_PRIMITIVE(v)) {
vobj = JSVAL_TO_OBJECT(v);
if (vobj->isXML()) {
if (OBJECT_IS_XML(cx, vobj)) {
xml = (JSXML *) vobj->getPrivate();
if (xml->xml_class == JSXML_CLASS_LIST) {
listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
@ -7625,7 +7656,7 @@ js_FindXMLProperty(JSContext *cx, jsval nameval, JSObject **objp, jsid *idp)
target = proto;
}
if (target->isXML()) {
if (OBJECT_IS_XML(cx, target)) {
if (funid == 0) {
xml = (JSXML *) target->getPrivate();
found = HasNamedProperty(xml, qn);
@ -7662,7 +7693,7 @@ js_FindXMLProperty(JSContext *cx, jsval nameval, JSObject **objp, jsid *idp)
static JSBool
GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
JS_ASSERT(obj->isXML());
JS_ASSERT(OBJECT_IS_XML(cx, obj));
/*
* See comments before xml_lookupProperty about the need for the proto
@ -7802,7 +7833,7 @@ js_StepXMLListFilter(JSContext *cx, JSBool initialized)
* We haven't iterated yet, so initialize the filter based on the
* value stored in sp[-2].
*/
if (!VALUE_IS_XML(sp[-2])) {
if (!VALUE_IS_XML(cx, sp[-2])) {
js_ReportValueError(cx, JSMSG_NON_XML_FILTER, -2, sp[-2], NULL);
return JS_FALSE;
}

View File

@ -40,7 +40,6 @@
#define jsxml_h___
#include "jspubtd.h"
#include "jsobj.h"
JS_BEGIN_EXTERN_C
@ -220,6 +219,10 @@ extern JSClass js_XMLFilterClass;
/*
* Methods to test whether an object or a value is of type "xml" (per typeof).
* NB: jsobj.h must be included before any call to OBJECT_IS_XML, and jsapi.h
* and jsobj.h must be included before any call to VALUE_IS_XML.
*
* FIXME: bogus cx parameters for OBJECT_IS_XML and VALUE_IS_XML.
*/
inline bool
JSObject::isXML() const
@ -227,22 +230,9 @@ JSObject::isXML() const
return map->ops == &js_XMLObjectOps;
}
#define VALUE_IS_XML(v) (!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isXML())
inline bool
JSObject::isNamespace() const
{
return getClass() == &js_NamespaceClass.base;
}
inline bool
JSObject::isQName() const
{
JSClass* clasp = getClass();
return clasp == &js_QNameClass.base ||
clasp == &js_AttributeNameClass ||
clasp == &js_AnyNameClass;
}
#define OBJECT_IS_XML(cx,obj) (obj)->isXML()
#define VALUE_IS_XML(cx,v) (!JSVAL_IS_PRIMITIVE(v) && \
JSVAL_TO_OBJECT(v)->isXML())
extern JSObject *
js_InitNamespaceClass(JSContext *cx, JSObject *obj);