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

This commit is contained in:
Jon Coppeard 2015-07-01 18:53:04 +01:00
parent 36fef836ec
commit 49efb3d692
10 changed files with 57 additions and 19 deletions

View File

@ -1787,7 +1787,8 @@ InitTypeClasses(JSContext* cx, HandleObject ctypesObj)
// * __proto__ === 'p', the prototype object from above
// * 'constructor' property === 't'
AutoObjectVector protos(cx);
protos.resize(CTYPEPROTO_SLOTS);
if (!protos.resize(CTYPEPROTO_SLOTS))
return false;
if (!InitTypeConstructor(cx, ctypesObj, CTypeProto, CDataProto,
sPointerFunction, nullptr, sPointerProps,
sPointerInstanceFunctions, sPointerInstanceProps,

View File

@ -1916,8 +1916,10 @@ Parser<FullParseHandler>::checkFunctionDefinition(HandlePropertyName funName,
*/
if (!pc->funcStmts) {
pc->funcStmts = alloc.new_<FuncStmtSet>(alloc);
if (!pc->funcStmts || !pc->funcStmts->init())
if (!pc->funcStmts || !pc->funcStmts->init()) {
ReportOutOfMemory(context);
return false;
}
}
if (!pc->funcStmts->put(funName))
return false;

View File

@ -176,8 +176,11 @@ GCRuntime::tryNewTenuredObject(ExclusiveContext* cx, AllocKind kind, size_t thin
HeapSlot* slots = nullptr;
if (nDynamicSlots) {
slots = cx->zone()->pod_malloc<HeapSlot>(nDynamicSlots);
if (MOZ_UNLIKELY(!slots))
if (MOZ_UNLIKELY(!slots)) {
if (allowGC)
ReportOutOfMemory(cx);
return nullptr;
}
Debug_SetSlotRangeToCrashOnTouch(slots, nDynamicSlots);
}

View File

@ -206,8 +206,10 @@ BaselineCompiler::compile()
pcEntries.length(),
bytecodeTypeMapEntries,
yieldOffsets_.length()));
if (!baselineScript)
if (!baselineScript) {
ReportOutOfMemory(cx);
return Method_Error;
}
baselineScript->setMethod(code);
baselineScript->setTemplateScope(templateScope);

View File

@ -379,9 +379,14 @@ bool
JitCompartment::initialize(JSContext* cx)
{
stubCodes_ = cx->new_<ICStubCodeMap>(cx);
if (!stubCodes_ || !stubCodes_->init())
if (!stubCodes_)
return false;
if (!stubCodes_->init()) {
ReportOutOfMemory(cx);
return false;
}
return true;
}

View File

@ -1761,8 +1761,10 @@ ScriptSource::ensureOwnsSource(ExclusiveContext* cx)
return true;
char16_t* uncompressed = cx->zone()->pod_malloc<char16_t>(Max<size_t>(length_, 1));
if (!uncompressed)
if (!uncompressed) {
ReportOutOfMemory(cx);
return false;
}
PodCopy(uncompressed, uncompressedChars(), length_);
data.uncompressed.chars = uncompressed;
@ -2083,8 +2085,10 @@ FormatIntroducedFilename(ExclusiveContext* cx, const char* filename, unsigned li
introducerLen +
1 /* \0 */;
char* formatted = cx->zone()->pod_malloc<char>(len);
if (!formatted)
if (!formatted) {
ReportOutOfMemory(cx);
return nullptr;
}
mozilla::DebugOnly<size_t> checkLen = JS_snprintf(formatted, len, "%s line %s > %s",
filename, linenoBuf, introducer);
MOZ_ASSERT(checkLen == len - 1);
@ -2199,8 +2203,10 @@ js::SharedScriptData::new_(ExclusiveContext* cx, uint32_t codeLength,
SharedScriptData* entry = reinterpret_cast<SharedScriptData*>(
cx->zone()->pod_malloc<uint8_t>(length + dataOffset));
if (!entry)
if (!entry) {
ReportOutOfMemory(cx);
return nullptr;
}
entry->length = length;
entry->natoms = natoms;
@ -2521,8 +2527,10 @@ JSScript::partiallyInit(ExclusiveContext* cx, HandleScript script, uint32_t ncon
size_t size = ScriptDataSize(script->bindings.count(), nconsts, nobjects, nregexps, ntrynotes,
nblockscopes, nyieldoffsets);
script->data = AllocScriptData(script->zone(), size);
if (size && !script->data)
if (size && !script->data) {
ReportOutOfMemory(cx);
return false;
}
script->dataSize_ = size;
MOZ_ASSERT(nTypeSets <= UINT16_MAX);
@ -3899,8 +3907,10 @@ LazyScript::CreateRaw(ExclusiveContext* cx, HandleFunction fun,
+ (p.numInnerFunctions * sizeof(HeapPtrFunction));
ScopedJSFreePtr<uint8_t> table(bytes ? fun->zone()->pod_malloc<uint8_t>(bytes) : nullptr);
if (bytes && !table)
if (bytes && !table) {
ReportOutOfMemory(cx);
return nullptr;
}
LazyScript* res = Allocate<LazyScript>(cx);
if (!res)

View File

@ -1023,13 +1023,17 @@ ObjectGroup::newPlainObject(ExclusiveContext* cx, IdValuePair* properties, size_
preliminaryObjects->registerNewObject(obj);
ScopedJSFreePtr<jsid> ids(group->zone()->pod_calloc<jsid>(nproperties));
if (!ids)
if (!ids) {
ReportOutOfMemory(cx);
return nullptr;
}
ScopedJSFreePtr<TypeSet::Type> types(
group->zone()->pod_calloc<TypeSet::Type>(nproperties));
if (!types)
if (!types) {
ReportOutOfMemory(cx);
return nullptr;
}
for (size_t i = 0; i < nproperties; i++) {
ids[i] = properties[i].id;

View File

@ -42,8 +42,10 @@ ProxyObject::New(JSContext* cx, const BaseProxyHandler* handler, HandleValue pri
allocKind = GetBackgroundAllocKind(allocKind);
ProxyValueArray* values = cx->zone()->new_<ProxyValueArray>();
if (!values)
if (!values) {
ReportOutOfMemory(cx);
return nullptr;
}
// Note: this will initialize the object's |data| to strange values, but we
// will immediately overwrite those below.

View File

@ -307,10 +307,13 @@ ShapeTable::grow(ExclusiveContext* cx)
MOZ_ASSERT(entryCount_ + removedCount_ <= size - 1);
if (!change(delta, cx) && entryCount_ + removedCount_ == size - 1) {
ReportOutOfMemory(cx);
return false;
if (!change(delta, cx)) {
if (entryCount_ + removedCount_ == size - 1)
return false;
cx->recoverFromOutOfMemory();
}
return true;
}

View File

@ -3289,8 +3289,10 @@ JSScript::makeTypes(JSContext* cx)
TypeScript* typeScript = (TypeScript*)
zone()->pod_calloc<uint8_t>(TypeScript::SizeIncludingTypeArray(count));
if (!typeScript)
if (!typeScript) {
ReportOutOfMemory(cx);
return false;
}
types_ = typeScript;
setTypesGeneration(cx->zone()->types.generation);
@ -3543,8 +3545,10 @@ TypeNewScript::makeNativeVersion(JSContext* cx, TypeNewScript* newScript,
size_t initializerLength = cursor - newScript->initializerList + 1;
nativeNewScript->initializerList = cx->zone()->pod_calloc<Initializer>(initializerLength);
if (!nativeNewScript->initializerList)
if (!nativeNewScript->initializerList) {
ReportOutOfMemory(cx);
return nullptr;
}
PodCopy(nativeNewScript->initializerList, newScript->initializerList, initializerLength);
return nativeNewScript.forget();
@ -3751,8 +3755,10 @@ TypeNewScript::maybeAnalyze(JSContext* cx, ObjectGroup* group, bool* regenerate,
return false;
initializerList = group->zone()->pod_calloc<Initializer>(initializerVector.length());
if (!initializerList)
if (!initializerList) {
ReportOutOfMemory(cx);
return false;
}
PodCopy(initializerList, initializerVector.begin(), initializerVector.length());
}