tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testDeepFreeze.cpp (1579B)


      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/. */
      7 
      8 #include "jsapi-tests/tests.h"
      9 
     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;
     18 }
     19 END_TEST(testDeepFreeze_bug535703)
     20 
     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);
     29 
     30  JS::RootedObject aobj(cx, a.toObjectOrNull());
     31  CHECK(JS_DeepFreezeObject(cx, aobj));
     32 
     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;
     39 }
     40 END_TEST(testDeepFreeze_deep)
     41 
     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);
     47 
     48  JS::RootedObject xobj(cx, x.toObjectOrNull());
     49  CHECK(JS_DeepFreezeObject(cx, xobj));
     50 
     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;
     57 }
     58 END_TEST(testDeepFreeze_loop)