Bug 519363: more new diagnostic null pointers. r=gal

This commit is contained in:
David Mandelin 2009-10-08 19:00:21 -07:00
Родитель 27efa4b049
Коммит 489e5ba0ba
5 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -419,7 +419,8 @@ js_NewNullClosure(JSContext* cx, JSObject* funobj, JSObject* proto, JSObject* pa
closure->map = scope; closure->map = scope;
closure->init(&js_FunctionClass, proto, parent, closure->init(&js_FunctionClass, proto, parent,
reinterpret_cast<jsval>(fun)); reinterpret_cast<jsval>(fun),
DSLOTS_NULL_INIT_CLOSURE);
return closure; return closure;
} }
JS_DEFINE_CALLINFO_4(extern, OBJECT, js_NewNullClosure, CONTEXT, OBJECT, OBJECT, OBJECT, 0, 0) JS_DEFINE_CALLINFO_4(extern, OBJECT, js_NewNullClosure, CONTEXT, OBJECT, OBJECT, OBJECT, 0, 0)

Просмотреть файл

@ -246,6 +246,8 @@ js_FillPropertyCache(JSContext *cx, JSObject *obj,
SPROP_HAS_VALID_SLOT(sprop, scope)) { SPROP_HAS_VALID_SLOT(sprop, scope)) {
/* Great, let's cache sprop's slot and use it on cache hit. */ /* Great, let's cache sprop's slot and use it on cache hit. */
vword = SLOT_TO_PCVAL(sprop->slot); vword = SLOT_TO_PCVAL(sprop->slot);
if (sprop->slot >= JS_INITIAL_NSLOTS && !DSLOTS_IS_NOT_NULL(obj))
DSLOTS_BUMP(obj);
} else { } else {
/* Best we can do is to cache sprop (still a nice speedup). */ /* Best we can do is to cache sprop (still a nice speedup). */
vword = SPROP_TO_PCVAL(sprop); vword = SPROP_TO_PCVAL(sprop);

Просмотреть файл

@ -2236,7 +2236,8 @@ js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
obj->init(clasp, obj->init(clasp,
proto, proto,
(!parent && proto) ? proto->getParent() : parent, (!parent && proto) ? proto->getParent() : parent,
JSObject::defaultPrivate(clasp)); JSObject::defaultPrivate(clasp),
OPS_IS_NATIVE(ops) ? DSLOTS_NULL_INIT_OBJECT_NATIVE : DSLOTS_NULL_INIT_OBJECT_NONNATIVE);
if (OPS_IS_NATIVE(ops)) { if (OPS_IS_NATIVE(ops)) {
if (!InitScopeForObject(cx, obj, proto, ops)) { if (!InitScopeForObject(cx, obj, proto, ops)) {
@ -2330,7 +2331,7 @@ NewNativeObject(JSContext* cx, JSClass* clasp, JSObject* proto,
if (!obj) if (!obj)
return NULL; return NULL;
obj->init(clasp, proto, parent, privateSlotValue); obj->init(clasp, proto, parent, privateSlotValue, DSLOTS_NULL_INIT_NATIVE);
return InitScopeForObject(cx, obj, proto, &js_ObjectOps) ? obj : NULL; return InitScopeForObject(cx, obj, proto, &js_ObjectOps) ? obj : NULL;
} }
@ -3275,7 +3276,8 @@ js_NewNativeObject(JSContext *cx, JSClass *clasp, JSObject *proto,
return NULL; return NULL;
} }
obj->map = scope; obj->map = scope;
obj->init(clasp, proto, proto->getParent(), privateSlotValue); obj->init(clasp, proto, proto->getParent(), privateSlotValue,
DSLOTS_NULL_INIT_JSNATIVE);
return obj; return obj;
} }

Просмотреть файл

@ -233,7 +233,7 @@ struct JSObject {
/* The map field is not initialized here and should be set separately. */ /* The map field is not initialized here and should be set separately. */
void init(JSClass *clasp, JSObject *proto, JSObject *parent, void init(JSClass *clasp, JSObject *proto, JSObject *parent,
jsval privateSlotValue) { jsval privateSlotValue, jsval *nullPtr) {
JS_ASSERT(((jsuword) clasp & 3) == 0); JS_ASSERT(((jsuword) clasp & 3) == 0);
JS_STATIC_ASSERT(JSSLOT_PRIVATE + 3 == JS_INITIAL_NSLOTS); JS_STATIC_ASSERT(JSSLOT_PRIVATE + 3 == JS_INITIAL_NSLOTS);
JS_ASSERT_IF(clasp->flags & JSCLASS_HAS_PRIVATE, JS_ASSERT_IF(clasp->flags & JSCLASS_HAS_PRIVATE,
@ -248,7 +248,7 @@ struct JSObject {
fslots[JSSLOT_PRIVATE] = privateSlotValue; fslots[JSSLOT_PRIVATE] = privateSlotValue;
fslots[JSSLOT_PRIVATE + 1] = JSVAL_VOID; fslots[JSSLOT_PRIVATE + 1] = JSVAL_VOID;
fslots[JSSLOT_PRIVATE + 2] = JSVAL_VOID; fslots[JSSLOT_PRIVATE + 2] = JSVAL_VOID;
dslots = DSLOTS_NULL_INIT; dslots = nullPtr;
} }
JSBool lookupProperty(JSContext *cx, jsid id, JSBool lookupProperty(JSContext *cx, jsid id,

Просмотреть файл

@ -370,17 +370,23 @@ extern JSBool js_CStringsAreUTF8;
*/ */
#define JS_ARGS_LENGTH_MAX (JS_BIT(24) - 1) #define JS_ARGS_LENGTH_MAX (JS_BIT(24) - 1)
#define DSLOTS_NULL_SHIFT 8 #define DSLOTS_NULL_SHIFT 8
#define DSLOTS_NULL_RESIZE_SLOTS ((jsval*) (1 << DSLOTS_NULL_SHIFT)) #define DSLOTS_NULL_RESIZE_SLOTS ((jsval*) (1 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_ARRAY_FINALIZE ((jsval*) (2 << DSLOTS_NULL_SHIFT)) #define DSLOTS_NULL_ARRAY_FINALIZE ((jsval*) (2 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_NEW_EMPTY_ARRAY ((jsval*) (3 << DSLOTS_NULL_SHIFT)) #define DSLOTS_NULL_NEW_EMPTY_ARRAY ((jsval*) (3 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_CLONE_BLOCK_OBJECT ((jsval*) (4 << DSLOTS_NULL_SHIFT)) #define DSLOTS_NULL_CLONE_BLOCK_OBJECT ((jsval*) (4 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_INIT ((jsval*) (5 << DSLOTS_NULL_SHIFT)) #define DSLOTS_NULL_SHRINK_SLOTS ((jsval*) (5 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_SHRINK_SLOTS ((jsval*) (6 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_LIMIT (16 << DSLOTS_NULL_SHIFT) #define DSLOTS_NULL_INIT_OBJECT_NATIVE ((jsval*) (6 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_INIT_OBJECT_NONNATIVE ((jsval*) (7 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_INIT_NATIVE ((jsval*) (8 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_INIT_JSNATIVE ((jsval*) (9 << DSLOTS_NULL_SHIFT))
#define DSLOTS_NULL_INIT_CLOSURE ((jsval*) (10 << DSLOTS_NULL_SHIFT))
#define DSLOTS_IS_NOT_NULL(obj) (uintptr_t(obj->dslots) >= DSLOTS_NULL_LIMIT) #define DSLOTS_NULL_LIMIT (16 << DSLOTS_NULL_SHIFT)
#define DSLOTS_IS_NOT_NULL(obj) (uintptr_t(obj->dslots) >= DSLOTS_NULL_LIMIT)
#define DSLOTS_NORMALIZE(obj) (DSLOTS_IS_NOT_NULL(obj) ? (obj)->dslots : NULL) #define DSLOTS_NORMALIZE(obj) (DSLOTS_IS_NOT_NULL(obj) ? (obj)->dslots : NULL)
#define DSLOTS_BUMP(obj) (obj->dslots = (jsval*) (uintptr_t((obj)->dslots) | (1 << (DSLOTS_NULL_SHIFT-1))))
#endif /* jsprvtd_h___ */ #endif /* jsprvtd_h___ */