bug 491013 - fixing shared setter regression and eliminating several useless anonymous prototype objects. r=brendan

This commit is contained in:
Igor Bukanov
2009-05-03 20:43:55 -04:00
parent 5a47ea6a6b
commit 5ef9af3875
14 changed files with 76 additions and 126 deletions

View File

@@ -2411,24 +2411,14 @@ js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth)
JSObject *
js_NewBlockObject(JSContext *cx)
{
JSObject *obj;
JSBool ok;
/*
* Null obj's proto slot so that Object.prototype.* does not pollute block
* scopes. Make sure obj has its own scope too, since clearing proto does
* not affect OBJ_SCOPE(obj).
* scopes and to give the block object its own scope.
*/
obj = js_NewObject(cx, &js_BlockClass, NULL, NULL, 0);
if (!obj)
return NULL;
JS_LOCK_OBJ(cx, obj);
ok = js_GetMutableScope(cx, obj) != NULL;
JS_UNLOCK_OBJ(cx, obj);
if (!ok)
return NULL;
OBJ_CLEAR_PROTO(cx, obj);
return obj;
JSObject *blockObj = js_NewObjectWithGivenProto(cx, &js_BlockClass,
NULL, NULL, 0);
JS_ASSERT_IF(blockObj, !OBJ_IS_CLONED_BLOCK(blockObj));
return blockObj;
}
JSObject *
@@ -2446,6 +2436,7 @@ js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent,
STOBJ_SET_SLOT(clone, JSSLOT_BLOCK_DEPTH,
OBJ_GET_SLOT(cx, proto, JSSLOT_BLOCK_DEPTH));
JS_ASSERT(OBJ_IS_CLONED_BLOCK(clone));
JS_ASSERT(OBJ_SCOPE(clone)->object == proto);
return clone;
}
@@ -2573,8 +2564,8 @@ FindObjectIndex(JSObjectArray *array, JSObject *obj)
return NO_PARENT_INDEX;
}
static JSBool
block_xdrObject(JSXDRState *xdr, JSObject **objp)
JSBool
js_XDRBlockObject(JSXDRState *xdr, JSObject **objp)
{
JSContext *cx;
uint32 parentId;
@@ -2687,8 +2678,6 @@ block_xdrObject(JSXDRState *xdr, JSObject **objp)
return ok;
}
#else
# define block_xdrObject NULL
#endif
static uint32
@@ -2699,27 +2688,12 @@ block_reserveSlots(JSContext *cx, JSObject *obj)
JSClass js_BlockClass = {
"Block",
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(1) |
JSCLASS_IS_ANONYMOUS | JSCLASS_HAS_CACHED_PROTO(JSProto_Block),
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_IS_ANONYMOUS,
JS_PropertyStub, JS_PropertyStub, block_getProperty, block_setProperty,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
NULL, NULL, NULL, NULL, block_xdrObject, NULL, NULL, block_reserveSlots
NULL, NULL, NULL, NULL, NULL, NULL, NULL, block_reserveSlots
};
JSObject*
js_InitBlockClass(JSContext *cx, JSObject* obj)
{
JSObject *proto;
proto = JS_InitClass(cx, obj, NULL, &js_BlockClass, NULL, 0, NULL,
NULL, NULL, NULL);
if (!proto)
return NULL;
OBJ_CLEAR_PROTO(cx, proto);
return proto;
}
JSObject *
js_InitEval(JSContext *cx, JSObject *obj)
{
@@ -4277,7 +4251,7 @@ js_NativeSet(JSContext *cx, JSObject *obj, JSScopeProperty *sprop, jsval *vp)
JS_ASSERT(OBJ_IS_NATIVE(obj));
JS_ASSERT(JS_IS_OBJ_LOCKED(cx, obj));
scope = OBJ_SCOPE(obj);
JS_ASSERT(scope->object == obj);
JS_ASSERT(scope->object == obj || (sprop->attrs & JSPROP_SHARED));
slot = sprop->slot;
if (slot != SPROP_INVALID_SLOT) {
@@ -4311,7 +4285,7 @@ js_NativeSet(JSContext *cx, JSObject *obj, JSScopeProperty *sprop, jsval *vp)
return JS_FALSE;
JS_LOCK_SCOPE(cx, scope);
JS_ASSERT(scope->object == obj);
JS_ASSERT(scope->object == obj || (sprop->attrs & JSPROP_SHARED));
if (SLOT_IN_SCOPE(slot, scope) &&
(JS_LIKELY(cx->runtime->propertyRemovals == sample) ||
SCOPE_GET_PROPERTY(scope, sprop->id) == sprop)) {