Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jsapi-tests / testContexts.cpp
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sw=4 et tw=99:
3  */
4
5 #include "tests.h"
6
7 BEGIN_TEST(testContexts_IsRunning)
8     {
9         CHECK(JS_DefineFunction(cx, global, "chk", chk, 0, 0));
10         EXEC("for (var i = 0; i < 9; i++) chk();");
11         return true;
12     }
13
14     static JSBool chk(JSContext *cx, uintN argc, jsval *vp)
15     {
16         JSRuntime *rt = JS_GetRuntime(cx);
17         JSContext *acx = JS_NewContext(rt, 8192);
18         if (!acx) {
19             JS_ReportOutOfMemory(cx);
20             return JS_FALSE;
21         }
22
23         // acx should not be running
24         bool ok = !JS_IsRunning(acx);
25         if (!ok)
26             JS_ReportError(cx, "Assertion failed: brand new context claims to be running");
27         JS_DestroyContext(acx);
28         return ok;
29     }
30 END_TEST(testContexts_IsRunning)
31
32 BEGIN_TEST(testContexts_bug563735)
33 {
34     JSContext *cx2 = JS_NewContext(rt, 8192);
35     CHECK(cx2);
36
37     JSBool ok;
38     {
39         JSAutoRequest req(cx2);
40         JSAutoEnterCompartment ac;
41         CHECK(ac.enter(cx2, global));
42         jsval v = JSVAL_NULL;
43         ok = JS_SetProperty(cx2, global, "x", &v);
44     }
45     CHECK(ok);
46
47     EXEC("(function () { for (var i = 0; i < 9; i++) ; })();");
48
49     JS_DestroyContext(cx2);
50     return true;
51 }
52 END_TEST(testContexts_bug563735)