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 | // |reftest| skip-if(xulRuntime.XPCOMABI.match(/x86_64/)||Android) -- No test results |
michael@0 | 2 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * |
michael@0 | 9 | * Date: 16 July 2002 |
michael@0 | 10 | * SUMMARY: Testing that Array.sort() doesn't crash on very large arrays |
michael@0 | 11 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=157652 |
michael@0 | 12 | * |
michael@0 | 13 | * How large can a JavaScript array be? |
michael@0 | 14 | * ECMA-262 Ed.3 Final, Section 15.4.2.2 : new Array(len) |
michael@0 | 15 | * |
michael@0 | 16 | * This states that |len| must be a a uint32_t (unsigned 32-bit integer). |
michael@0 | 17 | * Note the UBound for uint32's is 2^32 -1 = 0xFFFFFFFF = 4,294,967,295. |
michael@0 | 18 | * |
michael@0 | 19 | * Check: |
michael@0 | 20 | * js> var arr = new Array(0xFFFFFFFF) |
michael@0 | 21 | * js> arr.length |
michael@0 | 22 | * 4294967295 |
michael@0 | 23 | * |
michael@0 | 24 | * js> var arr = new Array(0x100000000) |
michael@0 | 25 | * RangeError: invalid array length |
michael@0 | 26 | * |
michael@0 | 27 | * |
michael@0 | 28 | * We'll try the largest possible array first, then a couple others. |
michael@0 | 29 | * We're just testing that we don't crash on Array.sort(). |
michael@0 | 30 | * |
michael@0 | 31 | * Try to be good about memory by nulling each array variable after it is |
michael@0 | 32 | * used. This will tell the garbage collector the memory is no longer needed. |
michael@0 | 33 | * |
michael@0 | 34 | * As of 2002-08-13, the JS shell runs out of memory no matter what we do, |
michael@0 | 35 | * when trying to sort such large arrays. |
michael@0 | 36 | * |
michael@0 | 37 | * We only want to test that we don't CRASH on the sort. So it will be OK |
michael@0 | 38 | * if we get the JS "out of memory" error. Note this terminates the test |
michael@0 | 39 | * with exit code 3. Therefore we put |
michael@0 | 40 | * |
michael@0 | 41 | * |expectExitCode(3);| |
michael@0 | 42 | * |
michael@0 | 43 | * The only problem will arise if the JS shell ever DOES have enough memory |
michael@0 | 44 | * to do the sort. Then this test will terminate with the normal exit code 0 |
michael@0 | 45 | * and fail. |
michael@0 | 46 | * |
michael@0 | 47 | * Right now, I can't see any other way to do this, because "out of memory" |
michael@0 | 48 | * is not a catchable error: it cannot be trapped with try...catch. |
michael@0 | 49 | * |
michael@0 | 50 | * |
michael@0 | 51 | * FURTHER HEADACHE: Rhino can't seem to handle the largest array: it hangs. |
michael@0 | 52 | * So we skip this case in Rhino. Here is correspondence with Igor Bukanov. |
michael@0 | 53 | * He explains that Rhino isn't actually hanging; it's doing the huge sort: |
michael@0 | 54 | * |
michael@0 | 55 | * Philip Schwartau wrote: |
michael@0 | 56 | * |
michael@0 | 57 | * > Hi, |
michael@0 | 58 | * > |
michael@0 | 59 | * > I'm getting a graceful OOM message on trying to sort certain large |
michael@0 | 60 | * > arrays. But if the array is too big, Rhino simply hangs. Note that ECMA |
michael@0 | 61 | * > allows array lengths to be anything less than Math.pow(2,32), so the |
michael@0 | 62 | * > arrays I'm sorting are legal. |
michael@0 | 63 | * > |
michael@0 | 64 | * > Note below, I'm getting an instantaneous OOM error on arr.sort() for LEN |
michael@0 | 65 | * > = Math.pow(2, 30). So shouldn't I also get one for every LEN between |
michael@0 | 66 | * > that and Math.pow(2, 32)? For some reason, I start to hang with 100% CPU |
michael@0 | 67 | * > as LEN hits, say, Math.pow(2, 31) and higher. SpiderMonkey gives OOM |
michael@0 | 68 | * > messages for all of these. Should I file a bug on this? |
michael@0 | 69 | * |
michael@0 | 70 | * Igor Bukanov wrote: |
michael@0 | 71 | * |
michael@0 | 72 | * This is due to different sorting algorithm Rhino uses when sorting |
michael@0 | 73 | * arrays with length > Integer.MAX_VALUE. If length can fit Java int, |
michael@0 | 74 | * Rhino first copies internal spare array to a temporary buffer, and then |
michael@0 | 75 | * sorts it, otherwise it sorts array directly. In case of very spare |
michael@0 | 76 | * arrays, that Array(big_number) generates, it is rather inefficient and |
michael@0 | 77 | * generates OutOfMemory if length fits int. It may be worth in your case |
michael@0 | 78 | * to optimize sorting to take into account array spareness, but then it |
michael@0 | 79 | * would be a good idea to file a bug about ineficient sorting of spare |
michael@0 | 80 | * arrays both in case of Rhino and SpiderMonkey as SM always uses a |
michael@0 | 81 | * temporary buffer. |
michael@0 | 82 | * |
michael@0 | 83 | */ |
michael@0 | 84 | //----------------------------------------------------------------------------- |
michael@0 | 85 | var BUGNUMBER = 157652; |
michael@0 | 86 | var summary = "Testing that Array.sort() doesn't crash on very large arrays"; |
michael@0 | 87 | var expect = 'No Crash'; |
michael@0 | 88 | var actual = 'No Crash'; |
michael@0 | 89 | |
michael@0 | 90 | printBugNumber(BUGNUMBER); |
michael@0 | 91 | printStatus(summary); |
michael@0 | 92 | |
michael@0 | 93 | expectExitCode(0); |
michael@0 | 94 | expectExitCode(5); |
michael@0 | 95 | |
michael@0 | 96 | var IN_RHINO = inRhino(); |
michael@0 | 97 | |
michael@0 | 98 | try |
michael@0 | 99 | { |
michael@0 | 100 | if (!IN_RHINO) |
michael@0 | 101 | { |
michael@0 | 102 | var a1=Array(0xFFFFFFFF); |
michael@0 | 103 | a1.sort(); |
michael@0 | 104 | a1 = null; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | var a2 = Array(0x40000000); |
michael@0 | 108 | a2.sort(); |
michael@0 | 109 | a2=null; |
michael@0 | 110 | |
michael@0 | 111 | var a3=Array(0x10000000/4); |
michael@0 | 112 | a3.sort(); |
michael@0 | 113 | a3=null; |
michael@0 | 114 | } |
michael@0 | 115 | catch(ex) |
michael@0 | 116 | { |
michael@0 | 117 | // handle changed 1.9 branch behavior. see bug 422348 |
michael@0 | 118 | expect = 'InternalError: allocation size overflow'; |
michael@0 | 119 | actual = ex + ''; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | reportCompare(expect, actual, summary); |