diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testGCOutOfMemory.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testGCOutOfMemory.cpp')
-rw-r--r-- | js/src/jsapi-tests/testGCOutOfMemory.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testGCOutOfMemory.cpp b/js/src/jsapi-tests/testGCOutOfMemory.cpp new file mode 100644 index 000000000..9f8302890 --- /dev/null +++ b/js/src/jsapi-tests/testGCOutOfMemory.cpp @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: Igor Bukanov + */ + +#include "jsapi-tests/tests.h" + +BEGIN_TEST(testGCOutOfMemory) +{ + JS::RootedValue root(cx); + + // Count the number of allocations until we hit OOM, and store it in 'max'. + static const char source[] = + "var max = 0; (function() {" + " var array = [];" + " for (; ; ++max)" + " array.push({});" + " array = []; array.push(0);" + "})();"; + JS::CompileOptions opts(cx); + bool ok = JS::Evaluate(cx, opts, source, strlen(source), &root); + + /* Check that we get OOM. */ + CHECK(!ok); + CHECK(JS_GetPendingException(cx, &root)); + CHECK(root.isString()); + bool match = false; + CHECK(JS_StringEqualsAscii(cx, root.toString(), "out of memory", &match)); + CHECK(match); + JS_ClearPendingException(cx); + + JS_GC(cx); + + // The above GC should have discarded everything. Verify that we can now + // allocate half as many objects without OOMing. + EVAL("(function() {" + " var array = [];" + " for (var i = max >> 2; i != 0;) {" + " --i;" + " array.push({});" + " }" + "})();", &root); + CHECK(!JS_IsExceptionPending(cx)); + return true; +} + +virtual JSContext* createContext() override { + // Note that the max nursery size must be less than the whole heap size, or + // the test will fail because 'max' (the number of allocations required for + // OOM) will be based on the nursery size, and that will overflow the + // tenured heap, which will cause the second pass with max/4 allocations to + // OOM. (Actually, this only happens with nursery zeal, because normally + // the nursery will start out with only a single chunk before triggering a + // major GC.) + JSContext* cx = JS_NewContext(1024 * 1024, 128 * 1024); + if (!cx) + return nullptr; + setNativeStackQuota(cx); + return cx; +} + +virtual void destroyContext() override { + JS_DestroyContext(cx); +} + +END_TEST(testGCOutOfMemory) |