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:
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
);
19 END_TEST(testDeepFreeze_bug535703
)
21 BEGIN_TEST(testDeepFreeze_deep
) {
22 JS::RootedValue
a(cx
), o(cx
);
24 "var a = {}, o = a;\n"
25 "for (var i = 0; i < 5000; i++)\n"
26 " a = {x: a, y: a};\n");
30 JS::RootedObject
aobj(cx
, a
.toObjectOrNull());
31 CHECK(JS_DeepFreezeObject(cx
, aobj
));
33 JS::RootedValue
b(cx
);
34 EVAL("Object.isFrozen(a)", &b
);
36 EVAL("Object.isFrozen(o)", &b
);
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);");
48 JS::RootedObject
xobj(cx
, x
.toObjectOrNull());
49 CHECK(JS_DeepFreezeObject(cx
, xobj
));
51 JS::RootedValue
b(cx
);
52 EVAL("Object.isFrozen(x)", &b
);
54 EVAL("Object.isFrozen(y)", &b
);
58 END_TEST(testDeepFreeze_loop
)