Bug 1155618 - Fix some more places we don't report allocation failure to the context r=terrence

This commit is contained in:
Jon Coppeard 2015-05-28 10:22:41 +01:00
parent 19d359076b
commit eb6861af9a
8 changed files with 34 additions and 9 deletions

View File

@ -1835,8 +1835,10 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
ungetCharIgnoreEOL(nc); ungetCharIgnoreEOL(nc);
} }
if (!tokenbuf.append(c)) if (!tokenbuf.append(c)) {
ReportOutOfMemory(cx);
return false; return false;
}
} }
JSAtom* atom = atomize(cx, tokenbuf); JSAtom* atom = atomize(cx, tokenbuf);

View File

@ -54,7 +54,10 @@ AllocateObjectBuffer(ExclusiveContext* cx, JSObject* obj, uint32_t count)
if (cx->isJSContext()) { if (cx->isJSContext()) {
Nursery& nursery = cx->asJSContext()->runtime()->gc.nursery; Nursery& nursery = cx->asJSContext()->runtime()->gc.nursery;
size_t nbytes = JS_ROUNDUP(count * sizeof(T), sizeof(Value)); size_t nbytes = JS_ROUNDUP(count * sizeof(T), sizeof(Value));
return static_cast<T*>(nursery.allocateBuffer(obj, nbytes)); T* buffer = static_cast<T*>(nursery.allocateBuffer(obj, nbytes));
if (!buffer)
ReportOutOfMemory(cx);
return buffer;
} }
return obj->zone()->pod_malloc<T>(count); return obj->zone()->pod_malloc<T>(count);
} }

View File

@ -151,8 +151,10 @@ BaselineCompiler::compile()
indexEntry.pcOffset = entry.pcOffset; indexEntry.pcOffset = entry.pcOffset;
indexEntry.nativeOffset = entry.nativeOffset; indexEntry.nativeOffset = entry.nativeOffset;
indexEntry.bufferOffset = pcEntries.length(); indexEntry.bufferOffset = pcEntries.length();
if (!pcMappingIndexEntries.append(indexEntry)) if (!pcMappingIndexEntries.append(indexEntry)) {
ReportOutOfMemory(cx);
return Method_Error; return Method_Error;
}
previousOffset = entry.nativeOffset; previousOffset = entry.nativeOffset;
} }

View File

@ -98,7 +98,11 @@ class BaselineCompilerShared
bool appendICEntry(ICEntry::Kind kind, uint32_t returnOffset) { bool appendICEntry(ICEntry::Kind kind, uint32_t returnOffset) {
ICEntry entry(script->pcToOffset(pc), kind); ICEntry entry(script->pcToOffset(pc), kind);
entry.setReturnOffset(CodeOffsetLabel(returnOffset)); entry.setReturnOffset(CodeOffsetLabel(returnOffset));
return icEntries_.append(entry); if (!icEntries_.append(entry)) {
ReportOutOfMemory(cx);
return false;
}
return true;
} }
bool addICLoadLabel(CodeOffsetLabel label) { bool addICLoadLabel(CodeOffsetLabel label) {
@ -106,7 +110,11 @@ class BaselineCompilerShared
ICLoadLabel loadLabel; ICLoadLabel loadLabel;
loadLabel.label = label; loadLabel.label = label;
loadLabel.icEntry = icEntries_.length() - 1; loadLabel.icEntry = icEntries_.length() - 1;
return icLoadLabels_.append(loadLabel); if (!icLoadLabels_.append(loadLabel)) {
ReportOutOfMemory(cx);
return false;
}
return true;
} }
JSFunction* function() const { JSFunction* function() const {

View File

@ -148,8 +148,10 @@ Bindings::initWithTemporaryStorage(ExclusiveContext* cx, InternalBindingsHandle
#ifdef DEBUG #ifdef DEBUG
HashSet<PropertyName*> added(cx); HashSet<PropertyName*> added(cx);
if (!added.init()) if (!added.init()) {
ReportOutOfMemory(cx);
return false; return false;
}
#endif #endif
uint32_t slot = CallObject::RESERVED_SLOTS; uint32_t slot = CallObject::RESERVED_SLOTS;
@ -160,8 +162,10 @@ Bindings::initWithTemporaryStorage(ExclusiveContext* cx, InternalBindingsHandle
#ifdef DEBUG #ifdef DEBUG
// The caller ensures no duplicate aliased names. // The caller ensures no duplicate aliased names.
MOZ_ASSERT(!added.has(bi->name())); MOZ_ASSERT(!added.has(bi->name()));
if (!added.put(bi->name())) if (!added.put(bi->name())) {
ReportOutOfMemory(cx);
return false; return false;
}
#endif #endif
StackBaseShape stackBase(cx, &CallObject::class_, StackBaseShape stackBase(cx, &CallObject::class_,

View File

@ -824,6 +824,7 @@ ObjectGroup::setGroupToHomogenousArray(ExclusiveContext* cx, JSObject* obj,
if (!table) { if (!table) {
table = cx->new_<ObjectGroupCompartment::ArrayObjectTable>(); table = cx->new_<ObjectGroupCompartment::ArrayObjectTable>();
if (!table || !table->init()) { if (!table || !table->init()) {
ReportOutOfMemory(cx);
js_delete(table); js_delete(table);
table = nullptr; table = nullptr;
return; return;
@ -947,6 +948,7 @@ ObjectGroup::newPlainObject(ExclusiveContext* cx, IdValuePair* properties, size_
if (!table) { if (!table) {
table = cx->new_<ObjectGroupCompartment::PlainObjectTable>(); table = cx->new_<ObjectGroupCompartment::PlainObjectTable>();
if (!table || !table->init()) { if (!table || !table->init()) {
ReportOutOfMemory(cx);
js_delete(table); js_delete(table);
table = nullptr; table = nullptr;
return nullptr; return nullptr;
@ -1135,6 +1137,7 @@ ObjectGroup::allocationSiteGroup(JSContext* cx, JSScript* script, jsbytecode* pc
if (!table) { if (!table) {
table = cx->new_<ObjectGroupCompartment::AllocationSiteTable>(); table = cx->new_<ObjectGroupCompartment::AllocationSiteTable>();
if (!table || !table->init()) { if (!table || !table->init()) {
ReportOutOfMemory(cx);
js_delete(table); js_delete(table);
table = nullptr; table = nullptr;
return nullptr; return nullptr;

View File

@ -61,7 +61,7 @@ NewObjectCache::newObjectFromHit(JSContext* cx, EntryIndex entryIndex, gc::Initi
return nullptr; return nullptr;
NativeObject* obj = static_cast<NativeObject*>(Allocate<JSObject, NoGC>(cx, entry->kind, 0, NativeObject* obj = static_cast<NativeObject*>(Allocate<JSObject, NoGC>(cx, entry->kind, 0,
heap, group->clasp())); heap, group->clasp()));
if (!obj) if (!obj)
return nullptr; return nullptr;

View File

@ -475,8 +475,11 @@ JSRope::flattenInternal(ExclusiveContext* maybecx)
} }
} }
if (!AllocChars(this, wholeLength, &wholeChars, &wholeCapacity)) if (!AllocChars(this, wholeLength, &wholeChars, &wholeCapacity)) {
if (maybecx)
ReportOutOfMemory(maybecx);
return nullptr; return nullptr;
}
pos = wholeChars; pos = wholeChars;
first_visit_node: { first_visit_node: {