diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index f872036dd73..a1b3dae7838 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -1835,8 +1835,10 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp) ungetCharIgnoreEOL(nc); } - if (!tokenbuf.append(c)) + if (!tokenbuf.append(c)) { + ReportOutOfMemory(cx); return false; + } } JSAtom* atom = atomize(cx, tokenbuf); diff --git a/js/src/gc/Nursery-inl.h b/js/src/gc/Nursery-inl.h index bb3ba33a831..57f130b041f 100644 --- a/js/src/gc/Nursery-inl.h +++ b/js/src/gc/Nursery-inl.h @@ -54,7 +54,10 @@ AllocateObjectBuffer(ExclusiveContext* cx, JSObject* obj, uint32_t count) if (cx->isJSContext()) { Nursery& nursery = cx->asJSContext()->runtime()->gc.nursery; size_t nbytes = JS_ROUNDUP(count * sizeof(T), sizeof(Value)); - return static_cast(nursery.allocateBuffer(obj, nbytes)); + T* buffer = static_cast(nursery.allocateBuffer(obj, nbytes)); + if (!buffer) + ReportOutOfMemory(cx); + return buffer; } return obj->zone()->pod_malloc(count); } diff --git a/js/src/jit/BaselineCompiler.cpp b/js/src/jit/BaselineCompiler.cpp index 1333fb8d69e..fcbef01246c 100644 --- a/js/src/jit/BaselineCompiler.cpp +++ b/js/src/jit/BaselineCompiler.cpp @@ -151,8 +151,10 @@ BaselineCompiler::compile() indexEntry.pcOffset = entry.pcOffset; indexEntry.nativeOffset = entry.nativeOffset; indexEntry.bufferOffset = pcEntries.length(); - if (!pcMappingIndexEntries.append(indexEntry)) + if (!pcMappingIndexEntries.append(indexEntry)) { + ReportOutOfMemory(cx); return Method_Error; + } previousOffset = entry.nativeOffset; } diff --git a/js/src/jit/shared/BaselineCompiler-shared.h b/js/src/jit/shared/BaselineCompiler-shared.h index 5f2c6fe0bfe..8b521ddef21 100644 --- a/js/src/jit/shared/BaselineCompiler-shared.h +++ b/js/src/jit/shared/BaselineCompiler-shared.h @@ -98,7 +98,11 @@ class BaselineCompilerShared bool appendICEntry(ICEntry::Kind kind, uint32_t returnOffset) { ICEntry entry(script->pcToOffset(pc), kind); entry.setReturnOffset(CodeOffsetLabel(returnOffset)); - return icEntries_.append(entry); + if (!icEntries_.append(entry)) { + ReportOutOfMemory(cx); + return false; + } + return true; } bool addICLoadLabel(CodeOffsetLabel label) { @@ -106,7 +110,11 @@ class BaselineCompilerShared ICLoadLabel loadLabel; loadLabel.label = label; loadLabel.icEntry = icEntries_.length() - 1; - return icLoadLabels_.append(loadLabel); + if (!icLoadLabels_.append(loadLabel)) { + ReportOutOfMemory(cx); + return false; + } + return true; } JSFunction* function() const { diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp index 4f371ef47fb..7ea1215a856 100644 --- a/js/src/jsscript.cpp +++ b/js/src/jsscript.cpp @@ -148,8 +148,10 @@ Bindings::initWithTemporaryStorage(ExclusiveContext* cx, InternalBindingsHandle #ifdef DEBUG HashSet added(cx); - if (!added.init()) + if (!added.init()) { + ReportOutOfMemory(cx); return false; + } #endif uint32_t slot = CallObject::RESERVED_SLOTS; @@ -160,8 +162,10 @@ Bindings::initWithTemporaryStorage(ExclusiveContext* cx, InternalBindingsHandle #ifdef DEBUG // The caller ensures no duplicate aliased names. MOZ_ASSERT(!added.has(bi->name())); - if (!added.put(bi->name())) + if (!added.put(bi->name())) { + ReportOutOfMemory(cx); return false; + } #endif StackBaseShape stackBase(cx, &CallObject::class_, diff --git a/js/src/vm/ObjectGroup.cpp b/js/src/vm/ObjectGroup.cpp index b5cdcddf997..8dc637dca3a 100644 --- a/js/src/vm/ObjectGroup.cpp +++ b/js/src/vm/ObjectGroup.cpp @@ -824,6 +824,7 @@ ObjectGroup::setGroupToHomogenousArray(ExclusiveContext* cx, JSObject* obj, if (!table) { table = cx->new_(); if (!table || !table->init()) { + ReportOutOfMemory(cx); js_delete(table); table = nullptr; return; @@ -947,6 +948,7 @@ ObjectGroup::newPlainObject(ExclusiveContext* cx, IdValuePair* properties, size_ if (!table) { table = cx->new_(); if (!table || !table->init()) { + ReportOutOfMemory(cx); js_delete(table); table = nullptr; return nullptr; @@ -1135,6 +1137,7 @@ ObjectGroup::allocationSiteGroup(JSContext* cx, JSScript* script, jsbytecode* pc if (!table) { table = cx->new_(); if (!table || !table->init()) { + ReportOutOfMemory(cx); js_delete(table); table = nullptr; return nullptr; diff --git a/js/src/vm/Runtime-inl.h b/js/src/vm/Runtime-inl.h index e9ad4984e82..6b43bd2e77d 100644 --- a/js/src/vm/Runtime-inl.h +++ b/js/src/vm/Runtime-inl.h @@ -61,7 +61,7 @@ NewObjectCache::newObjectFromHit(JSContext* cx, EntryIndex entryIndex, gc::Initi return nullptr; NativeObject* obj = static_cast(Allocate(cx, entry->kind, 0, - heap, group->clasp())); + heap, group->clasp())); if (!obj) return nullptr; diff --git a/js/src/vm/String.cpp b/js/src/vm/String.cpp index 3c56001b153..0ceb9c6ba75 100644 --- a/js/src/vm/String.cpp +++ b/js/src/vm/String.cpp @@ -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; + } pos = wholeChars; first_visit_node: {