js/src/tests/ecma_6/Math/20.2.2.ToNumber.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 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  */
     6 /*
     7  *   ECMA-262 6th Edition / Draft November 8, 2013
     8  *
     9  *   20.2.2 Function Properties of the Math Object
    10  */
    12 /*
    13  * This custom object will allow us to check if valueOf() is called
    14  */
    16 TestNumber.prototype = new Number();
    18 function TestNumber(value) {
    19     this.value = value;
    20     this.valueOfCalled = false;
    21 }
    23 TestNumber.prototype = {
    24     valueOf: function() {
    25         this.valueOfCalled = true;
    26         return this.value;
    27     }
    28 }
    30 // Verify that each TestNumber's flag is set after calling Math func
    31 function test(func /*, args */) {
    32     var args = Array.prototype.slice.call(arguments, 1);
    33     func.apply(null, args);
    35     for (var i = 0; i < args.length; ++i)
    36         assertEq(args[i].valueOfCalled, true);
    37 }
    39 // Note that we are not testing these functions' return values
    40 // We only test whether valueOf() is called for each argument
    42 // 1. Test Math.atan2()
    43 var x = new TestNumber(1);
    44 test(Math.atan2, x);
    46 var x = new TestNumber(1);
    47 var y = new TestNumber(2);
    48 test(Math.atan2, y, x);
    50 // Remove comment block once patch for bug 896264 is approved
    51 /*
    52 // 2. Test Math.hypot()
    53 var x = new TestNumber(1);
    54 test(Math.hypot, x);
    56 var x = new TestNumber(1);
    57 var y = new TestNumber(2);
    58 test(Math.hypot, x, y);
    60 var x = new TestNumber(1);
    61 var y = new TestNumber(2);
    62 var z = new TestNumber(3);
    63 test(Math.hypot, x, y, z);
    64 */
    66 // Remove comment block once patch for bug 808148 is approved
    67 /*
    68 // 3. Test Math.imul()
    69 var x = new TestNumber(1);
    70 test(Math.imul, x);
    72 var x = new TestNumber(1);
    73 var y = new TestNumber(2);
    74 test(Math.imul, x, y);
    75 */
    77 // 4. Test Math.max()
    78 var x = new TestNumber(1);
    79 test(Math.max, x);
    81 var x = new TestNumber(1);
    82 var y = new TestNumber(2);
    83 test(Math.max, x, y);
    85 var x = new TestNumber(1);
    86 var y = new TestNumber(2);
    87 var z = new TestNumber(3);
    88 test(Math.max, x, y, z);
    90 // 5. Test Math.min()
    91 var x = new TestNumber(1);
    92 test(Math.min, x);
    94 var x = new TestNumber(1);
    95 var y = new TestNumber(2);
    96 test(Math.min, x, y);
    98 var x = new TestNumber(1);
    99 var y = new TestNumber(2);
   100 var z = new TestNumber(3);
   101 test(Math.min, x, y, z);
   103 // 6. Test Math.pow()
   104 var x = new TestNumber(1);
   105 test(Math.pow, x);
   107 var x = new TestNumber(1);
   108 var y = new TestNumber(2);
   109 test(Math.pow, x, y);
   111 reportCompare(0, 0, "ok");

mercurial