Bug 1931736. Add missing braces around if/loop statements in layout/xul/. r=layout...
[gecko.git] / js / src / jsapi-tests / testDeepFreeze.cpp
bloba1b62b8ca4d8391d9731f4948f16ff072dcd576c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "jsapi-tests/tests.h"
10 BEGIN_TEST(testDeepFreeze_bug535703) {
11 JS::RootedValue v(cx);
12 EVAL("var x = {}; x;", &v);
13 JS::RootedObject obj(cx, v.toObjectOrNull());
14 CHECK(JS_DeepFreezeObject(cx, obj)); // don't crash
15 EVAL("Object.isFrozen(x)", &v);
16 CHECK(v.isTrue());
17 return true;
19 END_TEST(testDeepFreeze_bug535703)
21 BEGIN_TEST(testDeepFreeze_deep) {
22 JS::RootedValue a(cx), o(cx);
23 EXEC(
24 "var a = {}, o = a;\n"
25 "for (var i = 0; i < 5000; i++)\n"
26 " a = {x: a, y: a};\n");
27 EVAL("a", &a);
28 EVAL("o", &o);
30 JS::RootedObject aobj(cx, a.toObjectOrNull());
31 CHECK(JS_DeepFreezeObject(cx, aobj));
33 JS::RootedValue b(cx);
34 EVAL("Object.isFrozen(a)", &b);
35 CHECK(b.isTrue());
36 EVAL("Object.isFrozen(o)", &b);
37 CHECK(b.isTrue());
38 return true;
40 END_TEST(testDeepFreeze_deep)
42 BEGIN_TEST(testDeepFreeze_loop) {
43 JS::RootedValue x(cx), y(cx);
44 EXEC("var x = [], y = {x: x}; y.y = y; x.push(x, y);");
45 EVAL("x", &x);
46 EVAL("y", &y);
48 JS::RootedObject xobj(cx, x.toObjectOrNull());
49 CHECK(JS_DeepFreezeObject(cx, xobj));
51 JS::RootedValue b(cx);
52 EVAL("Object.isFrozen(x)", &b);
53 CHECK(b.isTrue());
54 EVAL("Object.isFrozen(y)", &b);
55 CHECK(b.isTrue());
56 return true;
58 END_TEST(testDeepFreeze_loop)