js/src/jsapi-tests/testGCOutOfMemory.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     3  *
     4  * Any copyright is dedicated to the Public Domain.
     5  * http://creativecommons.org/licenses/publicdomain/
     6  * Contributor: Igor Bukanov
     7  */
     9 #include "jsapi-tests/tests.h"
    11 static unsigned errorCount = 0;
    13 static void
    14 ErrorCounter(JSContext *cx, const char *message, JSErrorReport *report)
    15 {
    16     ++errorCount;
    17 }
    19 BEGIN_TEST(testGCOutOfMemory)
    20 {
    21     JS_SetErrorReporter(cx, ErrorCounter);
    23     JS::RootedValue root(cx);
    25     static const char source[] =
    26         "var max = 0; (function() {"
    27         "    var array = [];"
    28         "    for (; ; ++max)"
    29         "        array.push({});"
    30         "    array = []; array.push(0);"
    31         "})();";
    32     bool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1, &root);
    34     /* Check that we get OOM. */
    35     CHECK(!ok);
    36     CHECK(!JS_IsExceptionPending(cx));
    37     CHECK_EQUAL(errorCount, 1);
    38     JS_GC(rt);
    40     // Temporarily disabled to reopen the tree. Bug 847579.
    41     return true;
    43     EVAL("(function() {"
    44          "    var array = [];"
    45          "    for (var i = max >> 2; i != 0;) {"
    46          "        --i;"
    47          "        array.push({});"
    48          "    }"
    49          "})();", &root);
    50     CHECK_EQUAL(errorCount, 1);
    51     return true;
    52 }
    54 virtual JSRuntime * createRuntime() {
    55     JSRuntime *rt = JS_NewRuntime(768 * 1024, JS_USE_HELPER_THREADS);
    56     if (!rt)
    57         return nullptr;
    58     setNativeStackQuota(rt);
    59     return rt;
    60 }
    62 virtual void destroyRuntime() {
    63     JS_DestroyRuntime(rt);
    64 }
    66 END_TEST(testGCOutOfMemory)

mercurial