js/src/jsapi-tests/testDefineGetterSetterNonEnumerable.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 static bool
    11 NativeGetterSetter(JSContext *cx, unsigned argc, jsval *vp)
    12 {
    13     return true;
    14 }
    16 BEGIN_TEST(testDefineGetterSetterNonEnumerable)
    17 {
    18     static const char PROPERTY_NAME[] = "foo";
    20     JS::RootedValue vobj(cx);
    21     JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
    22     CHECK(obj);
    23     vobj = OBJECT_TO_JSVAL(obj);
    25     JSFunction *funGet = JS_NewFunction(cx, NativeGetterSetter, 0, 0, JS::NullPtr(), "get");
    26     CHECK(funGet);
    27     JS::RootedObject funGetObj(cx, JS_GetFunctionObject(funGet));
    28     JS::RootedValue vget(cx, OBJECT_TO_JSVAL(funGetObj));
    30     JSFunction *funSet = JS_NewFunction(cx, NativeGetterSetter, 1, 0, JS::NullPtr(), "set");
    31     CHECK(funSet);
    32     JS::RootedObject funSetObj(cx, JS_GetFunctionObject(funSet));
    33     JS::RootedValue vset(cx, OBJECT_TO_JSVAL(funSetObj));
    35     JS::RootedObject vObject(cx, JSVAL_TO_OBJECT(vobj));
    36     CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME,
    37                             JS::UndefinedHandleValue,
    38                             JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_ENUMERATE,
    39                             JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj),
    40                             JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj)));
    42     CHECK(JS_DefineProperty(cx, vObject, PROPERTY_NAME,
    43                             JS::UndefinedHandleValue,
    44                             JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED | JSPROP_PERMANENT,
    45                             JS_DATA_TO_FUNC_PTR(JSPropertyOp, (JSObject*) funGetObj),
    46                             JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, (JSObject*) funSetObj)));
    48     JS::Rooted<JSPropertyDescriptor> desc(cx);
    49     CHECK(JS_GetOwnPropertyDescriptor(cx, vObject, PROPERTY_NAME, &desc));
    50     CHECK(desc.object());
    51     CHECK(desc.hasGetterObject());
    52     CHECK(desc.hasSetterObject());
    53     CHECK(desc.isPermanent());
    54     CHECK(!desc.isEnumerable());
    56     return true;
    57 }
    58 END_TEST(testDefineGetterSetterNonEnumerable)

mercurial