Bug 987995, part 2 - Add a data parameter to two memory-pressure-related callbacks. r=luke.

This commit is contained in:
Jason Orendorff 2014-05-22 08:18:01 -05:00
parent 961997c4b5
commit 1387145693
9 changed files with 21 additions and 15 deletions

View File

@ -2913,7 +2913,7 @@ AsmJSCacheOpenEntryForWrite(JS::Handle<JSObject*> aGlobal,
}
static void
OnLargeAllocationFailure()
OnLargeAllocationFailure(void* data)
{
nsCOMPtr<nsIObserverService> os =
mozilla::services::GetObserverService();
@ -2981,7 +2981,7 @@ nsJSContext::EnsureStatics()
};
JS::SetAsmJSCacheOps(sRuntime, &asmJSCacheOps);
JS::SetLargeAllocationFailureCallback(sRuntime, OnLargeAllocationFailure);
JS::SetLargeAllocationFailureCallback(sRuntime, OnLargeAllocationFailure, nullptr);
// Set these global xpconnect options...
Preferences::RegisterCallbackAndCall(ReportAllJSExceptionsPrefChangedCallback,

View File

@ -6576,14 +6576,17 @@ JSAutoByteString::encodeLatin1(ExclusiveContext *cx, JSString *str)
}
JS_PUBLIC_API(void)
JS::SetLargeAllocationFailureCallback(JSRuntime *rt, JS::LargeAllocationFailureCallback lafc)
JS::SetLargeAllocationFailureCallback(JSRuntime *rt, JS::LargeAllocationFailureCallback lafc,
void *data)
{
rt->largeAllocationFailureCallback = lafc;
rt->largeAllocationFailureCallbackData = data;
}
JS_PUBLIC_API(void)
JS::SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb)
JS::SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data)
{
rt->oomCallback = cb;
rt->oomCallbackData = data;
}

View File

@ -5059,10 +5059,10 @@ class MOZ_STACK_CLASS JS_PUBLIC_API(ForOfIterator) {
*/
typedef void
(* LargeAllocationFailureCallback)();
(* LargeAllocationFailureCallback)(void *data);
extern JS_PUBLIC_API(void)
SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc);
SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback afc, void *data);
/*
* Unlike the error reporter, which is only called if the exception for an OOM
@ -5076,10 +5076,10 @@ SetLargeAllocationFailureCallback(JSRuntime *rt, LargeAllocationFailureCallback
*/
typedef void
(* OutOfMemoryCallback)(JSContext *cx);
(* OutOfMemoryCallback)(JSContext *cx, void *data);
extern JS_PUBLIC_API(void)
SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb);
SetOutOfMemoryCallback(JSRuntime *rt, OutOfMemoryCallback cb, void *data);
} /* namespace JS */

View File

@ -376,7 +376,7 @@ js_ReportOutOfMemory(ThreadSafeContext *cxArg)
/* Report the oom. */
if (JS::OutOfMemoryCallback oomCallback = cx->runtime()->oomCallback) {
AutoSuppressGC suppressGC(cx);
oomCallback(cx);
oomCallback(cx, cx->runtime()->oomCallbackData);
}
if (JS_IsRunning(cx)) {

View File

@ -5016,7 +5016,7 @@ my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
}
static void
my_OOMCallback(JSContext *cx)
my_OOMCallback(JSContext *cx, void *data)
{
// If a script is running, the engine is about to throw the string "out of
// memory", which may or may not be caught. Otherwise the engine will just
@ -6263,7 +6263,7 @@ main(int argc, char **argv, char **envp)
if (!rt)
return 1;
JS::SetOutOfMemoryCallback(rt, my_OOMCallback);
JS::SetOutOfMemoryCallback(rt, my_OOMCallback, nullptr);
if (!SetRuntimeOptions(rt, op))
return 1;

View File

@ -772,7 +772,7 @@ JSRuntime::onOutOfMemoryCanGC(void *p, size_t bytes)
{
if (!largeAllocationFailureCallback || bytes < LARGE_ALLOCATION)
return nullptr;
largeAllocationFailureCallback();
largeAllocationFailureCallback(largeAllocationFailureCallbackData);
return onOutOfMemory(p, bytes);
}

View File

@ -1395,8 +1395,11 @@ struct JSRuntime : public JS::shadow::Runtime,
/* See comment for JS::SetLargeAllocationFailureCallback in jsapi.h. */
JS::LargeAllocationFailureCallback largeAllocationFailureCallback;
void *largeAllocationFailureCallbackData;
/* See comment for JS::SetOutOfMemoryCallback in jsapi.h. */
JS::OutOfMemoryCallback oomCallback;
void *oomCallbackData;
/*
* These variations of malloc/calloc/realloc will call the

View File

@ -1437,7 +1437,7 @@ XPCJSRuntime::InterruptCallback(JSContext *cx)
}
/* static */ void
XPCJSRuntime::OutOfMemoryCallback(JSContext *cx)
XPCJSRuntime::OutOfMemoryCallback(JSContext *cx, void *data)
{
if (!Preferences::GetBool("memory.dump_reports_on_oom")) {
return;
@ -3178,7 +3178,7 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
js::SetActivityCallback(runtime, ActivityCallback, this);
js::SetCTypesActivityCallback(runtime, CTypesActivityCallback);
JS_SetInterruptCallback(runtime, InterruptCallback);
JS::SetOutOfMemoryCallback(runtime, OutOfMemoryCallback);
JS::SetOutOfMemoryCallback(runtime, OutOfMemoryCallback, nullptr);
// The JS engine needs to keep the source code around in order to implement
// Function.prototype.toSource(). It'd be nice to not have to do this for

View File

@ -547,7 +547,7 @@ public:
static void CTypesActivityCallback(JSContext *cx,
js::CTypesActivityType type);
static bool InterruptCallback(JSContext *cx);
static void OutOfMemoryCallback(JSContext *cx);
static void OutOfMemoryCallback(JSContext *cx, void *data);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);