js/src/jsapi-tests/testEnclosingFunction.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  * Test script cloning.
     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 "jsfriendapi.h"
    12 #include "js/OldDebugAPI.h"
    13 #include "jsapi-tests/tests.h"
    15 using namespace js;
    17 static JSScript *foundScript = nullptr;
    19 static bool
    20 CheckEnclosing(JSContext *cx, unsigned argc, Value *vp)
    21 {
    22     CallArgs args = CallArgsFromVp(argc, vp);
    24     foundScript = js::GetOutermostEnclosingFunctionOfScriptedCaller(cx);
    26     args.rval().set(UndefinedValue());
    27     return true;
    28 }
    30 BEGIN_TEST(test_enclosingFunction)
    31 {
    32     CHECK(JS_DefineFunction(cx, global, "checkEnclosing", CheckEnclosing, 0, 0));
    34     EXEC("checkEnclosing()");
    35     CHECK(foundScript == nullptr);
    37     RootedFunction fun(cx);
    39     JS::CompileOptions options(cx);
    40     options.setFileAndLine(__FILE__, __LINE__);
    42     const char s1chars[] = "checkEnclosing()";
    43     fun = JS_CompileFunction(cx, global, "s1", 0, nullptr, s1chars,
    44                              strlen(s1chars), options);
    45     CHECK(fun);
    46     EXEC("s1()");
    47     CHECK(foundScript == JS_GetFunctionScript(cx, fun));
    49     const char s2chars[] = "return function() { checkEnclosing() }";
    50     fun = JS_CompileFunction(cx, global, "s2", 0, nullptr, s2chars,
    51                              strlen(s2chars), options);
    52     CHECK(fun);
    53     EXEC("s2()()");
    54     CHECK(foundScript == JS_GetFunctionScript(cx, fun));
    56     const char s3chars[] = "return function() { let (x) { function g() { checkEnclosing() } return g() } }";
    57     fun = JS_CompileFunction(cx, global, "s3", 0, nullptr, s3chars,
    58                              strlen(s3chars), options);
    59     CHECK(fun);
    60     EXEC("s3()()");
    61     CHECK(foundScript == JS_GetFunctionScript(cx, fun));
    63     return true;
    64 }
    65 END_TEST(test_enclosingFunction)

mercurial