js/src/tests/ecma_6/Array/fill.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/ */
     5 //-----------------------------------------------------------------------------
     6 var BUGNUMBER = 911147;
     7 var summary = 'Array.prototype.fill';
     9 print(BUGNUMBER + ": " + summary);
    11 /**************
    12  * BEGIN TEST *
    13  **************/
    15 assertEq(typeof [].fill, 'function');
    16 assertEq([].fill.length, 1);
    18 // Default values for arguments and absolute values for negative start and end
    19 // arguments are resolved correctly.
    20 assertDeepEq([].fill(1), []);
    21 assertDeepEq([1,1,1].fill(2), [2,2,2]);
    22 assertDeepEq([1,1,1].fill(2, 1), [1,2,2]);
    23 assertDeepEq([1,1,1].fill(2, 1, 2), [1,2,1]);
    24 assertDeepEq([1,1,1].fill(2, -2), [1,2,2]);
    25 assertDeepEq([1,1,1].fill(2, -2, -1), [1,2,1]);
    26 assertDeepEq([1,1,1].fill(2, undefined), [2,2,2]);
    27 assertDeepEq([1,1,1].fill(2, undefined, undefined), [2,2,2]);
    28 assertDeepEq([1,1,1].fill(2, 1, undefined), [1,2,2]);
    29 assertDeepEq([1,1,1].fill(2, undefined, 1), [2,1,1]);
    30 assertDeepEq([1,1,1].fill(2, 2, 1), [1,1,1]);
    31 assertDeepEq([1,1,1].fill(2, -1, 1), [1,1,1]);
    32 assertDeepEq([1,1,1].fill(2, -2, 1), [1,1,1]);
    33 assertDeepEq([1,1,1].fill(2, 1, -2), [1,1,1]);
    34 assertDeepEq([1,1,1].fill(2, 0.1), [2,2,2]);
    35 assertDeepEq([1,1,1].fill(2, 0.9), [2,2,2]);
    36 assertDeepEq([1,1,1].fill(2, 1.1), [1,2,2]);
    37 assertDeepEq([1,1,1].fill(2, 0.1, 0.9), [1,1,1]);
    38 assertDeepEq([1,1,1].fill(2, 0.1, 1.9), [2,1,1]);
    39 assertDeepEq([1,1,1].fill(2, 0.1, 1.9), [2,1,1]);
    40 assertDeepEq([1,1,1].fill(2, -0), [2,2,2]);
    41 assertDeepEq([1,1,1].fill(2, 0, -0), [1,1,1]);
    42 assertDeepEq([1,1,1].fill(2, NaN), [2,2,2]);
    43 assertDeepEq([1,1,1].fill(2, 0, NaN), [1,1,1]);
    44 assertDeepEq([1,1,1].fill(2, false), [2,2,2]);
    45 assertDeepEq([1,1,1].fill(2, true), [1,2,2]);
    46 assertDeepEq([1,1,1].fill(2, "0"), [2,2,2]);
    47 assertDeepEq([1,1,1].fill(2, "1"), [1,2,2]);
    48 assertDeepEq([1,1,1].fill(2, "-2"), [1,2,2]);
    49 assertDeepEq([1,1,1].fill(2, "-2", "-1"), [1,2,1]);
    50 assertDeepEq([1,1,1].fill(2, {valueOf: ()=>1}), [1,2,2]);
    51 assertDeepEq([1,1,1].fill(2, 0, {valueOf: ()=>1}), [2,1,1]);
    53 // fill works generically for objects, too.
    54 assertDeepEq([].fill.call({length: 2}, 2), {0: 2, 1: 2, length: 2});
    56 var setterCalled = false;
    57 var objWithSetter = {set "0"(val) { setterCalled = true}, length: 1};
    58 [].fill.call(objWithSetter, 2);
    59 assertEq(setterCalled, true);
    61 var setHandlerCallCount = 0;
    62 var proxy = new Proxy({length: 3}, {set: function(value) {setHandlerCallCount++;}});
    63 [].fill.call(proxy, 2);
    64 assertEq(setHandlerCallCount, 3);
    66 var valueOfCallCount = 0;
    67 var typedArray = new Uint8ClampedArray(3);
    68 [].fill.call(typedArray, {valueOf: function() {valueOfCallCount++; return 2000;}});
    69 assertEq(valueOfCallCount, 3);
    70 assertEq(typedArray[0], 0xff);
    72 // All remaining cases should throw.
    73 var objWithGetterOnly = {get "0"() {return 1;}, length: 1};
    75 var objWithReadOnlyProp = {length: 1};
    76 Object.defineProperty(objWithReadOnlyProp, 0, {value: 1, writable: false});
    78 var objWithNonconfigurableProp = {length: 1};
    79 Object.defineProperty(objWithNonconfigurableProp, 0, {value: 1, configurable: false});
    81 var frozenObj = {length: 1};
    82 Object.freeze(frozenObj);
    84 var frozenArray = [1, 1, 1];
    85 Object.freeze(frozenArray);
    87 assertThrowsInstanceOf(() => [].fill.call(objWithGetterOnly, 2), TypeError);
    88 assertThrowsInstanceOf(() => [].fill.call(objWithReadOnlyProp, 2), TypeError);
    89 assertThrowsInstanceOf(() => [].fill.call(objWithNonconfigurableProp, 2), TypeError);
    90 assertThrowsInstanceOf(() => [].fill.call(frozenObj, 2), TypeError);
    91 assertThrowsInstanceOf(() => [].fill.call(frozenArray, 2), TypeError);
    92 assertThrowsInstanceOf(() => [].fill.call("111", 2), TypeError);
    93 assertThrowsInstanceOf(() => [].fill.call(null, 2), TypeError);
    94 assertThrowsInstanceOf(() => [].fill.call(undefined, 2), TypeError);
    96 if (typeof reportCompare === "function")
    97   reportCompare(true, true);

mercurial