|
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 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "jsapi-tests/tests.h" |
|
8 |
|
9 BEGIN_TEST(testContexts_IsRunning) |
|
10 { |
|
11 CHECK(JS_DefineFunction(cx, global, "chk", chk, 0, 0)); |
|
12 EXEC("for (var i = 0; i < 9; i++) chk();"); |
|
13 return true; |
|
14 } |
|
15 |
|
16 static bool chk(JSContext *cx, unsigned argc, jsval *vp) |
|
17 { |
|
18 JSRuntime *rt = JS_GetRuntime(cx); |
|
19 JSContext *acx = JS_NewContext(rt, 8192); |
|
20 if (!acx) { |
|
21 JS_ReportOutOfMemory(cx); |
|
22 return false; |
|
23 } |
|
24 |
|
25 // acx should not be running |
|
26 bool ok = !JS_IsRunning(acx); |
|
27 if (!ok) |
|
28 JS_ReportError(cx, "Assertion failed: brand new context claims to be running"); |
|
29 JS_DestroyContext(acx); |
|
30 return ok; |
|
31 } |
|
32 END_TEST(testContexts_IsRunning) |
|
33 |
|
34 BEGIN_TEST(testContexts_bug563735) |
|
35 { |
|
36 JSContext *cx2 = JS_NewContext(rt, 8192); |
|
37 CHECK(cx2); |
|
38 |
|
39 bool ok; |
|
40 { |
|
41 JSAutoRequest req(cx2); |
|
42 JSAutoCompartment ac(cx2, global); |
|
43 JS::RootedValue v(cx2); |
|
44 ok = JS_SetProperty(cx2, global, "x", v); |
|
45 } |
|
46 CHECK(ok); |
|
47 |
|
48 EXEC("(function () { for (var i = 0; i < 9; i++) ; })();"); |
|
49 |
|
50 JS_DestroyContext(cx2); |
|
51 return true; |
|
52 } |
|
53 END_TEST(testContexts_bug563735) |