Bug 827490 - Allow native objects to have both slots and dense elements, rm dense/slow array distinction, r=billm, dvander.

This commit is contained in:
Brian Hackett
2013-01-10 17:53:11 -07:00
parent a1fbb8f3de
commit 62f921e915
57 changed files with 1185 additions and 1862 deletions

View File

@@ -131,6 +131,17 @@ static bool
EnumerateNativeProperties(JSContext *cx, HandleObject pobj, unsigned flags, IdSet &ht,
AutoIdVector *props)
{
/* Collect any elements from this object. */
size_t initlen = pobj->getDenseInitializedLength();
const Value *vp = pobj->getDenseElements();
for (size_t i = 0; i < initlen; ++i, ++vp) {
if (!vp->isMagic(JS_ELEMENTS_HOLE)) {
/* Dense arrays never get so large that i would not fit into an integer id. */
if (!Enumerate(cx, pobj, INT_TO_JSID(i), true, flags, ht, props))
return false;
}
}
size_t initialLength = props->length();
/* Collect all unique properties from this object's scope. */
@@ -150,28 +161,6 @@ EnumerateNativeProperties(JSContext *cx, HandleObject pobj, unsigned flags, IdSe
return true;
}
static bool
EnumerateDenseArrayProperties(JSContext *cx, HandleObject pobj, unsigned flags,
IdSet &ht, AutoIdVector *props)
{
if (!Enumerate(cx, pobj, NameToId(cx->names().length), false, flags, ht, props))
return false;
if (pobj->getArrayLength() > 0) {
size_t initlen = pobj->getDenseArrayInitializedLength();
const Value *vp = pobj->getDenseArrayElements();
for (size_t i = 0; i < initlen; ++i, ++vp) {
if (!vp->isMagic(JS_ARRAY_HOLE)) {
/* Dense arrays never get so large that i would not fit into an integer id. */
if (!Enumerate(cx, pobj, INT_TO_JSID(i), true, flags, ht, props))
return false;
}
}
}
return true;
}
#ifdef JS_MORE_DETERMINISTIC
struct SortComparatorIds
@@ -220,9 +209,6 @@ Snapshot(JSContext *cx, RawObject pobj_, unsigned flags, AutoIdVector *props)
return false;
if (!EnumerateNativeProperties(cx, pobj, flags, ht, props))
return false;
} else if (pobj->isDenseArray()) {
if (!EnumerateDenseArrayProperties(cx, pobj, flags, ht, props))
return false;
} else if (ParallelArrayObject::is(pobj)) {
if (!ParallelArrayObject::enumerate(cx, pobj, flags, props))
return false;
@@ -629,10 +615,12 @@ js::GetIterator(JSContext *cx, HandleObject obj, unsigned flags, MutableHandleVa
NativeIterator *lastni = last->getNativeIterator();
if (!(lastni->flags & (JSITER_ACTIVE|JSITER_UNREUSABLE)) &&
obj->isNative() &&
obj->hasEmptyElements() &&
obj->lastProperty() == lastni->shapes_array[0])
{
JSObject *proto = obj->getProto();
if (proto->isNative() &&
proto->hasEmptyElements() &&
proto->lastProperty() == lastni->shapes_array[1] &&
!proto->getProto())
{
@@ -655,6 +643,7 @@ js::GetIterator(JSContext *cx, HandleObject obj, unsigned flags, MutableHandleVa
RawObject pobj = obj;
do {
if (!pobj->isNative() ||
!pobj->hasEmptyElements() ||
pobj->hasUncacheableProto() ||
obj->getOps()->enumerate ||
pobj->getClass()->enumerate != JS_EnumerateStub) {