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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const ASM_OK_STRING = "successfully compiled asm.js code";
6 const ASM_TYPE_FAIL_STRING = "asm.js type error:";
7 const ASM_DIRECTIVE_FAIL_STRING = "\"use asm\" is only meaningful in the Directive Prologue of a function body";
9 const USE_ASM = '"use asm";';
10 const HEAP_IMPORTS = "const i8=new glob.Int8Array(b);var u8=new glob.Uint8Array(b);"+
11 "const i16=new glob.Int16Array(b);var u16=new glob.Uint16Array(b);"+
12 "const i32=new glob.Int32Array(b);var u32=new glob.Uint32Array(b);"+
13 "const f32=new glob.Float32Array(b);var f64=new glob.Float64Array(b);";
14 const BUF_64KB = new ArrayBuffer(64 * 1024);
16 function asmCompile()
17 {
18 var f = Function.apply(null, arguments);
19 assertEq(!isAsmJSCompilationAvailable() || isAsmJSModule(f), true);
20 return f;
21 }
23 function asmCompileCached()
24 {
25 if (!isAsmJSCompilationAvailable())
26 return Function.apply(null, arguments);
28 if (!isCachingEnabled()) {
29 var f = Function.apply(null, arguments);
30 assertEq(isAsmJSModule(f), true);
31 return f;
32 }
34 var quotedArgs = [];
35 for (var i = 0; i < arguments.length; i++)
36 quotedArgs.push("'" + arguments[i] + "'");
37 var code = "setCachingEnabled(true); var f = new Function(" + quotedArgs.join(',') + ");assertEq(isAsmJSModule(f), true);";
38 nestedShell("--js-cache", "--execute=" + code);
40 var f = Function.apply(null, arguments);
41 assertEq(isAsmJSModuleLoadedFromCache(f), true);
42 return f;
43 }
45 function assertAsmDirectiveFail(str)
46 {
47 if (!isAsmJSCompilationAvailable())
48 return;
50 // Turn on warnings-as-errors
51 var oldOpts = options("werror");
52 assertEq(oldOpts.indexOf("werror"), -1);
54 // Verify an error is thrown
55 var caught = false;
56 try {
57 eval(str);
58 } catch (e) {
59 if ((''+e).indexOf(ASM_DIRECTIVE_FAIL_STRING) == -1)
60 throw new Error("Didn't catch the expected directive failure error; instead caught: " + e + "\nStack: " + new Error().stack);
61 caught = true;
62 }
63 if (!caught)
64 throw new Error("Didn't catch the directive failure error");
66 // Turn warnings-as-errors back off
67 options("werror");
68 }
70 function assertAsmTypeFail()
71 {
72 if (!isAsmJSCompilationAvailable())
73 return;
75 // Verify no error is thrown with warnings off
76 Function.apply(null, arguments);
78 // Turn on warnings-as-errors
79 var oldOpts = options("werror");
80 assertEq(oldOpts.indexOf("werror"), -1);
82 // Verify an error is thrown
83 var caught = false;
84 try {
85 Function.apply(null, arguments);
86 } catch (e) {
87 if ((''+e).indexOf(ASM_TYPE_FAIL_STRING) == -1)
88 throw new Error("Didn't catch the expected type failure error; instead caught: " + e + "\nStack: " + new Error().stack);
89 caught = true;
90 }
91 if (!caught)
92 throw new Error("Didn't catch the type failure error");
94 // Turn warnings-as-errors back off
95 options("werror");
96 }
98 function assertAsmLinkFail(f)
99 {
100 if (!isAsmJSCompilationAvailable())
101 return;
103 assertEq(isAsmJSModule(f), true);
105 // Verify no error is thrown with warnings off
106 var ret = f.apply(null, Array.slice(arguments, 1));
108 assertEq(isAsmJSFunction(ret), false);
109 if (typeof ret === 'object')
110 for (f of ret)
111 assertEq(isAsmJSFunction(f), false);
113 // Turn on warnings-as-errors
114 var oldOpts = options("werror");
115 assertEq(oldOpts.indexOf("werror"), -1);
117 // Verify an error is thrown
118 var caught = false;
119 try {
120 f.apply(null, Array.slice(arguments, 1));
121 } catch (e) {
122 // Arbitrary code an run in the GetProperty, so don't assert any
123 // particular string
124 caught = true;
125 }
126 if (!caught)
127 throw new Error("Didn't catch the link failure error");
129 // Turn warnings-as-errors back off
130 options("werror");
131 }
133 // Linking should throw an exception even without warnings-as-errors
134 function assertAsmLinkAlwaysFail(f)
135 {
136 var caught = false;
137 try {
138 f.apply(null, Array.slice(arguments, 1));
139 } catch (e) {
140 caught = true;
141 }
142 if (!caught)
143 throw new Error("Didn't catch the link failure error");
145 // Turn on warnings-as-errors
146 var oldOpts = options("werror");
147 assertEq(oldOpts.indexOf("werror"), -1);
149 // Verify an error is thrown
150 var caught = false;
151 try {
152 f.apply(null, Array.slice(arguments, 1));
153 } catch (e) {
154 caught = true;
155 }
156 if (!caught)
157 throw new Error("Didn't catch the link failure error");
159 // Turn warnings-as-errors back off
160 options("werror");
161 }
163 // Linking should throw a warning-as-error but otherwise run fine
164 function asmLink(f)
165 {
166 if (!isAsmJSCompilationAvailable())
167 return f.apply(null, Array.slice(arguments, 1));
169 // Turn on warnings-as-errors
170 var oldOpts = options("werror");
171 assertEq(oldOpts.indexOf("werror"), -1);
173 var ret = f.apply(null, Array.slice(arguments, 1));
175 // Turn warnings-as-errors back off
176 options("werror");
178 return ret;
179 }