js/src/jsapi-tests/testDeepFreeze.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "jsapi-tests/tests.h"
michael@0 9
michael@0 10 BEGIN_TEST(testDeepFreeze_bug535703)
michael@0 11 {
michael@0 12 JS::RootedValue v(cx);
michael@0 13 EVAL("var x = {}; x;", &v);
michael@0 14 JS::RootedObject obj(cx, JSVAL_TO_OBJECT(v));
michael@0 15 CHECK(JS_DeepFreezeObject(cx, obj)); // don't crash
michael@0 16 EVAL("Object.isFrozen(x)", &v);
michael@0 17 CHECK_SAME(v, JSVAL_TRUE);
michael@0 18 return true;
michael@0 19 }
michael@0 20 END_TEST(testDeepFreeze_bug535703)
michael@0 21
michael@0 22 BEGIN_TEST(testDeepFreeze_deep)
michael@0 23 {
michael@0 24 JS::RootedValue a(cx), o(cx);
michael@0 25 EXEC("var a = {}, o = a;\n"
michael@0 26 "for (var i = 0; i < 5000; i++)\n"
michael@0 27 " a = {x: a, y: a};\n");
michael@0 28 EVAL("a", &a);
michael@0 29 EVAL("o", &o);
michael@0 30
michael@0 31 JS::RootedObject aobj(cx, JSVAL_TO_OBJECT(a));
michael@0 32 CHECK(JS_DeepFreezeObject(cx, aobj));
michael@0 33
michael@0 34 JS::RootedValue b(cx);
michael@0 35 EVAL("Object.isFrozen(a)", &b);
michael@0 36 CHECK_SAME(b, JSVAL_TRUE);
michael@0 37 EVAL("Object.isFrozen(o)", &b);
michael@0 38 CHECK_SAME(b, JSVAL_TRUE);
michael@0 39 return true;
michael@0 40 }
michael@0 41 END_TEST(testDeepFreeze_deep)
michael@0 42
michael@0 43 BEGIN_TEST(testDeepFreeze_loop)
michael@0 44 {
michael@0 45 JS::RootedValue x(cx), y(cx);
michael@0 46 EXEC("var x = [], y = {x: x}; y.y = y; x.push(x, y);");
michael@0 47 EVAL("x", &x);
michael@0 48 EVAL("y", &y);
michael@0 49
michael@0 50 JS::RootedObject xobj(cx, JSVAL_TO_OBJECT(x));
michael@0 51 CHECK(JS_DeepFreezeObject(cx, xobj));
michael@0 52
michael@0 53 JS::RootedValue b(cx);
michael@0 54 EVAL("Object.isFrozen(x)", &b);
michael@0 55 CHECK_SAME(b, JSVAL_TRUE);
michael@0 56 EVAL("Object.isFrozen(y)", &b);
michael@0 57 CHECK_SAME(b, JSVAL_TRUE);
michael@0 58 return true;
michael@0 59 }
michael@0 60 END_TEST(testDeepFreeze_loop)

mercurial