[INFER] Reapply 7db908db3669 (bug 684084) 19ed9da5789d (bug 684824) a250c3cb749a (bug 686178) 820f11a3fdb1 (bug 686179) e678ced82a6a (bug 686418) 300e1f974f55 (bug 669715) 5c131d458c53 (bug 686396) 3a8b5e4a286b (bug 683140).
This commit is contained in:
@@ -2615,6 +2615,21 @@ array_unshift(JSContext *cx, uintN argc, Value *vp)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static inline void
|
||||
TryReuseArrayType(JSObject *obj, JSObject *nobj)
|
||||
{
|
||||
/*
|
||||
* Try to change the type of a newly created array nobj to the same type
|
||||
* as obj. This can only be performed if the original object is an array
|
||||
* and has the same prototype.
|
||||
*/
|
||||
JS_ASSERT(nobj->isDenseArray());
|
||||
JS_ASSERT(nobj->type() == nobj->getProto()->newType);
|
||||
|
||||
if (obj->isArray() && !obj->hasSingletonType() && obj->getProto() == nobj->getProto())
|
||||
nobj->setType(obj->type());
|
||||
}
|
||||
|
||||
static JSBool
|
||||
array_splice(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
@@ -2625,24 +2640,11 @@ array_splice(JSContext *cx, uintN argc, Value *vp)
|
||||
jsuint length, begin, end, count, delta, last;
|
||||
JSBool hole;
|
||||
|
||||
/*
|
||||
* Get the type of the result object: the original type when splicing an
|
||||
* array, a generic array type otherwise.
|
||||
*/
|
||||
TypeObject *type;
|
||||
if (obj->isArray() && !obj->hasSingletonType()) {
|
||||
type = obj->type();
|
||||
} else {
|
||||
type = GetTypeNewObject(cx, JSProto_Array);
|
||||
if (!type)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Create a new array value to return. */
|
||||
JSObject *obj2 = NewDenseEmptyArray(cx);
|
||||
if (!obj2)
|
||||
return JS_FALSE;
|
||||
obj2->setType(type);
|
||||
TryReuseArrayType(obj, obj2);
|
||||
vp->setObject(*obj2);
|
||||
|
||||
/* Nothing to do if no args. Otherwise get length. */
|
||||
@@ -2801,8 +2803,7 @@ array_concat(JSContext *cx, uintN argc, Value *vp)
|
||||
nobj = NewDenseCopiedArray(cx, initlen, vector);
|
||||
if (!nobj)
|
||||
return JS_FALSE;
|
||||
if (nobj->getProto() == aobj->getProto() && !aobj->hasSingletonType())
|
||||
nobj->setType(aobj->type());
|
||||
TryReuseArrayType(aobj, nobj);
|
||||
nobj->setArrayLength(cx, length);
|
||||
if (!aobj->isPackedDenseArray())
|
||||
nobj->markDenseArrayNotPacked(cx);
|
||||
@@ -2905,22 +2906,12 @@ array_slice(JSContext *cx, uintN argc, Value *vp)
|
||||
if (begin > end)
|
||||
begin = end;
|
||||
|
||||
/* Get the type object for the returned array, as for array_splice. */
|
||||
TypeObject *type;
|
||||
if (obj->isArray() && !obj->hasSingletonType()) {
|
||||
type = obj->type();
|
||||
} else {
|
||||
type = GetTypeNewObject(cx, JSProto_Array);
|
||||
if (!type)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj->isDenseArray() && end <= obj->getDenseArrayInitializedLength() &&
|
||||
!js_PrototypeHasIndexedProperties(cx, obj)) {
|
||||
nobj = NewDenseCopiedArray(cx, end - begin, obj->getDenseArrayElements() + begin);
|
||||
if (!nobj)
|
||||
return JS_FALSE;
|
||||
nobj->setType(type);
|
||||
TryReuseArrayType(obj, nobj);
|
||||
if (!obj->isPackedDenseArray())
|
||||
nobj->markDenseArrayNotPacked(cx);
|
||||
vp->setObject(*nobj);
|
||||
@@ -2931,7 +2922,7 @@ array_slice(JSContext *cx, uintN argc, Value *vp)
|
||||
nobj = NewDenseAllocatedArray(cx, end - begin);
|
||||
if (!nobj)
|
||||
return JS_FALSE;
|
||||
nobj->setType(type);
|
||||
TryReuseArrayType(obj, nobj);
|
||||
vp->setObject(*nobj);
|
||||
|
||||
AutoValueRooter tvr(cx);
|
||||
|
||||
Reference in New Issue
Block a user