Bug 1201051 - Add ObjectWeakMap::init() rather than crashing in constructor on OOM r=terrence

This commit is contained in:
Jon Coppeard 2015-09-03 12:08:08 +01:00
parent 2b6fac45c5
commit 69e5e253e9
5 changed files with 15 additions and 5 deletions

View File

@ -2189,7 +2189,7 @@ InlineTransparentTypedObject::getOrCreateBuffer(JSContext* cx)
ObjectWeakMap*& table = cx->compartment()->lazyArrayBuffers;
if (!table) {
table = cx->new_<ObjectWeakMap>(cx);
if (!table)
if (!table || !table->init())
return nullptr;
}

View File

@ -807,7 +807,7 @@ JSCompartment::setNewObjectMetadata(JSContext* cx, JSObject* obj)
assertSameCompartment(cx, metadata);
if (!objectMetadataTable) {
objectMetadataTable = cx->new_<ObjectWeakMap>(cx);
if (!objectMetadataTable)
if (!objectMetadataTable || !objectMetadataTable->init())
CrashAtUnhandlableOOM("setNewObjectMetadata");
}
if (!objectMetadataTable->add(cx, obj, metadata))

View File

@ -683,9 +683,12 @@ js::InitBareWeakMapCtor(JSContext* cx, HandleObject obj)
ObjectWeakMap::ObjectWeakMap(JSContext* cx)
: map(cx, nullptr)
{}
bool
ObjectWeakMap::init()
{
if (!map.init())
CrashAtUnhandlableOOM("ObjectWeakMap");
return map.init();
}
ObjectWeakMap::~ObjectWeakMap()
@ -696,6 +699,7 @@ ObjectWeakMap::~ObjectWeakMap()
JSObject*
ObjectWeakMap::lookup(const JSObject* obj)
{
MOZ_ASSERT(map.initialized());
if (ObjectValueMap::Ptr p = map.lookup(const_cast<JSObject*>(obj)))
return &p->value().toObject();
return nullptr;
@ -705,6 +709,7 @@ bool
ObjectWeakMap::add(JSContext* cx, JSObject* obj, JSObject* target)
{
MOZ_ASSERT(obj && target);
MOZ_ASSERT(map.initialized());
MOZ_ASSERT(!map.has(obj));
if (!map.put(obj, ObjectValue(*target))) {
@ -720,18 +725,21 @@ ObjectWeakMap::add(JSContext* cx, JSObject* obj, JSObject* target)
void
ObjectWeakMap::clear()
{
MOZ_ASSERT(map.initialized());
map.clear();
}
void
ObjectWeakMap::trace(JSTracer* trc)
{
MOZ_ASSERT(map.initialized());
map.trace(trc);
}
size_t
ObjectWeakMap::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)
{
MOZ_ASSERT(map.initialized());
return map.sizeOfExcludingThis(mallocSizeOf);
}
@ -739,6 +747,7 @@ ObjectWeakMap::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf)
void
ObjectWeakMap::checkAfterMovingGC()
{
MOZ_ASSERT(map.initialized());
for (ObjectValueMap::Range r = map.all(); !r.empty(); r.popFront()) {
CheckGCThingAfterMovingGC(r.front().key().get());
CheckGCThingAfterMovingGC(&r.front().value().toObject());

View File

@ -1921,7 +1921,7 @@ DebugScopes::~DebugScopes()
bool
DebugScopes::init()
{
return liveScopes.init() && missingScopes.init();
return proxiedScopes.init() && missingScopes.init() && liveScopes.init();
}
void

View File

@ -38,6 +38,7 @@ class ObjectWeakMap
public:
explicit ObjectWeakMap(JSContext* cx);
bool init();
~ObjectWeakMap();
JSObject* lookup(const JSObject* obj);