Bug 1155618 - Fix some more places where we didn't report OOM to the context r=terrence

This commit is contained in:
Jon Coppeard 2015-06-01 10:42:28 +01:00
parent 41d94a4c7a
commit b2304f79c4
7 changed files with 41 additions and 13 deletions

View File

@ -23,6 +23,8 @@ AtomThingMapPtr<Map>::ensureMap(ExclusiveContext* cx)
AutoLockForExclusiveAccess lock(cx);
map_ = cx->parseMapPool().acquire<Map>();
if (!map_)
ReportOutOfMemory(cx);
return !!map_;
}

View File

@ -42,7 +42,10 @@ AllocateObjectBuffer(ExclusiveContext* cx, 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<T*>(nursery.allocateBuffer(cx->zone(), nbytes));
T* buffer = static_cast<T*>(nursery.allocateBuffer(cx->zone(), nbytes));
if (!buffer)
ReportOutOfMemory(cx);
return buffer;
}
return cx->zone()->pod_malloc<T>(count);
}
@ -70,9 +73,12 @@ ReallocateObjectBuffer(ExclusiveContext* cx, JSObject* obj, T* oldBuffer,
{
if (cx->isJSContext()) {
Nursery& nursery = cx->asJSContext()->runtime()->gc.nursery;
return static_cast<T*>(nursery.reallocateBuffer(obj, oldBuffer,
oldCount * sizeof(T),
newCount * sizeof(T)));
T* buffer = static_cast<T*>(nursery.reallocateBuffer(obj, oldBuffer,
oldCount * sizeof(T),
newCount * sizeof(T)));
if (!buffer)
ReportOutOfMemory(cx);
return buffer;
}
return obj->zone()->pod_realloc<T>(oldBuffer, oldCount, newCount);
}

View File

@ -3500,8 +3500,11 @@ jit::AnalyzeArgumentsUsage(JSContext* cx, JSScript* scriptArg)
MIRGraph graph(&temp);
InlineScriptTree* inlineScriptTree = InlineScriptTree::New(&temp, nullptr, nullptr, script);
if (!inlineScriptTree)
if (!inlineScriptTree) {
ReportOutOfMemory(cx);
return false;
}
CompileInfo info(script, script->functionNonDelazifying(),
/* osrPc = */ nullptr, /* constructing = */ false,
Analysis_ArgumentsUsage,
@ -3511,8 +3514,10 @@ jit::AnalyzeArgumentsUsage(JSContext* cx, JSScript* scriptArg)
const OptimizationInfo* optimizationInfo = js_IonOptimizations.get(Optimization_Normal);
CompilerConstraintList* constraints = NewCompilerConstraintList(temp);
if (!constraints)
if (!constraints) {
ReportOutOfMemory(cx);
return false;
}
BaselineInspector inspector(script);
const JitCompileOptions options(cx);

View File

@ -4905,8 +4905,10 @@ EncodeLatin1(ExclusiveContext* cx, JSString* str)
size_t len = str->length();
Latin1Char* buf = cx->pod_malloc<Latin1Char>(len + 1);
if (!buf)
if (!buf) {
ReportOutOfMemory(cx);
return nullptr;
}
mozilla::PodCopy(buf, linear->latin1Chars(nogc), len);
buf[len] = '\0';

View File

@ -639,6 +639,7 @@ js::ExpandErrorArgumentsVA(ExclusiveContext* cx, JSErrorCallback callback,
*/
reportp->ucmessage = out = cx->pod_malloc<char16_t>(expandedLength + 1);
if (!out) {
ReportOutOfMemory(cx);
js_free(buffer);
goto error;
}

View File

@ -835,8 +835,10 @@ ToDisassemblySource(JSContext* cx, HandleValue v, JSAutoByteString* bytes)
if (!nbytes)
return false;
nbytes = JS_sprintf_append(nullptr, "%s", nbytes);
if (!nbytes)
if (!nbytes) {
ReportOutOfMemory(cx);
return false;
}
bytes->initBytes(nbytes);
return true;
}
@ -844,8 +846,10 @@ ToDisassemblySource(JSContext* cx, HandleValue v, JSAutoByteString* bytes)
JSRuntime* rt = cx->runtime();
if (rt->isHeapBusy() || !rt->gc.isAllocAllowed()) {
char* source = JS_sprintf_append(nullptr, "<value>");
if (!source)
if (!source) {
ReportOutOfMemory(cx);
return false;
}
bytes->initBytes(source);
return true;
}
@ -855,8 +859,10 @@ ToDisassemblySource(JSContext* cx, HandleValue v, JSAutoByteString* bytes)
if (obj.is<StaticBlockObject>()) {
Rooted<StaticBlockObject*> block(cx, &obj.as<StaticBlockObject>());
char* source = JS_sprintf_append(nullptr, "depth %d {", block->localOffset());
if (!source)
if (!source) {
ReportOutOfMemory(cx);
return false;
}
Shape::Range<CanGC> r(cx, block->lastProperty());
@ -875,13 +881,17 @@ ToDisassemblySource(JSContext* cx, HandleValue v, JSAutoByteString* bytes)
bytes.ptr(),
block->shapeToIndex(*shape),
!r.empty() ? ", " : "");
if (!source)
if (!source) {
ReportOutOfMemory(cx);
return false;
}
}
source = JS_sprintf_append(source, "}");
if (!source)
if (!source) {
ReportOutOfMemory(cx);
return false;
}
bytes->initBytes(source);
return true;
}

View File

@ -694,8 +694,10 @@ RegExpShared::execute(JSContext* cx, HandleLinearString input, size_t start,
* Ensure sufficient memory for output vector.
* No need to initialize it. The RegExp engine fills them in on a match.
*/
if (matches && !matches->allocOrExpandArray(pairCount()))
if (matches && !matches->allocOrExpandArray(pairCount())) {
ReportOutOfMemory(cx);
return RegExpRunStatus_Error;
}
/*
* |displacement| emulates sticky mode by matching from this offset