js/src/jsapi-tests/testDeepFreeze.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     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 {
    12     JS::RootedValue v(cx);
    13     EVAL("var x = {}; x;", &v);
    14     JS::RootedObject obj(cx, JSVAL_TO_OBJECT(v));
    15     CHECK(JS_DeepFreezeObject(cx, obj));  // don't crash
    16     EVAL("Object.isFrozen(x)", &v);
    17     CHECK_SAME(v, JSVAL_TRUE);
    18     return true;
    19 }
    20 END_TEST(testDeepFreeze_bug535703)
    22 BEGIN_TEST(testDeepFreeze_deep)
    23 {
    24     JS::RootedValue a(cx), o(cx);
    25     EXEC("var a = {}, o = a;\n"
    26          "for (var i = 0; i < 5000; i++)\n"
    27          "    a = {x: a, y: a};\n");
    28     EVAL("a", &a);
    29     EVAL("o", &o);
    31     JS::RootedObject aobj(cx, JSVAL_TO_OBJECT(a));
    32     CHECK(JS_DeepFreezeObject(cx, aobj));
    34     JS::RootedValue b(cx);
    35     EVAL("Object.isFrozen(a)", &b);
    36     CHECK_SAME(b, JSVAL_TRUE);
    37     EVAL("Object.isFrozen(o)", &b);
    38     CHECK_SAME(b, JSVAL_TRUE);
    39     return true;
    40 }
    41 END_TEST(testDeepFreeze_deep)
    43 BEGIN_TEST(testDeepFreeze_loop)
    44 {
    45     JS::RootedValue x(cx), y(cx);
    46     EXEC("var x = [], y = {x: x}; y.y = y; x.push(x, y);");
    47     EVAL("x", &x);
    48     EVAL("y", &y);
    50     JS::RootedObject xobj(cx, JSVAL_TO_OBJECT(x));
    51     CHECK(JS_DeepFreezeObject(cx, xobj));
    53     JS::RootedValue b(cx);
    54     EVAL("Object.isFrozen(x)", &b);
    55     CHECK_SAME(b, JSVAL_TRUE);
    56     EVAL("Object.isFrozen(y)", &b);
    57     CHECK_SAME(b, JSVAL_TRUE);
    58     return true;
    59 }
    60 END_TEST(testDeepFreeze_loop)

mercurial