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: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* |
michael@0 | 3 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 4 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 5 | */ |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | // The Worker constructor can take a relative URL, but different test runners |
michael@0 | 9 | // run in different enough environments that it doesn't all just automatically |
michael@0 | 10 | // work. For the shell, we use just a filename; for the browser, see browser.js. |
michael@0 | 11 | var workerDir = ''; |
michael@0 | 12 | |
michael@0 | 13 | // explicitly turn on js185 |
michael@0 | 14 | // XXX: The browser currently only supports up to version 1.8 |
michael@0 | 15 | if (typeof version != 'undefined') |
michael@0 | 16 | { |
michael@0 | 17 | version(185); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | // A little pattern-matching library. |
michael@0 | 21 | var Match = |
michael@0 | 22 | |
michael@0 | 23 | (function() { |
michael@0 | 24 | |
michael@0 | 25 | function Pattern(template) { |
michael@0 | 26 | // act like a constructor even as a function |
michael@0 | 27 | if (!(this instanceof Pattern)) |
michael@0 | 28 | return new Pattern(template); |
michael@0 | 29 | |
michael@0 | 30 | this.template = template; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | Pattern.prototype = { |
michael@0 | 34 | match: function(act) { |
michael@0 | 35 | return match(act, this.template); |
michael@0 | 36 | }, |
michael@0 | 37 | |
michael@0 | 38 | matches: function(act) { |
michael@0 | 39 | try { |
michael@0 | 40 | return this.match(act); |
michael@0 | 41 | } |
michael@0 | 42 | catch (e if e instanceof MatchError) { |
michael@0 | 43 | return false; |
michael@0 | 44 | } |
michael@0 | 45 | }, |
michael@0 | 46 | |
michael@0 | 47 | assert: function(act, message) { |
michael@0 | 48 | try { |
michael@0 | 49 | return this.match(act); |
michael@0 | 50 | } |
michael@0 | 51 | catch (e if e instanceof MatchError) { |
michael@0 | 52 | throw new Error((message || "failed match") + ": " + e.message); |
michael@0 | 53 | } |
michael@0 | 54 | }, |
michael@0 | 55 | |
michael@0 | 56 | toString: function() "[object Pattern]" |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | Pattern.ANY = new Pattern; |
michael@0 | 60 | Pattern.ANY.template = Pattern.ANY; |
michael@0 | 61 | |
michael@0 | 62 | var quote = uneval; |
michael@0 | 63 | |
michael@0 | 64 | function MatchError(msg) { |
michael@0 | 65 | this.message = msg; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | MatchError.prototype = { |
michael@0 | 69 | toString: function() { |
michael@0 | 70 | return "match error: " + this.message; |
michael@0 | 71 | } |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | function isAtom(x) { |
michael@0 | 75 | return (typeof x === "number") || |
michael@0 | 76 | (typeof x === "string") || |
michael@0 | 77 | (typeof x === "boolean") || |
michael@0 | 78 | (x === null) || |
michael@0 | 79 | (typeof x === "object" && x instanceof RegExp); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function isObject(x) { |
michael@0 | 83 | return (x !== null) && (typeof x === "object"); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function isArrayLike(x) { |
michael@0 | 87 | return isObject(x) && ("length" in x); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function matchAtom(act, exp) { |
michael@0 | 91 | if ((typeof exp) === "number" && isNaN(exp)) { |
michael@0 | 92 | if ((typeof act) !== "number" || !isNaN(act)) |
michael@0 | 93 | throw new MatchError("expected NaN, got: " + quote(act)); |
michael@0 | 94 | return true; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | if (exp === null) { |
michael@0 | 98 | if (act !== null) |
michael@0 | 99 | throw new MatchError("expected null, got: " + quote(act)); |
michael@0 | 100 | return true; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | if (exp instanceof RegExp) { |
michael@0 | 104 | if (!(act instanceof RegExp) || exp.source !== act.source) |
michael@0 | 105 | throw new MatchError("expected " + quote(exp) + ", got: " + quote(act)); |
michael@0 | 106 | return true; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | switch (typeof exp) { |
michael@0 | 110 | case "string": |
michael@0 | 111 | if (act !== exp) |
michael@0 | 112 | throw new MatchError("expected " + exp.quote() + ", got " + quote(act)); |
michael@0 | 113 | return true; |
michael@0 | 114 | case "boolean": |
michael@0 | 115 | case "number": |
michael@0 | 116 | if (exp !== act) |
michael@0 | 117 | throw new MatchError("expected " + exp + ", got " + quote(act)); |
michael@0 | 118 | return true; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | throw new Error("bad pattern: " + exp.toSource()); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function matchObject(act, exp) { |
michael@0 | 125 | if (!isObject(act)) |
michael@0 | 126 | throw new MatchError("expected object, got " + quote(act)); |
michael@0 | 127 | |
michael@0 | 128 | for (var key in exp) { |
michael@0 | 129 | if (!(key in act)) |
michael@0 | 130 | throw new MatchError("expected property " + key.quote() + " not found in " + quote(act)); |
michael@0 | 131 | match(act[key], exp[key]); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | return true; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | function matchArray(act, exp) { |
michael@0 | 138 | if (!isObject(act) || !("length" in act)) |
michael@0 | 139 | throw new MatchError("expected array-like object, got " + quote(act)); |
michael@0 | 140 | |
michael@0 | 141 | var length = exp.length; |
michael@0 | 142 | if (act.length !== exp.length) |
michael@0 | 143 | throw new MatchError("expected array-like object of length " + length + ", got " + quote(act)); |
michael@0 | 144 | |
michael@0 | 145 | for (var i = 0; i < length; i++) { |
michael@0 | 146 | if (i in exp) { |
michael@0 | 147 | if (!(i in act)) |
michael@0 | 148 | throw new MatchError("expected array property " + i + " not found in " + quote(act)); |
michael@0 | 149 | match(act[i], exp[i]); |
michael@0 | 150 | } |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | return true; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | function match(act, exp) { |
michael@0 | 157 | if (exp === Pattern.ANY) |
michael@0 | 158 | return true; |
michael@0 | 159 | |
michael@0 | 160 | if (exp instanceof Pattern) |
michael@0 | 161 | return exp.match(act); |
michael@0 | 162 | |
michael@0 | 163 | if (isAtom(exp)) |
michael@0 | 164 | return matchAtom(act, exp); |
michael@0 | 165 | |
michael@0 | 166 | if (isArrayLike(exp)) |
michael@0 | 167 | return matchArray(act, exp); |
michael@0 | 168 | |
michael@0 | 169 | return matchObject(act, exp); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | return { Pattern: Pattern, |
michael@0 | 173 | MatchError: MatchError }; |
michael@0 | 174 | |
michael@0 | 175 | })(); |
michael@0 | 176 | |
michael@0 | 177 | function referencesVia(from, edge, to) { |
michael@0 | 178 | edge = "edge: " + edge; |
michael@0 | 179 | var edges = findReferences(to); |
michael@0 | 180 | if (edge in edges && edges[edge].indexOf(from) != -1) |
michael@0 | 181 | return true; |
michael@0 | 182 | |
michael@0 | 183 | // Be nice: make it easy to fix if the edge name has just changed. |
michael@0 | 184 | var alternatives = []; |
michael@0 | 185 | for (var e in edges) { |
michael@0 | 186 | if (edges[e].indexOf(from) != -1) |
michael@0 | 187 | alternatives.push(e); |
michael@0 | 188 | } |
michael@0 | 189 | if (alternatives.length == 0) { |
michael@0 | 190 | print("referent not referred to by referrer after all"); |
michael@0 | 191 | } else { |
michael@0 | 192 | print("referent is not referenced via: " + uneval(edge)); |
michael@0 | 193 | print("but it is referenced via: " + uneval(alternatives)); |
michael@0 | 194 | } |
michael@0 | 195 | print("all incoming edges, from any object:"); |
michael@0 | 196 | for (var e in edges) |
michael@0 | 197 | print(e); |
michael@0 | 198 | return false; |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | // Note that AsmJS ArrayBuffers have a minimum size, currently 4096 bytes. If a |
michael@0 | 202 | // smaller size is given, a regular ArrayBuffer will be returned instead. |
michael@0 | 203 | function AsmJSArrayBuffer(size) { |
michael@0 | 204 | var ab = new ArrayBuffer(size); |
michael@0 | 205 | (new Function('global', 'foreign', 'buffer', '' + |
michael@0 | 206 | ' "use asm";' + |
michael@0 | 207 | ' var i32 = new global.Int32Array(buffer);' + |
michael@0 | 208 | ' function g() {};' + |
michael@0 | 209 | ' return g;' + |
michael@0 | 210 | ''))(Function("return this")(),null,ab); |
michael@0 | 211 | return ab; |
michael@0 | 212 | } |