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 | // for-of works on strings and String objects. |
michael@0 | 2 | |
michael@0 | 3 | load(libdir + "string.js"); |
michael@0 | 4 | |
michael@0 | 5 | function test(s, expectedCodePoints) { |
michael@0 | 6 | var copy = ''; |
michael@0 | 7 | var codepoints = 0; |
michael@0 | 8 | var singleHighSurrogate = false; |
michael@0 | 9 | for (var v of s) { |
michael@0 | 10 | assertEq(typeof v, 'string'); |
michael@0 | 11 | assertEq(v.length, isSurrogatePair(v) ? 2 : 1); |
michael@0 | 12 | assertEq(false, singleHighSurrogate && isLowSurrogate(v)); |
michael@0 | 13 | copy += v; |
michael@0 | 14 | codepoints += 1; |
michael@0 | 15 | singleHighSurrogate = !isSurrogatePair(v) && isHighSurrogate(v); |
michael@0 | 16 | } |
michael@0 | 17 | assertEq(copy, String(s)); |
michael@0 | 18 | assertEq(codepoints, expectedCodePoints); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | test('', 0); |
michael@0 | 22 | test('abc', 3); |
michael@0 | 23 | test('a \0 \ufffe \ufeff', 7); |
michael@0 | 24 | |
michael@0 | 25 | // Non-BMP characters are generally passed to JS in UTF-16, as surrogate pairs. |
michael@0 | 26 | // ES6 requires that such pairs be treated as a single code point in for-of. |
michael@0 | 27 | test('\ud808\udf45', 1); |
michael@0 | 28 | |
michael@0 | 29 | // Also test invalid surrogate pairs: |
michael@0 | 30 | // (1) High surrogate not followed by low surrogate |
michael@0 | 31 | test('\ud808', 1); |
michael@0 | 32 | test('\ud808\u0000', 2); |
michael@0 | 33 | // (2) Low surrogate not preceded by high surrogate |
michael@0 | 34 | test('\udf45', 1); |
michael@0 | 35 | test('\u0000\udf45', 2); |
michael@0 | 36 | // (3) Low surrogate followed by high surrogate |
michael@0 | 37 | test('\udf45\ud808', 2); |
michael@0 | 38 | |
michael@0 | 39 | test(new String(''), 0); |
michael@0 | 40 | test(new String('abc'), 3); |
michael@0 | 41 | test(new String('a \0 \ufffe \ufeff'), 7); |
michael@0 | 42 | test(new String('\ud808\udf45'), 1); |
michael@0 | 43 | test(new String('\ud808'), 1); |
michael@0 | 44 | test(new String('\ud808\u0000'), 2); |
michael@0 | 45 | test(new String('\udf45'), 1); |
michael@0 | 46 | test(new String('\u0000\udf45'), 2); |
michael@0 | 47 | test(new String('\udf45\ud808'), 2); |