js/src/jsapi-tests/testGCOutOfMemory.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jsapi-tests/testGCOutOfMemory.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + *
     1.7 + * Any copyright is dedicated to the Public Domain.
     1.8 + * http://creativecommons.org/licenses/publicdomain/
     1.9 + * Contributor: Igor Bukanov
    1.10 + */
    1.11 +
    1.12 +#include "jsapi-tests/tests.h"
    1.13 +
    1.14 +static unsigned errorCount = 0;
    1.15 +
    1.16 +static void
    1.17 +ErrorCounter(JSContext *cx, const char *message, JSErrorReport *report)
    1.18 +{
    1.19 +    ++errorCount;
    1.20 +}
    1.21 +
    1.22 +BEGIN_TEST(testGCOutOfMemory)
    1.23 +{
    1.24 +    JS_SetErrorReporter(cx, ErrorCounter);
    1.25 +
    1.26 +    JS::RootedValue root(cx);
    1.27 +
    1.28 +    static const char source[] =
    1.29 +        "var max = 0; (function() {"
    1.30 +        "    var array = [];"
    1.31 +        "    for (; ; ++max)"
    1.32 +        "        array.push({});"
    1.33 +        "    array = []; array.push(0);"
    1.34 +        "})();";
    1.35 +    bool ok = JS_EvaluateScript(cx, global, source, strlen(source), "", 1, &root);
    1.36 +
    1.37 +    /* Check that we get OOM. */
    1.38 +    CHECK(!ok);
    1.39 +    CHECK(!JS_IsExceptionPending(cx));
    1.40 +    CHECK_EQUAL(errorCount, 1);
    1.41 +    JS_GC(rt);
    1.42 +
    1.43 +    // Temporarily disabled to reopen the tree. Bug 847579.
    1.44 +    return true;
    1.45 +
    1.46 +    EVAL("(function() {"
    1.47 +         "    var array = [];"
    1.48 +         "    for (var i = max >> 2; i != 0;) {"
    1.49 +         "        --i;"
    1.50 +         "        array.push({});"
    1.51 +         "    }"
    1.52 +         "})();", &root);
    1.53 +    CHECK_EQUAL(errorCount, 1);
    1.54 +    return true;
    1.55 +}
    1.56 +
    1.57 +virtual JSRuntime * createRuntime() {
    1.58 +    JSRuntime *rt = JS_NewRuntime(768 * 1024, JS_USE_HELPER_THREADS);
    1.59 +    if (!rt)
    1.60 +        return nullptr;
    1.61 +    setNativeStackQuota(rt);
    1.62 +    return rt;
    1.63 +}
    1.64 +
    1.65 +virtual void destroyRuntime() {
    1.66 +    JS_DestroyRuntime(rt);
    1.67 +}
    1.68 +
    1.69 +END_TEST(testGCOutOfMemory)

mercurial