Bug 734976 - Call js_ReportOutOfMemory in jsgcinlines when simulating OOM. Original patch by Brian Hackett. r=luke,bhackett,jdemooij
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -153,19 +153,30 @@ PrintBacktrace()
do \
{ \
if (++OOM_counter > OOM_maxAllocations) { \
JS_OOM_EMIT_BACKTRACE();\
return NULL; \
} \
} while (0)
+# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \
+ do \
+ { \
+ if (++OOM_counter > OOM_maxAllocations) { \
+ JS_OOM_EMIT_BACKTRACE();\
+ js_ReportOutOfMemory(cx);\
+ return NULL; \
+ } \
+ } while (0)
+
# else
# define JS_OOM_POSSIBLY_FAIL() do {} while(0)
-# endif
+# define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0)
+# endif /* DEBUG */
/*
* SpiderMonkey code should not be calling these allocation functions directly.
* Instead, all calls should go through JSRuntime, JSContext or OffTheBooks.
* However, js_free() can be called directly.
*/
static JS_INLINE void* js_malloc(size_t bytes)
{
--- a/js/src/jsgcinlines.h
+++ b/js/src/jsgcinlines.h
@@ -435,17 +435,17 @@ NewGCThing(JSContext *cx, js::gc::AllocK
#ifdef JS_THREADSAFE
JS_ASSERT_IF((cx->compartment == cx->runtime->atomsCompartment),
kind == js::gc::FINALIZE_STRING || kind == js::gc::FINALIZE_SHORT_STRING);
#endif
JS_ASSERT(!cx->runtime->gcRunning);
JS_ASSERT(!cx->runtime->noGCOrAllocationCheck);
/* For testing out of memory conditions */
- JS_OOM_POSSIBLY_FAIL();
+ JS_OOM_POSSIBLY_FAIL_REPORT(cx);
#ifdef JS_GC_ZEAL
if (cx->runtime->needZealousGC())
js::gc::RunDebugGC(cx);
#endif
js::gc::MaybeCheckStackRoots(cx);