js/src/tests/ecma_3/Expressions/11.9.6-1.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  *
     8  * Date:    20 Feb 2002
     9  * SUMMARY: Testing the comparison |undefined === null|
    10  * See http://bugzilla.mozilla.org/show_bug.cgi?id=126722
    11  *
    12  */
    13 //-----------------------------------------------------------------------------
    14 var UBound = 0;
    15 var BUGNUMBER = 126722;
    16 var summary = 'Testing the comparison |undefined === null|';
    17 var status = '';
    18 var statusitems = [];
    19 var actual = '';
    20 var actualvalues = [];
    21 var expect= '';
    22 var expectedvalues = [];
    25 status = inSection(1);
    26 if (undefined === null)
    27   actual = true;
    28 else
    29   actual = false;
    30 expect = false;
    31 addThis();
    35 status = inSection(2);
    36 switch(true)
    37 {
    38 case (undefined === null) :
    39   actual = true;
    40   break;
    42 default:
    43   actual = false;
    44 }
    45 expect = false;
    46 addThis();
    50 status = inSection(3);
    51 function f3(x)
    52 {
    53   var res = false;
    55   switch(true)
    56   {
    57   case (x === null) :
    58     res = true;
    59     break;
    61   default:
    62     // do nothing
    63   }
    65   return res;
    66 }
    68 actual = f3(undefined);
    69 expect = false;
    70 addThis();
    74 status = inSection(4);
    75 function f4(arr)
    76 {
    77   var elt = '';
    78   var res = false;
    80   for (i=0; i<arr.length; i++)
    81   {
    82     elt = arr[i];
    84     switch(true)
    85     {
    86     case (elt === null) :
    87       res = true;
    88       break;
    90     default:
    91       // do nothing
    92     }
    93   }
    95   return res;
    96 }
    98 var arr = Array('a', undefined);
    99 actual = f4(arr);
   100 expect = false;
   101 addThis();
   105 status = inSection(5);
   106 function f5(arr)
   107 {
   108   var len = arr.length;
   110   for(var i=0; (arr[i]===undefined) && (i<len); i++)
   111     ; //do nothing
   113   return i;
   114 }
   116 /*
   117  * An array of 5 undefined elements. Note:
   118  *
   119  * The return value of eval(a STATEMENT) is undefined.
   120  * A non-existent PROPERTY is undefined, not a ReferenceError.
   121  * No undefined element exists AFTER trailing comma at end.
   122  *
   123  */
   124 var arrUndef = [ , undefined, eval('var x = 0'), this.NOT_A_PROPERTY, , ];
   125 actual = f5(arrUndef);
   126 expect = 5;
   127 addThis();
   131 status = inSection(6);
   132 function f6(arr)
   133 {
   134   var len = arr.length;
   136   for(var i=0; (arr[i]===null) && (i<len); i++)
   137     ; //do nothing
   139   return i;
   140 }
   142 /*
   143  * Use same array as above. This time we're comparing to |null|, so we expect 0
   144  */
   145 actual = f6(arrUndef);
   146 expect = 0;
   147 addThis();
   152 //-----------------------------------------------------------------------------
   153 test();
   154 //-----------------------------------------------------------------------------
   158 function addThis()
   159 {
   160   statusitems[UBound] = status;
   161   actualvalues[UBound] = actual;
   162   expectedvalues[UBound] = expect;
   163   UBound++;
   164 }
   167 function test()
   168 {
   169   enterFunc('test');
   170   printBugNumber(BUGNUMBER);
   171   printStatus(summary);
   173   for (var i=0; i<UBound; i++)
   174   {
   175     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   176   }
   178   exitFunc ('test');
   179 }

mercurial