Bug 537204 - No more BOGUS_CX bogosities (r=jwalden).

This commit is contained in:
Brendan Eich 2009-12-30 13:49:26 -08:00
parent 4629cf448e
commit 398f5f3b9b
9 changed files with 51 additions and 25 deletions

View File

@ -1206,7 +1206,7 @@ array_trace(JSTracer *trc, JSObject *obj)
size_t i; size_t i;
jsval v; jsval v;
JS_ASSERT(js_IsDenseArray(obj)); JS_ASSERT(obj->isDenseArray());
obj->traceProtoAndParent(trc); obj->traceProtoAndParent(trc);
capacity = js_DenseArrayCapacity(obj); capacity = js_DenseArrayCapacity(obj);
@ -3541,7 +3541,7 @@ js_CoerceArrayToCanvasImageData(JSObject *obj, jsuint offset, jsuint count,
{ {
uint32 length; uint32 length;
if (!obj || !js_IsDenseArray(obj)) if (!obj || !obj->isDenseArray())
return JS_FALSE; return JS_FALSE;
length = obj->fslots[JSSLOT_ARRAY_LENGTH]; length = obj->fslots[JSSLOT_ARRAY_LENGTH];

View File

@ -55,16 +55,20 @@ js_IdIsIndex(jsval id, jsuint *indexp);
extern JSClass js_ArrayClass, js_SlowArrayClass; extern JSClass js_ArrayClass, js_SlowArrayClass;
static JS_INLINE JSBool inline bool
js_IsDenseArray(JSObject *obj) JSObject::isDenseArray() const
{ {
return STOBJ_GET_CLASS(obj) == &js_ArrayClass; return getClass() == &js_ArrayClass;
} }
#define OBJ_IS_DENSE_ARRAY(cx, obj) js_IsDenseArray(obj) inline bool
JSObject::isArray() const
{
return isDenseArray() || getClass() == &js_SlowArrayClass;
}
#define OBJ_IS_ARRAY(cx,obj) (OBJ_IS_DENSE_ARRAY(cx, obj) || \ #define OBJ_IS_DENSE_ARRAY(cx,obj) (obj)->isDenseArray()
OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass) #define OBJ_IS_ARRAY(cx,obj) (obj)->isArray()
/* /*
* Dense arrays are not native (OBJ_IS_NATIVE(cx, aobj) for a dense array aobj * Dense arrays are not native (OBJ_IS_NATIVE(cx, aobj) for a dense array aobj
@ -122,14 +126,14 @@ js_MakeArraySlow(JSContext *cx, JSObject *obj);
static JS_INLINE uint32 static JS_INLINE uint32
js_DenseArrayCapacity(JSObject *obj) js_DenseArrayCapacity(JSObject *obj)
{ {
JS_ASSERT(js_IsDenseArray(obj)); JS_ASSERT(obj->isDenseArray());
return obj->dslots ? (uint32) obj->dslots[-1] : 0; return obj->dslots ? (uint32) obj->dslots[-1] : 0;
} }
static JS_INLINE void static JS_INLINE void
js_SetDenseArrayCapacity(JSObject *obj, uint32 capacity) js_SetDenseArrayCapacity(JSObject *obj, uint32 capacity)
{ {
JS_ASSERT(js_IsDenseArray(obj)); JS_ASSERT(obj->isDenseArray());
JS_ASSERT(obj->dslots); JS_ASSERT(obj->dslots);
obj->dslots[-1] = (jsval) capacity; obj->dslots[-1] = (jsval) capacity;
} }

View File

@ -212,7 +212,13 @@ extern const uint32 CALL_CLASS_FIXED_RESERVED_SLOTS;
/* JS_FRIEND_DATA so that VALUE_IS_FUNCTION is callable from the shell. */ /* JS_FRIEND_DATA so that VALUE_IS_FUNCTION is callable from the shell. */
extern JS_FRIEND_DATA(JSClass) js_FunctionClass; extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
#define HAS_FUNCTION_CLASS(obj) (STOBJ_GET_CLASS(obj) == &js_FunctionClass) inline bool
JSObject::isFunction() const
{
return getClass() == &js_FunctionClass;
}
#define HAS_FUNCTION_CLASS(obj) (obj)->isFunction()
/* /*
* NB: jsapi.h and jsobj.h must be included before any call to this macro. * NB: jsapi.h and jsobj.h must be included before any call to this macro.

View File

@ -6907,8 +6907,7 @@ js_DumpObject(JSObject *obj)
clasp = STOBJ_GET_CLASS(obj); clasp = STOBJ_GET_CLASS(obj);
fprintf(stderr, "class %p %s\n", (void *)clasp, clasp->name); fprintf(stderr, "class %p %s\n", (void *)clasp, clasp->name);
/* OBJ_IS_DENSE_ARRAY ignores the cx argument. */ if (obj->isDenseArray()) {
if (OBJ_IS_DENSE_ARRAY(BOGUS_CX, obj)) {
slots = JS_MIN((jsuint) obj->fslots[JSSLOT_ARRAY_LENGTH], slots = JS_MIN((jsuint) obj->fslots[JSSLOT_ARRAY_LENGTH],
js_DenseArrayCapacity(obj)); js_DenseArrayCapacity(obj));
fprintf(stderr, "elements\n"); fprintf(stderr, "elements\n");

View File

@ -391,6 +391,12 @@ struct JSObject {
if (map->ops->dropProperty) if (map->ops->dropProperty)
map->ops->dropProperty(cx, this, prop); map->ops->dropProperty(cx, this, prop);
} }
inline bool isArray() const;
inline bool isDenseArray() const;
inline bool isFunction() const;
inline bool isRegExp() const;
inline bool isXML() const;
}; };
/* Compatibility macros. */ /* Compatibility macros. */

View File

@ -149,11 +149,16 @@ extern void
js_FreeRegExpStatics(JSContext *cx); js_FreeRegExpStatics(JSContext *cx);
#define VALUE_IS_REGEXP(cx, v) \ #define VALUE_IS_REGEXP(cx, v) \
(JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \ (!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isRegExp())
OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass)
extern JSClass js_RegExpClass; extern JSClass js_RegExpClass;
inline bool
JSObject::isRegExp() const
{
return getClass() == &js_RegExpClass;
}
enum regexp_tinyid { enum regexp_tinyid {
REGEXP_SOURCE = -1, REGEXP_SOURCE = -1,
REGEXP_GLOBAL = -2, REGEXP_GLOBAL = -2,

View File

@ -554,7 +554,7 @@ struct JSScopeProperty {
jsval getterValue() const { jsval getterValue() const {
JS_ASSERT(attrs & JSPROP_GETTER); JS_ASSERT(attrs & JSPROP_GETTER);
jsval getterVal = getter ? js_CastAsObjectJSVal(getter) : JSVAL_VOID; jsval getterVal = getter ? js_CastAsObjectJSVal(getter) : JSVAL_VOID;
JS_ASSERT_IF(getter, VALUE_IS_FUNCTION(BOGUS_CX, getterVal)); JS_ASSERT_IF(getter, HAS_FUNCTION_CLASS(JSVAL_TO_OBJECT(getterVal)));
return getterVal; return getterVal;
} }
@ -565,7 +565,7 @@ struct JSScopeProperty {
jsval setterValue() const { jsval setterValue() const {
JS_ASSERT(attrs & JSPROP_SETTER); JS_ASSERT(attrs & JSPROP_SETTER);
jsval setterVal = setter ? js_CastAsObjectJSVal(setter) : JSVAL_VOID; jsval setterVal = setter ? js_CastAsObjectJSVal(setter) : JSVAL_VOID;
JS_ASSERT_IF(setter, VALUE_IS_FUNCTION(BOGUS_CX, setterVal)); JS_ASSERT_IF(setter, HAS_FUNCTION_CLASS(JSVAL_TO_OBJECT(setterVal)));
return setterVal; return setterVal;
} }

View File

@ -88,10 +88,8 @@ using namespace nanojit;
#if JS_HAS_XML_SUPPORT #if JS_HAS_XML_SUPPORT
#define RETURN_VALUE_IF_XML(val, ret) \ #define RETURN_VALUE_IF_XML(val, ret) \
JS_BEGIN_MACRO \ JS_BEGIN_MACRO \
if (!JSVAL_IS_PRIMITIVE(val) && \ if (!JSVAL_IS_PRIMITIVE(val) && JSVAL_TO_OBJECT(val)->isXML()) \
OBJECT_IS_XML(BOGUS_CX, JSVAL_TO_OBJECT(val))) { \
RETURN_VALUE("xml detected", ret); \ RETURN_VALUE("xml detected", ret); \
} \
JS_END_MACRO JS_END_MACRO
#else #else
#define RETURN_IF_XML(val, ret) ((void) 0) #define RETURN_IF_XML(val, ret) ((void) 0)
@ -11881,7 +11879,7 @@ TraceRecorder::record_JSOP_GETELEM()
} }
RETURN_STOP_A("can't reach arguments object's frame"); RETURN_STOP_A("can't reach arguments object's frame");
} }
if (js_IsDenseArray(obj)) { if (obj->isDenseArray()) {
// Fast path for dense arrays accessed with a integer index. // Fast path for dense arrays accessed with a integer index.
jsval* vp; jsval* vp;
LIns* addr_ins; LIns* addr_ins;

View File

@ -169,13 +169,21 @@ extern JS_FRIEND_DATA(JSClass) js_AnyNameClass;
extern JSClass js_XMLFilterClass; extern JSClass js_XMLFilterClass;
/* /*
* Macros to test whether an object or a value is of type "xml" (per typeof). * 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 * 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. * 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.
*/ */
#define OBJECT_IS_XML(cx,obj) ((obj)->map->ops == &js_XMLObjectOps) inline bool
JSObject::isXML() const
{
return map->ops == &js_XMLObjectOps;
}
#define OBJECT_IS_XML(cx,obj) (obj)->isXML()
#define VALUE_IS_XML(cx,v) (!JSVAL_IS_PRIMITIVE(v) && \ #define VALUE_IS_XML(cx,v) (!JSVAL_IS_PRIMITIVE(v) && \
OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v))) JSVAL_TO_OBJECT(v)->isXML())
extern JSObject * extern JSObject *
js_InitNamespaceClass(JSContext *cx, JSObject *obj); js_InitNamespaceClass(JSContext *cx, JSObject *obj);