js/src/jsapi-tests/testContexts.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jsapi-tests/testContexts.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     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 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "jsapi-tests/tests.h"
    1.11 +
    1.12 +BEGIN_TEST(testContexts_IsRunning)
    1.13 +    {
    1.14 +        CHECK(JS_DefineFunction(cx, global, "chk", chk, 0, 0));
    1.15 +        EXEC("for (var i = 0; i < 9; i++) chk();");
    1.16 +        return true;
    1.17 +    }
    1.18 +
    1.19 +    static bool chk(JSContext *cx, unsigned argc, jsval *vp)
    1.20 +    {
    1.21 +        JSRuntime *rt = JS_GetRuntime(cx);
    1.22 +        JSContext *acx = JS_NewContext(rt, 8192);
    1.23 +        if (!acx) {
    1.24 +            JS_ReportOutOfMemory(cx);
    1.25 +            return false;
    1.26 +        }
    1.27 +
    1.28 +        // acx should not be running
    1.29 +        bool ok = !JS_IsRunning(acx);
    1.30 +        if (!ok)
    1.31 +            JS_ReportError(cx, "Assertion failed: brand new context claims to be running");
    1.32 +        JS_DestroyContext(acx);
    1.33 +        return ok;
    1.34 +    }
    1.35 +END_TEST(testContexts_IsRunning)
    1.36 +
    1.37 +BEGIN_TEST(testContexts_bug563735)
    1.38 +{
    1.39 +    JSContext *cx2 = JS_NewContext(rt, 8192);
    1.40 +    CHECK(cx2);
    1.41 +
    1.42 +    bool ok;
    1.43 +    {
    1.44 +        JSAutoRequest req(cx2);
    1.45 +        JSAutoCompartment ac(cx2, global);
    1.46 +        JS::RootedValue v(cx2);
    1.47 +        ok = JS_SetProperty(cx2, global, "x", v);
    1.48 +    }
    1.49 +    CHECK(ok);
    1.50 +
    1.51 +    EXEC("(function () { for (var i = 0; i < 9; i++) ; })();");
    1.52 +
    1.53 +    JS_DestroyContext(cx2);
    1.54 +    return true;
    1.55 +}
    1.56 +END_TEST(testContexts_bug563735)

mercurial