Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | //----------------------------------------------------------------------------- |
michael@0 | 8 | var BUGNUMBER = 634472; |
michael@0 | 9 | var summary = 'contextual restrictions for yield and arguments'; |
michael@0 | 10 | var actual = ''; |
michael@0 | 11 | var expect = ''; |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | function error(str) { |
michael@0 | 15 | let base; |
michael@0 | 16 | try { |
michael@0 | 17 | // the following line must not be broken up into multiple lines |
michael@0 | 18 | base = (function(){try{eval('throw new Error()')}catch(e){return e.lineNumber}})(); eval(str); |
michael@0 | 19 | return null; |
michael@0 | 20 | } catch (e) { |
michael@0 | 21 | e.lineNumber = e.lineNumber - base + 1; |
michael@0 | 22 | return e; |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | const JSMSG_GENEXP_YIELD = error("(function(){((yield) for (x in []))})").message; |
michael@0 | 27 | const JSMSG_TOP_YIELD = error("yield").message; |
michael@0 | 28 | const JSMSG_YIELD_PAREN = error("(function(){yield, 1})").message; |
michael@0 | 29 | const JSMSG_YIELD_FOR = error("(function(){yield for})").message; |
michael@0 | 30 | const JSMSG_BAD_GENERATOR_SYNTAX = error("(1, x for (x in []))").message; |
michael@0 | 31 | |
michael@0 | 32 | const cases = [ |
michael@0 | 33 | // yield expressions |
michael@0 | 34 | { expr: "yield", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield" }, |
michael@0 | 35 | { expr: "yield 1", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg" }, |
michael@0 | 36 | { expr: "1, yield", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list" }, |
michael@0 | 37 | { expr: "1, yield 2", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list" }, |
michael@0 | 38 | { expr: "yield, 1", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list" }, |
michael@0 | 39 | { expr: "yield 1, 2", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list" }, |
michael@0 | 40 | { expr: "(yield)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized" }, |
michael@0 | 41 | { expr: "(yield 1)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg, parenthesized" }, |
michael@0 | 42 | { expr: "(1, yield)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list, parenthesized" }, |
michael@0 | 43 | { expr: "(1, yield 2)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list, parenthesized" }, |
michael@0 | 44 | { expr: "(yield, 1)", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list, parenthesized" }, |
michael@0 | 45 | { expr: "(yield 1, 2)", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list, parenthesized" }, |
michael@0 | 46 | |
michael@0 | 47 | // deeply nested yield expressions |
michael@0 | 48 | { expr: "((((yield))))", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield" }, |
michael@0 | 49 | { expr: "((((yield 1))))", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield w/ arg" }, |
michael@0 | 50 | |
michael@0 | 51 | // arguments |
michael@0 | 52 | { expr: "arguments", top: null, fun: null, gen: null, desc: "arguments in list" }, |
michael@0 | 53 | { expr: "1, arguments", top: null, fun: null, gen: null, desc: "arguments in list" }, |
michael@0 | 54 | |
michael@0 | 55 | // yield in generator expressions |
michael@0 | 56 | { expr: "(yield for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_FOR, gen: JSMSG_YIELD_FOR, desc: "simple yield in genexp" }, |
michael@0 | 57 | { expr: "(yield 1 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg in genexp" }, |
michael@0 | 58 | { expr: "(yield, 1 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list in genexp" }, |
michael@0 | 59 | { expr: "(yield 1, 2 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list in genexp" }, |
michael@0 | 60 | { expr: "(1, yield for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_FOR, gen: JSMSG_YIELD_FOR, desc: "simple yield at end of list in genexp" }, |
michael@0 | 61 | { expr: "(1, yield 2 for (x in []))", top: JSMSG_TOP_YIELD, fun: { simple: JSMSG_GENEXP_YIELD, call: JSMSG_GENEXP_YIELD }, |
michael@0 | 62 | gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list in genexp" }, |
michael@0 | 63 | { expr: "((yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized in genexp" }, |
michael@0 | 64 | { expr: "((yield 1) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg, parenthesized in genexp" }, |
michael@0 | 65 | { expr: "(1, (yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized in list in genexp" }, |
michael@0 | 66 | { expr: "(1, (yield 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg, parenthesized in list in genexp" }, |
michael@0 | 67 | { expr: "((1, yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list, parenthesized in genexp" }, |
michael@0 | 68 | { expr: "((1, yield 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list, parenthesized in genexp" }, |
michael@0 | 69 | { expr: "(1, (2, yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list, parenthesized in list in genexp" }, |
michael@0 | 70 | { expr: "(1, (2, yield 3) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list, parenthesized in list in genexp" }, |
michael@0 | 71 | { expr: "((yield, 1) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list, parenthesized in genexp" }, |
michael@0 | 72 | { expr: "((yield 1, 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list, parenthesized in genexp" }, |
michael@0 | 73 | { expr: "(1, (yield, 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list, parenthesized in list in genexp" }, |
michael@0 | 74 | { expr: "(1, (yield 2, 3) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list, parenthesized in list in genexp" }, |
michael@0 | 75 | |
michael@0 | 76 | // deeply nested yield in generator expressions |
michael@0 | 77 | { expr: "((((1, yield 2))) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield in genexp" }, |
michael@0 | 78 | { expr: "((((1, yield 2)) for (x in [])) for (y in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield in multiple genexps" }, |
michael@0 | 79 | |
michael@0 | 80 | // arguments in generator expressions |
michael@0 | 81 | { expr: "(arguments for (x in []))", top: null, fun: null, gen: null, desc: "simple arguments in genexp" }, |
michael@0 | 82 | { expr: "(1, arguments for (x in []))", top: JSMSG_BAD_GENERATOR_SYNTAX, fun: JSMSG_BAD_GENERATOR_SYNTAX, gen: JSMSG_BAD_GENERATOR_SYNTAX, desc: "arguments in list in genexp" }, |
michael@0 | 83 | { expr: "((arguments) for (x in []))", top: null, fun: null, gen: null, desc: "arguments, parenthesized in genexp" }, |
michael@0 | 84 | { expr: "(1, (arguments) for (x in []))", top: JSMSG_BAD_GENERATOR_SYNTAX, fun: JSMSG_BAD_GENERATOR_SYNTAX, gen: JSMSG_BAD_GENERATOR_SYNTAX, desc: "arguments, parenthesized in list in genexp" }, |
michael@0 | 85 | { expr: "((1, arguments) for (x in []))", top: null, fun: null, gen: null, desc: "arguments in list, parenthesized in genexp" }, |
michael@0 | 86 | { expr: "(1, (2, arguments) for (x in []))", top: JSMSG_BAD_GENERATOR_SYNTAX, fun: JSMSG_BAD_GENERATOR_SYNTAX, gen: JSMSG_BAD_GENERATOR_SYNTAX, desc: "arguments in list, parenthesized in list in genexp" }, |
michael@0 | 87 | |
michael@0 | 88 | // deeply nested arguments in generator expressions |
michael@0 | 89 | { expr: "((((1, arguments))) for (x in []))", top: null, fun: null, gen: null, desc: "deeply nested arguments in genexp" }, |
michael@0 | 90 | { expr: "((((1, arguments)) for (x in [])) for (y in []))", top: null, fun: null, gen: null, desc: "deeply nested arguments in multiple genexps" }, |
michael@0 | 91 | |
michael@0 | 92 | // legal yield/arguments in nested function |
michael@0 | 93 | { expr: "((function() { yield }) for (x in []))", top: null, fun: null, gen: null, desc: "legal yield in nested function" }, |
michael@0 | 94 | { expr: "((function() { arguments }) for (x in []))", top: null, fun: null, gen: null, desc: "legal arguments in nested function" }, |
michael@0 | 95 | { expr: "((function() arguments) for (x in []))", top: null, fun: null, gen: null, desc: "legal arguments in nested expression-closure" } |
michael@0 | 96 | ]; |
michael@0 | 97 | |
michael@0 | 98 | //----------------------------------------------------------------------------- |
michael@0 | 99 | test(); |
michael@0 | 100 | //----------------------------------------------------------------------------- |
michael@0 | 101 | |
michael@0 | 102 | function splitKeyword(str) { |
michael@0 | 103 | return str. |
michael@0 | 104 | replace(/yield for/, '\nyield for\n'). |
michael@0 | 105 | replace(/yield ([0-9])/, '\nyield $1\n'). |
michael@0 | 106 | replace(/yield([^ ]|$)/, '\nyield\n$1'). |
michael@0 | 107 | replace(/arguments/, '\narguments\n'); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function expectError1(err, ctx, msg) { |
michael@0 | 111 | reportCompare('object', typeof err, 'exn for: ' + msg); |
michael@0 | 112 | reportCompare(ctx, err.message, 'exn message for: ' + msg); |
michael@0 | 113 | if (ctx !== JSMSG_BAD_GENERATOR_SYNTAX) |
michael@0 | 114 | reportCompare(2, err.lineNumber, 'exn token for: ' + msg); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function expectError(expr, call, wrapCtx, expect, msg) { |
michael@0 | 118 | let exps = (typeof expect === "string") |
michael@0 | 119 | ? { simple: expect, call: expect } |
michael@0 | 120 | : expect; |
michael@0 | 121 | expectError1(error(wrapCtx(expr)), exps.simple, msg); |
michael@0 | 122 | if (call) |
michael@0 | 123 | expectError1(error(wrapCtx(call)), exps.call, 'call argument in ' + msg); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | function expectSuccess(err, msg) { |
michael@0 | 127 | reportCompare(null, err, 'parse: ' + msg); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function atTop(str) { return str } |
michael@0 | 131 | function inFun(str) { return '(function(){' + str + '})' } |
michael@0 | 132 | function inGen(str) { return '(y for (y in ' + str + '))' } |
michael@0 | 133 | |
michael@0 | 134 | function test() |
michael@0 | 135 | { |
michael@0 | 136 | enterFunc ('test'); |
michael@0 | 137 | printBugNumber(BUGNUMBER); |
michael@0 | 138 | printStatus (summary); |
michael@0 | 139 | |
michael@0 | 140 | for (let i = 0, len = cases.length; i < len; i++) { |
michael@0 | 141 | let {expr, top, fun, gen, desc} = cases[i]; |
michael@0 | 142 | |
michael@0 | 143 | let call = (expr[0] === "(") ? ("print" + expr) : null; |
michael@0 | 144 | |
michael@0 | 145 | expr = splitKeyword(expr); |
michael@0 | 146 | if (call) |
michael@0 | 147 | call = splitKeyword(call); |
michael@0 | 148 | |
michael@0 | 149 | if (top) |
michael@0 | 150 | expectError(expr, call, atTop, top, 'top-level context, ' + desc); |
michael@0 | 151 | else |
michael@0 | 152 | expectSuccess(error(expr), 'top-level context, ' + desc); |
michael@0 | 153 | |
michael@0 | 154 | if (fun) |
michael@0 | 155 | expectError(expr, call, inFun, fun, 'function context, ' + desc); |
michael@0 | 156 | else |
michael@0 | 157 | expectSuccess(error(inFun(expr)), 'function context, ' + desc); |
michael@0 | 158 | |
michael@0 | 159 | if (gen) |
michael@0 | 160 | expectError(expr, call, inGen, gen, 'genexp context, ' + desc); |
michael@0 | 161 | else |
michael@0 | 162 | expectSuccess(error(inGen(expr)), 'genexp context, ' + desc); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | exitFunc ('test'); |
michael@0 | 166 | } |