michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: * Contributor: Igor Bukanov michael@0: */ michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: static unsigned errorCount = 0; michael@0: michael@0: static void michael@0: ErrorCounter(JSContext *cx, const char *message, JSErrorReport *report) michael@0: { michael@0: ++errorCount; michael@0: } michael@0: michael@0: BEGIN_TEST(testGCOutOfMemory) michael@0: { michael@0: JS_SetErrorReporter(cx, ErrorCounter); michael@0: michael@0: JS::RootedValue root(cx); michael@0: michael@0: static const char source[] = michael@0: "var max = 0; (function() {" michael@0: " var array = [];" michael@0: " for (; ; ++max)" michael@0: " array.push({});" michael@0: " array = []; array.push(0);" michael@0: "})();"; michael@0: bool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1, &root); michael@0: michael@0: /* Check that we get OOM. */ michael@0: CHECK(!ok); michael@0: CHECK(!JS_IsExceptionPending(cx)); michael@0: CHECK_EQUAL(errorCount, 1); michael@0: JS_GC(rt); michael@0: michael@0: // Temporarily disabled to reopen the tree. Bug 847579. michael@0: return true; michael@0: michael@0: EVAL("(function() {" michael@0: " var array = [];" michael@0: " for (var i = max >> 2; i != 0;) {" michael@0: " --i;" michael@0: " array.push({});" michael@0: " }" michael@0: "})();", &root); michael@0: CHECK_EQUAL(errorCount, 1); michael@0: return true; michael@0: } michael@0: michael@0: virtual JSRuntime * createRuntime() { michael@0: JSRuntime *rt = JS_NewRuntime(768 * 1024, JS_USE_HELPER_THREADS); michael@0: if (!rt) michael@0: return nullptr; michael@0: setNativeStackQuota(rt); michael@0: return rt; michael@0: } michael@0: michael@0: virtual void destroyRuntime() { michael@0: JS_DestroyRuntime(rt); michael@0: } michael@0: michael@0: END_TEST(testGCOutOfMemory)