js/src/jsapi-tests/testOps.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  * Tests for operators and implicit type conversion.
     5  */
     6 /* This Source Code Form is subject to the terms of the Mozilla Public
     7  * License, v. 2.0. If a copy of the MPL was not distributed with this
     8  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    10 #include "jsapi-tests/tests.h"
    12 static bool
    13 my_convert(JSContext* context, JS::HandleObject obj, JSType type, JS::MutableHandleValue rval)
    14 {
    15     if (type == JSTYPE_VOID || type == JSTYPE_STRING || type == JSTYPE_NUMBER || type == JSTYPE_BOOLEAN) {
    16         rval.set(JS_NumberValue(123));
    17         return true;
    18     }
    19     return false;
    20 }
    22 static const JSClass myClass = {
    23     "MyClass",
    24     0,
    25     JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
    26     JS_EnumerateStub, JS_ResolveStub, my_convert
    27 };
    29 static bool
    30 createMyObject(JSContext* context, unsigned argc, jsval *vp)
    31 {
    32     JS_BeginRequest(context);
    34     //JS_GC(context); //<- if we make GC here, all is ok
    36     JSObject* myObject = JS_NewObject(context, &myClass, JS::NullPtr(), JS::NullPtr());
    37     *vp = OBJECT_TO_JSVAL(myObject);
    39     JS_EndRequest(context);
    41     return true;
    42 }
    44 static const JSFunctionSpec s_functions[] =
    45 {
    46     JS_FN("createMyObject", createMyObject, 0, 0),
    47     JS_FS_END
    48 };
    50 BEGIN_TEST(testOps_bug559006)
    51 {
    52     CHECK(JS_DefineFunctions(cx, global, s_functions));
    54     EXEC("function main() { while(1) return 0 + createMyObject(); }");
    56     for (int i = 0; i < 9; i++) {
    57         JS::RootedValue rval(cx);
    58         CHECK(JS_CallFunctionName(cx, global, "main", JS::HandleValueArray::empty(),
    59                                   &rval));
    60         CHECK_SAME(rval, INT_TO_JSVAL(123));
    61     }
    62     return true;
    63 }
    64 END_TEST(testOps_bug559006)

mercurial