Bug 1002737 - Make AutoPropDescRooter into an AutoVectorRooter. (r=jorendorff)

This commit is contained in:
Eric Faust 2014-06-03 12:37:43 -07:00
Родитель 8f1835b4f0
Коммит 4d5e51d5bd
7 изменённых файлов: 31 добавлений и 54 удалений

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

@ -388,16 +388,11 @@ AutoGCRooter::trace(JSTracer *trc)
return; return;
} }
case DESCRIPTORS: { case DESCVECTOR: {
PropDescArray &descriptors = AutoPropDescVector::VectorImpl &descriptors =
static_cast<AutoPropDescArrayRooter *>(this)->descriptors; static_cast<AutoPropDescVector *>(this)->vector;
for (size_t i = 0, len = descriptors.length(); i < len; i++) { for (size_t i = 0, len = descriptors.length(); i < len; i++)
PropDesc &desc = descriptors[i]; descriptors[i].trace(trc);
MarkValueRoot(trc, &desc.pd_, "PropDesc::pd_");
MarkValueRoot(trc, &desc.value_, "PropDesc::value_");
MarkValueRoot(trc, &desc.get_, "PropDesc::get_");
MarkValueRoot(trc, &desc.set_, "PropDesc::set_");
}
return; return;
} }

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

@ -106,7 +106,7 @@ class JS_PUBLIC_API(AutoGCRooter) {
PARSER = -3, /* js::frontend::Parser */ PARSER = -3, /* js::frontend::Parser */
SHAPEVECTOR = -4, /* js::AutoShapeVector */ SHAPEVECTOR = -4, /* js::AutoShapeVector */
IDARRAY = -6, /* js::AutoIdArray */ IDARRAY = -6, /* js::AutoIdArray */
DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ DESCVECTOR = -7, /* js::AutoPropDescVector */
VALVECTOR = -10, /* js::AutoValueVector */ VALVECTOR = -10, /* js::AutoValueVector */
IDVECTOR = -13, /* js::AutoIdVector */ IDVECTOR = -13, /* js::AutoIdVector */
OBJVECTOR = -14, /* js::AutoObjectVector */ OBJVECTOR = -14, /* js::AutoObjectVector */

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

@ -1090,7 +1090,7 @@ js::DefineOwnProperty(JSContext *cx, HandleObject obj, HandleId id,
bool bool
js::ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccessors, js::ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccessors,
AutoIdVector *ids, AutoPropDescArrayRooter *descs) AutoIdVector *ids, AutoPropDescVector *descs)
{ {
if (!GetPropertyNames(cx, props, JSITER_OWNONLY, ids)) if (!GetPropertyNames(cx, props, JSITER_OWNONLY, ids))
return false; return false;
@ -1098,11 +1098,11 @@ js::ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccesso
RootedId id(cx); RootedId id(cx);
for (size_t i = 0, len = ids->length(); i < len; i++) { for (size_t i = 0, len = ids->length(); i < len; i++) {
id = (*ids)[i]; id = (*ids)[i];
PropDesc* desc = descs->append(); Rooted<PropDesc> desc(cx);
RootedValue v(cx); RootedValue v(cx);
if (!desc || if (!JSObject::getGeneric(cx, props, props, id, &v) ||
!JSObject::getGeneric(cx, props, props, id, &v) || !desc.initialize(cx, v, checkAccessors) ||
!desc->initialize(cx, v, checkAccessors)) !descs->append(desc))
{ {
return false; return false;
} }
@ -1114,7 +1114,7 @@ bool
js::DefineProperties(JSContext *cx, HandleObject obj, HandleObject props) js::DefineProperties(JSContext *cx, HandleObject obj, HandleObject props)
{ {
AutoIdVector ids(cx); AutoIdVector ids(cx);
AutoPropDescArrayRooter descs(cx); AutoPropDescVector descs(cx);
if (!ReadPropertyDescriptors(cx, props, true, &ids, &descs)) if (!ReadPropertyDescriptors(cx, props, true, &ids, &descs))
return false; return false;

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

@ -32,7 +32,7 @@ struct ObjectsExtraSizes;
namespace js { namespace js {
class AutoPropDescArrayRooter; class AutoPropDescVector;
struct GCMarker; struct GCMarker;
struct NativeIterator; struct NativeIterator;
class Nursery; class Nursery;
@ -1401,7 +1401,7 @@ DefineProperties(JSContext *cx, HandleObject obj, HandleObject props);
*/ */
extern bool extern bool
ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccessors, ReadPropertyDescriptors(JSContext *cx, HandleObject props, bool checkAccessors,
AutoIdVector *ids, AutoPropDescArrayRooter *descs); AutoIdVector *ids, AutoPropDescVector *descs);
/* Read the name using a dynamic lookup on the scopeChain. */ /* Read the name using a dynamic lookup on the scopeChain. */
extern bool extern bool

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

@ -772,32 +772,17 @@ IsInternalFunctionObject(JSObject *funobj)
return fun->isLambda() && !funobj->getParent(); return fun->isLambda() && !funobj->getParent();
} }
class AutoPropDescArrayRooter : private AutoGCRooter class AutoPropDescVector : public AutoVectorRooter<PropDesc>
{ {
public: public:
explicit AutoPropDescArrayRooter(JSContext *cx) explicit AutoPropDescVector(JSContext *cx
: AutoGCRooter(cx, DESCRIPTORS), descriptors(cx) MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
{ } : AutoVectorRooter<PropDesc>(cx, DESCVECTOR)
{
PropDesc *append() { MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (!descriptors.append(PropDesc()))
return nullptr;
return &descriptors.back();
} }
bool reserve(size_t n) { MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
return descriptors.reserve(n);
}
PropDesc& operator[](size_t i) {
JS_ASSERT(i < descriptors.length());
return descriptors[i];
}
friend void AutoGCRooter::trace(JSTracer *trc);
private:
PropDescArray descriptors;
}; };
/* /*

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

@ -5354,19 +5354,16 @@ DebuggerObject_defineProperties(JSContext *cx, unsigned argc, Value *vp)
return false; return false;
AutoIdVector ids(cx); AutoIdVector ids(cx);
AutoPropDescArrayRooter descs(cx); AutoPropDescVector descs(cx);
if (!ReadPropertyDescriptors(cx, props, false, &ids, &descs)) if (!ReadPropertyDescriptors(cx, props, false, &ids, &descs))
return false; return false;
size_t n = ids.length(); size_t n = ids.length();
AutoPropDescArrayRooter unwrappedDescs(cx); AutoPropDescVector unwrappedDescs(cx);
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
if (!unwrappedDescs.append()) if (!unwrappedDescs.append(PropDesc()))
return false; return false;
Handle<PropDesc> wrapped = Handle<PropDesc>::fromMarkedLocation(&descs[i]); if (!dbg->unwrapPropDescInto(cx, obj, descs[i], unwrappedDescs[i]))
MutableHandle<PropDesc> unwrapped =
MutableHandle<PropDesc>::fromMarkedLocation(&unwrappedDescs[i]);
if (!dbg->unwrapPropDescInto(cx, obj, wrapped, unwrapped))
return false; return false;
if (!unwrappedDescs[i].checkGetter(cx) || !unwrappedDescs[i].checkSetter(cx)) if (!unwrappedDescs[i].checkGetter(cx) || !unwrappedDescs[i].checkSetter(cx))
return false; return false;
@ -5374,17 +5371,18 @@ DebuggerObject_defineProperties(JSContext *cx, unsigned argc, Value *vp)
{ {
AutoIdVector rewrappedIds(cx); AutoIdVector rewrappedIds(cx);
AutoPropDescArrayRooter rewrappedDescs(cx); AutoPropDescVector rewrappedDescs(cx);
Maybe<AutoCompartment> ac; Maybe<AutoCompartment> ac;
ac.construct(cx, obj); ac.construct(cx, obj);
RootedId id(cx);
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
if (!rewrappedIds.append(JSID_VOID) || !rewrappedDescs.append()) if (!rewrappedIds.append(JSID_VOID) || !rewrappedDescs.append(PropDesc()))
return false; return false;
id = ids[i]; if (!unwrappedDescs[i].get().wrapInto(cx, obj, ids[i], rewrappedIds[i].address(),
if (!unwrappedDescs[i].wrapInto(cx, obj, id, rewrappedIds[i].address(), &rewrappedDescs[i])) rewrappedDescs[i].address()))
{
return false; return false;
}
} }
ErrorCopier ec(ac, dbg->toJSObject()); ErrorCopier ec(ac, dbg->toJSObject());

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

@ -64,7 +64,6 @@ struct PropDesc {
} }
public: public:
friend void JS::AutoGCRooter::trace(JSTracer *trc);
friend struct GCMethods<PropDesc>; friend struct GCMethods<PropDesc>;
void trace(JSTracer *trc); void trace(JSTracer *trc);