diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index de475fbf1c5..3fcac074cd8 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -1206,7 +1206,7 @@ array_trace(JSTracer *trc, JSObject *obj) size_t i; jsval v; - JS_ASSERT(js_IsDenseArray(obj)); + JS_ASSERT(obj->isDenseArray()); obj->traceProtoAndParent(trc); capacity = js_DenseArrayCapacity(obj); @@ -3541,7 +3541,7 @@ js_CoerceArrayToCanvasImageData(JSObject *obj, jsuint offset, jsuint count, { uint32 length; - if (!obj || !js_IsDenseArray(obj)) + if (!obj || !obj->isDenseArray()) return JS_FALSE; length = obj->fslots[JSSLOT_ARRAY_LENGTH]; diff --git a/js/src/jsarray.h b/js/src/jsarray.h index 9a44afd992b..c3a00b874ed 100644 --- a/js/src/jsarray.h +++ b/js/src/jsarray.h @@ -55,16 +55,20 @@ js_IdIsIndex(jsval id, jsuint *indexp); extern JSClass js_ArrayClass, js_SlowArrayClass; -static JS_INLINE JSBool -js_IsDenseArray(JSObject *obj) +inline bool +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) || \ - OBJ_GET_CLASS(cx, obj) == &js_SlowArrayClass) +#define OBJ_IS_DENSE_ARRAY(cx,obj) (obj)->isDenseArray() +#define OBJ_IS_ARRAY(cx,obj) (obj)->isArray() /* * 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 js_DenseArrayCapacity(JSObject *obj) { - JS_ASSERT(js_IsDenseArray(obj)); + JS_ASSERT(obj->isDenseArray()); return obj->dslots ? (uint32) obj->dslots[-1] : 0; } static JS_INLINE void js_SetDenseArrayCapacity(JSObject *obj, uint32 capacity) { - JS_ASSERT(js_IsDenseArray(obj)); + JS_ASSERT(obj->isDenseArray()); JS_ASSERT(obj->dslots); obj->dslots[-1] = (jsval) capacity; } diff --git a/js/src/jsfun.h b/js/src/jsfun.h index 77c49be8cdb..74a9be4dbed 100644 --- a/js/src/jsfun.h +++ b/js/src/jsfun.h @@ -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. */ 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. diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 609ae7571b0..4e4101851cc 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -2278,7 +2278,7 @@ class AutoDescriptorArray : private JSTempValueRooter public: AutoDescriptorArray(JSContext *cx) - : cx(cx), descriptors(cx) + : cx(cx), descriptors(cx) { JS_PUSH_TEMP_ROOT_TRACE(cx, trace, this); } @@ -6907,8 +6907,7 @@ js_DumpObject(JSObject *obj) clasp = STOBJ_GET_CLASS(obj); fprintf(stderr, "class %p %s\n", (void *)clasp, clasp->name); - /* OBJ_IS_DENSE_ARRAY ignores the cx argument. */ - if (OBJ_IS_DENSE_ARRAY(BOGUS_CX, obj)) { + if (obj->isDenseArray()) { slots = JS_MIN((jsuint) obj->fslots[JSSLOT_ARRAY_LENGTH], js_DenseArrayCapacity(obj)); fprintf(stderr, "elements\n"); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index c989f1df39a..2b124e737fb 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -391,6 +391,12 @@ struct JSObject { if (map->ops->dropProperty) 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. */ diff --git a/js/src/jsregexp.h b/js/src/jsregexp.h index 956b5fde7cc..b17906e6b08 100644 --- a/js/src/jsregexp.h +++ b/js/src/jsregexp.h @@ -149,11 +149,16 @@ extern void js_FreeRegExpStatics(JSContext *cx); #define VALUE_IS_REGEXP(cx, v) \ - (JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \ - OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass) + (!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isRegExp()) extern JSClass js_RegExpClass; +inline bool +JSObject::isRegExp() const +{ + return getClass() == &js_RegExpClass; +} + enum regexp_tinyid { REGEXP_SOURCE = -1, REGEXP_GLOBAL = -2, diff --git a/js/src/jsscope.h b/js/src/jsscope.h index c49347b09ff..bdbce9a4534 100644 --- a/js/src/jsscope.h +++ b/js/src/jsscope.h @@ -554,7 +554,7 @@ struct JSScopeProperty { jsval getterValue() const { JS_ASSERT(attrs & JSPROP_GETTER); 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; } @@ -565,7 +565,7 @@ struct JSScopeProperty { jsval setterValue() const { JS_ASSERT(attrs & JSPROP_SETTER); 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; } diff --git a/js/src/jstracer.cpp b/js/src/jstracer.cpp index 07d9d8eeb27..ced184e7dea 100644 --- a/js/src/jstracer.cpp +++ b/js/src/jstracer.cpp @@ -88,10 +88,8 @@ using namespace nanojit; #if JS_HAS_XML_SUPPORT #define RETURN_VALUE_IF_XML(val, ret) \ JS_BEGIN_MACRO \ - if (!JSVAL_IS_PRIMITIVE(val) && \ - OBJECT_IS_XML(BOGUS_CX, JSVAL_TO_OBJECT(val))) { \ + if (!JSVAL_IS_PRIMITIVE(val) && JSVAL_TO_OBJECT(val)->isXML()) \ RETURN_VALUE("xml detected", ret); \ - } \ JS_END_MACRO #else #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"); } - if (js_IsDenseArray(obj)) { + if (obj->isDenseArray()) { // Fast path for dense arrays accessed with a integer index. jsval* vp; LIns* addr_ins; diff --git a/js/src/jsxml.h b/js/src/jsxml.h index 77392cdf7fa..c9fe34cddc1 100644 --- a/js/src/jsxml.h +++ b/js/src/jsxml.h @@ -169,13 +169,21 @@ extern JS_FRIEND_DATA(JSClass) js_AnyNameClass; 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 * 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) && \ - OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v))) + JSVAL_TO_OBJECT(v)->isXML()) extern JSObject * js_InitNamespaceClass(JSContext *cx, JSObject *obj);