1 /* ***** BEGIN LICENSE BLOCK ***** 2 * Version: NPL 1.1/GPL 2.0/LGPL 2.1 3 * 4 * The contents of this file are subject to the Netscape Public License 5 * Version 1.1 (the "License"); you may not use this file except in 6 * compliance with the License. You may obtain a copy of the License at 7 * http://www.mozilla.org/NPL/ 8 * 9 * Software distributed under the License is distributed on an "AS IS" basis, 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 * for the specific language governing rights and limitations under the 12 * License. 13 * 14 * The Original Code is JavaScript Engine testing utilities. 15 * 16 * The Initial Developer of the Original Code is Netscape Communications Corp. 17 * Portions created by the Initial Developer are Copyright (C) 2002 18 * the Initial Developer. All Rights Reserved. 19 * 20 * Contributor(s): pschwartau (at) netscape.com 21 * 22 * Alternatively, the contents of this file may be used under the terms of 23 * either the GNU General Public License Version 2 or later (the "GPL"), or 24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 25 * in which case the provisions of the GPL or the LGPL are applicable instead 26 * of those above. If you wish to allow use of your version of this file only 27 * under the terms of either the GPL or the LGPL, and not to allow others to 28 * use your version of this file under the terms of the NPL, indicate your 29 * decision by deleting the provisions above and replace them with the notice 30 * and other provisions required by the GPL or the LGPL. If you do not delete 31 * the provisions above, a recipient may use your version of this file under 32 * the terms of any one of the NPL, the GPL or the LGPL. 33 * 34 * ***** END LICENSE BLOCK ***** 35 * 36 * 37 * Date: 20 Feb 2002 38 * SUMMARY: Testing the comparison |undefined === null| 39 * See http://bugzilla.mozilla.org/show_bug.cgi?id=126722 40 * 41 */ 42 //----------------------------------------------------------------------------- 43 var UBound = 0; 44 var bug = 126722; 45 var summary = 'Testing the comparison |undefined === null|'; 46 var status = ''; 47 var statusitems = []; 48 var actual = ''; 49 var actualvalues = []; 50 var expect= ''; 51 var expectedvalues = []; 52 53 54 status = inSection(1); 55 if (undefined === null) 56 actual = true; 57 else 58 actual = false; 59 expect = false; 60 addThis(); 61 62 63 64 status = inSection(2); 65 switch(true) 66 { 67 case (undefined === null) : 68 actual = true; 69 break; 70 71 default: 72 actual = false; 73 } 74 expect = false; 75 addThis(); 76 77 78 79 status = inSection(3); 80 function f3(x) 81 { 82 var res = false; 83 84 switch(true) 85 { 86 case (x === null) : 87 res = true; 88 break; 89 90 default: 91 // do nothing 92 } 93 94 return res; 95 } 96 97 actual = f3(undefined); 98 expect = false; 99 addThis(); 100 101 102 103 status = inSection(4); 104 function f4(arr) 105 { 106 var elt = ''; 107 var res = false; 108 109 for (i=0; i<arr.length; i++) 110 { 111 elt = arr[i]; 112 113 switch(true) 114 { 115 case (elt === null) : 116 res = true; 117 break; 118 119 default: 120 // do nothing 121 } 122 } 123 124 return res; 125 } 126 127 var arr = Array('a', undefined); 128 actual = f4(arr); 129 expect = false; 130 addThis(); 131 132 133 134 status = inSection(5); 135 function f5(arr) 136 { 137 var len = arr.length; 138 139 for(var i=0; (arr[i]===undefined) && (i<len); i++) 140 ; //do nothing 141 142 return i; 143 } 144 145 /* 146 * An array of 5 undefined elements. Note: 147 * 148 * The return value of eval(a STATEMENT) is undefined. 149 * A non-existent PROPERTY is undefined, not a ReferenceError. 150 * No undefined element exists AFTER trailing comma at end. 151 * 152 */ 153 var arrUndef = [ , undefined, eval('var x = 0'), this.NOT_A_PROPERTY, , ]; 154 actual = f5(arrUndef); 155 expect = 5; 156 addThis(); 157 158 159 160 status = inSection(6); 161 function f6(arr) 162 { 163 var len = arr.length; 164 165 for(var i=0; (arr[i]===null) && (i<len); i++) 166 ; //do nothing 167 168 return i; 169 } 170 171 /* 172 * Use same array as above. This time we're comparing to |null|, so we expect 0 173 */ 174 actual = f6(arrUndef); 175 expect = 0; 176 addThis(); 177 178 179 180 181 //----------------------------------------------------------------------------- 182 test(); 183 //----------------------------------------------------------------------------- 184 185 186 187 function addThis() 188 { 189 statusitems[UBound] = status; 190 actualvalues[UBound] = actual; 191 expectedvalues[UBound] = expect; 192 UBound++; 193 } 194 195 196 function test() 197 { 198 enterFunc('test'); 199 printBugNumber(bug); 200 printStatus(summary); 201 202 for (var i=0; i<UBound; i++) 203 { 204 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 205 } 206 207 exitFunc ('test'); 208 } 209