js/src/jsapi-tests/testOOM.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "mozilla/DebugOnly.h"
michael@0 6
michael@0 7 #include "jsapi-tests/tests.h"
michael@0 8
michael@0 9 BEGIN_TEST(testOOM)
michael@0 10 {
michael@0 11 JS::RootedValue v(cx, JS::Int32Value(9));
michael@0 12 JS::RootedString jsstr(cx, JS::ToString(cx, v));
michael@0 13 mozilla::DebugOnly<const jschar *> s = JS_GetStringCharsZ(cx, jsstr);
michael@0 14 JS_ASSERT(s[0] == '9' && s[1] == '\0');
michael@0 15 return true;
michael@0 16 }
michael@0 17
michael@0 18 virtual JSRuntime * createRuntime()
michael@0 19 {
michael@0 20 JSRuntime *rt = JS_NewRuntime(0, JS_USE_HELPER_THREADS);
michael@0 21 if (!rt)
michael@0 22 return nullptr;
michael@0 23 JS_SetGCParameter(rt, JSGC_MAX_BYTES, (uint32_t)-1);
michael@0 24 setNativeStackQuota(rt);
michael@0 25 return rt;
michael@0 26 }
michael@0 27 END_TEST(testOOM)
michael@0 28
michael@0 29 #ifdef DEBUG // OOM_maxAllocations is only available in debug builds.
michael@0 30
michael@0 31 const uint32_t maxAllocsPerTest = 100;
michael@0 32
michael@0 33 #define START_OOM_TEST(name) \
michael@0 34 testName = name; \
michael@0 35 printf("Test %s: started\n", testName); \
michael@0 36 for (oomAfter = 1; oomAfter < maxAllocsPerTest; ++oomAfter) { \
michael@0 37 setOOMAfter(oomAfter)
michael@0 38
michael@0 39 #define OOM_TEST_FINISHED \
michael@0 40 { \
michael@0 41 printf("Test %s: finished with %d allocations\n", \
michael@0 42 testName, oomAfter - 1); \
michael@0 43 break; \
michael@0 44 }
michael@0 45
michael@0 46 #define END_OOM_TEST \
michael@0 47 } \
michael@0 48 cancelOOMAfter(); \
michael@0 49 CHECK(oomAfter != maxAllocsPerTest)
michael@0 50
michael@0 51 BEGIN_TEST(testNewRuntime)
michael@0 52 {
michael@0 53 uninit(); // Get rid of test harness' original JSRuntime.
michael@0 54
michael@0 55 JSRuntime *rt;
michael@0 56 START_OOM_TEST("new runtime");
michael@0 57 rt = JS_NewRuntime(8L * 1024 * 1024, JS_USE_HELPER_THREADS);
michael@0 58 if (rt)
michael@0 59 OOM_TEST_FINISHED;
michael@0 60 END_OOM_TEST;
michael@0 61 JS_DestroyRuntime(rt);
michael@0 62 return true;
michael@0 63 }
michael@0 64
michael@0 65 const char* testName;
michael@0 66 uint32_t oomAfter;
michael@0 67
michael@0 68 void
michael@0 69 setOOMAfter(uint32_t numAllocs)
michael@0 70 {
michael@0 71 OOM_maxAllocations = OOM_counter + numAllocs;
michael@0 72 }
michael@0 73
michael@0 74 void
michael@0 75 cancelOOMAfter()
michael@0 76 {
michael@0 77 OOM_maxAllocations = UINT32_MAX;
michael@0 78 }
michael@0 79 END_TEST(testNewRuntime)
michael@0 80
michael@0 81 #endif

mercurial