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 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | var gTestfile = 'toLocaleString.js'; |
michael@0 | 7 | var BUGNUMBER = 653789; |
michael@0 | 8 | var summary = "Object.prototype.toLocaleString"; |
michael@0 | 9 | |
michael@0 | 10 | print(BUGNUMBER + ": " + summary); |
michael@0 | 11 | |
michael@0 | 12 | /************** |
michael@0 | 13 | * BEGIN TEST * |
michael@0 | 14 | **************/ |
michael@0 | 15 | |
michael@0 | 16 | function expectThrowTypeError(fun) |
michael@0 | 17 | { |
michael@0 | 18 | try |
michael@0 | 19 | { |
michael@0 | 20 | var r = fun(); |
michael@0 | 21 | throw "didn't throw TypeError, returned " + r; |
michael@0 | 22 | } |
michael@0 | 23 | catch (e) |
michael@0 | 24 | { |
michael@0 | 25 | assertEq(e instanceof TypeError, true, |
michael@0 | 26 | "didn't throw TypeError, got: " + e); |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | var toLocaleString = Object.prototype.toLocaleString; |
michael@0 | 31 | |
michael@0 | 32 | /* |
michael@0 | 33 | * 1. Let O be the result of calling ToObject passing the this value as the |
michael@0 | 34 | * argument. |
michael@0 | 35 | */ |
michael@0 | 36 | expectThrowTypeError(function() { toLocaleString.call(null); }); |
michael@0 | 37 | expectThrowTypeError(function() { toLocaleString.call(undefined); }); |
michael@0 | 38 | expectThrowTypeError(function() { toLocaleString.apply(null); }); |
michael@0 | 39 | expectThrowTypeError(function() { toLocaleString.apply(undefined); }); |
michael@0 | 40 | |
michael@0 | 41 | |
michael@0 | 42 | /* |
michael@0 | 43 | * 2. Let toString be the result of calling the [[Get]] internal method of O |
michael@0 | 44 | * passing "toString" as the argument. |
michael@0 | 45 | */ |
michael@0 | 46 | try |
michael@0 | 47 | { |
michael@0 | 48 | toLocaleString.call({ get toString() { throw 17; } }); |
michael@0 | 49 | throw new Error("didn't throw"); |
michael@0 | 50 | } |
michael@0 | 51 | catch (e) |
michael@0 | 52 | { |
michael@0 | 53 | assertEq(e, 17); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | /* 3. If IsCallable(toString) is false, throw a TypeError exception. */ |
michael@0 | 58 | expectThrowTypeError(function() { toLocaleString.call({ toString: 12 }); }); |
michael@0 | 59 | expectThrowTypeError(function() { toLocaleString.call({ toString: 0.3423423452352e9 }); }); |
michael@0 | 60 | expectThrowTypeError(function() { toLocaleString.call({ toString: undefined }); }); |
michael@0 | 61 | expectThrowTypeError(function() { toLocaleString.call({ toString: false }); }); |
michael@0 | 62 | expectThrowTypeError(function() { toLocaleString.call({ toString: [] }); }); |
michael@0 | 63 | expectThrowTypeError(function() { toLocaleString.call({ toString: {} }); }); |
michael@0 | 64 | expectThrowTypeError(function() { toLocaleString.call({ toString: new String }); }); |
michael@0 | 65 | expectThrowTypeError(function() { toLocaleString.call({ toString: new Number(7.7) }); }); |
michael@0 | 66 | expectThrowTypeError(function() { toLocaleString.call({ toString: new Boolean(true) }); }); |
michael@0 | 67 | expectThrowTypeError(function() { toLocaleString.call({ toString: JSON }); }); |
michael@0 | 68 | |
michael@0 | 69 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 12 }); }); |
michael@0 | 70 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 0.3423423452352e9 }); }); |
michael@0 | 71 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: undefined }); }); |
michael@0 | 72 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: false }); }); |
michael@0 | 73 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: [] }); }); |
michael@0 | 74 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: {} }); }); |
michael@0 | 75 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new String }); }); |
michael@0 | 76 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Number(7.7) }); }); |
michael@0 | 77 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Boolean(true) }); }); |
michael@0 | 78 | expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: JSON }); }); |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | /* |
michael@0 | 82 | * 4. Return the result of calling the [[Call]] internal method of toString |
michael@0 | 83 | * passing O as the this value and no arguments. |
michael@0 | 84 | */ |
michael@0 | 85 | assertEq(toLocaleString.call({ get toString() { return function() { return "foo"; } } }), |
michael@0 | 86 | "foo"); |
michael@0 | 87 | |
michael@0 | 88 | var obj = { toString: function() { assertEq(this, obj); assertEq(arguments.length, 0); return 5; } }; |
michael@0 | 89 | assertEq(toLocaleString.call(obj), 5); |
michael@0 | 90 | |
michael@0 | 91 | assertEq(toLocaleString.call({ toString: function() { return obj; } }), obj); |
michael@0 | 92 | |
michael@0 | 93 | assertEq(toLocaleString.call({ toString: function() { return obj; }, |
michael@0 | 94 | valueOf: function() { return "abc"; } }), |
michael@0 | 95 | obj); |
michael@0 | 96 | |
michael@0 | 97 | /******************************************************************************/ |
michael@0 | 98 | |
michael@0 | 99 | if (typeof reportCompare === "function") |
michael@0 | 100 | reportCompare(true, true); |
michael@0 | 101 | |
michael@0 | 102 | print("All tests passed!"); |