| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 Array.prototype.some, | 143 Array.prototype.some, |
| 144 Array.prototype.forEach, | 144 Array.prototype.forEach, |
| 145 Array.prototype.map, | 145 Array.prototype.map, |
| 146 Array.prototype.filter]; | 146 Array.prototype.filter]; |
| 147 | 147 |
| 148 // Reduce functions. | 148 // Reduce functions. |
| 149 var reducing_functions = | 149 var reducing_functions = |
| 150 [Array.prototype.reduce, | 150 [Array.prototype.reduce, |
| 151 Array.prototype.reduceRight]; | 151 Array.prototype.reduceRight]; |
| 152 | 152 |
| 153 function checkExpectedMessage(e) { |
| 154 assertTrue(e.message.indexOf("called on null or undefined") >= 0 || |
| 155 e.message.indexOf("Cannot convert null to object") >= 0); |
| 156 } |
| 157 |
| 153 // Test that all natives using the ToObject call throw the right exception. | 158 // Test that all natives using the ToObject call throw the right exception. |
| 154 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { | 159 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { |
| 155 // Sanity check that all functions are correct | 160 // Sanity check that all functions are correct |
| 156 assertEquals(typeof(should_throw_on_null_and_undefined[i]), "function"); | 161 assertEquals(typeof(should_throw_on_null_and_undefined[i]), "function"); |
| 157 | 162 |
| 158 var exception = false; | 163 var exception = false; |
| 159 try { | 164 try { |
| 160 // We call all functions with no parameters, which means that essential | 165 // We call all functions with no parameters, which means that essential |
| 161 // parameters will have the undefined value. | 166 // parameters will have the undefined value. |
| 162 // The test for whether the "this" value is null or undefined is always | 167 // The test for whether the "this" value is null or undefined is always |
| 163 // performed before access to the other parameters, so even if the | 168 // performed before access to the other parameters, so even if the |
| 164 // undefined value is an invalid argument value, it mustn't change | 169 // undefined value is an invalid argument value, it mustn't change |
| 165 // the result of the test. | 170 // the result of the test. |
| 166 should_throw_on_null_and_undefined[i].call(null); | 171 should_throw_on_null_and_undefined[i].call(null); |
| 167 } catch (e) { | 172 } catch (e) { |
| 168 exception = true; | 173 exception = true; |
| 169 assertTrue("called_on_null_or_undefined" == e.type || | 174 checkExpectedMessage(e); |
| 170 "null_to_object" == e.type); | |
| 171 } | 175 } |
| 172 assertTrue(exception); | 176 assertTrue(exception); |
| 173 | 177 |
| 174 exception = false; | 178 exception = false; |
| 175 try { | 179 try { |
| 176 should_throw_on_null_and_undefined[i].call(undefined); | 180 should_throw_on_null_and_undefined[i].call(undefined); |
| 177 } catch (e) { | 181 } catch (e) { |
| 178 exception = true; | 182 exception = true; |
| 179 assertTrue("called_on_null_or_undefined" == e.type || | 183 checkExpectedMessage(e); |
| 180 "null_to_object" == e.type); | |
| 181 } | 184 } |
| 182 assertTrue(exception); | 185 assertTrue(exception); |
| 183 | 186 |
| 184 exception = false; | 187 exception = false; |
| 185 try { | 188 try { |
| 186 should_throw_on_null_and_undefined[i].apply(null); | 189 should_throw_on_null_and_undefined[i].apply(null); |
| 187 } catch (e) { | 190 } catch (e) { |
| 188 exception = true; | 191 exception = true; |
| 189 assertTrue("called_on_null_or_undefined" == e.type || | 192 checkExpectedMessage(e); |
| 190 "null_to_object" == e.type); | |
| 191 } | 193 } |
| 192 assertTrue(exception); | 194 assertTrue(exception); |
| 193 | 195 |
| 194 exception = false; | 196 exception = false; |
| 195 try { | 197 try { |
| 196 should_throw_on_null_and_undefined[i].apply(undefined); | 198 should_throw_on_null_and_undefined[i].apply(undefined); |
| 197 } catch (e) { | 199 } catch (e) { |
| 198 exception = true; | 200 exception = true; |
| 199 assertTrue("called_on_null_or_undefined" == e.type || | 201 checkExpectedMessage(e); |
| 200 "null_to_object" == e.type); | |
| 201 } | 202 } |
| 202 assertTrue(exception); | 203 assertTrue(exception); |
| 203 } | 204 } |
| 204 | 205 |
| 205 // Test that all natives that are non generic throw on null and undefined. | 206 // Test that all natives that are non generic throw on null and undefined. |
| 206 for (var i = 0; i < non_generic.length; i++) { | 207 for (var i = 0; i < non_generic.length; i++) { |
| 207 // Sanity check that all functions are correct | 208 // Sanity check that all functions are correct |
| 208 assertEquals(typeof(non_generic[i]), "function"); | 209 assertEquals(typeof(non_generic[i]), "function"); |
| 209 | 210 |
| 210 exception = false; | 211 exception = false; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 var array = [1,2,3,4,5]; | 251 var array = [1,2,3,4,5]; |
| 251 for (var j = 0; j < mapping_functions.length; j++) { | 252 for (var j = 0; j < mapping_functions.length; j++) { |
| 252 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { | 253 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { |
| 253 exception = false; | 254 exception = false; |
| 254 try { | 255 try { |
| 255 mapping_functions[j].call(array, | 256 mapping_functions[j].call(array, |
| 256 should_throw_on_null_and_undefined[i], | 257 should_throw_on_null_and_undefined[i], |
| 257 null); | 258 null); |
| 258 } catch (e) { | 259 } catch (e) { |
| 259 exception = true; | 260 exception = true; |
| 260 assertTrue("called_on_null_or_undefined" == e.type || | 261 checkExpectedMessage(e); |
| 261 "null_to_object" == e.type); | |
| 262 } | 262 } |
| 263 assertTrue(exception); | 263 assertTrue(exception); |
| 264 | 264 |
| 265 exception = false; | 265 exception = false; |
| 266 try { | 266 try { |
| 267 mapping_functions[j].call(array, | 267 mapping_functions[j].call(array, |
| 268 should_throw_on_null_and_undefined[i], | 268 should_throw_on_null_and_undefined[i], |
| 269 undefined); | 269 undefined); |
| 270 } catch (e) { | 270 } catch (e) { |
| 271 exception = true; | 271 exception = true; |
| 272 assertTrue("called_on_null_or_undefined" == e.type || | 272 checkExpectedMessage(e); |
| 273 "null_to_object" == e.type); | |
| 274 } | 273 } |
| 275 assertTrue(exception); | 274 assertTrue(exception); |
| 276 } | 275 } |
| 277 } | 276 } |
| 278 | 277 |
| 279 for (var j = 0; j < mapping_functions.length; j++) { | 278 for (var j = 0; j < mapping_functions.length; j++) { |
| 280 for (var i = 0; i < non_generic.length; i++) { | 279 for (var i = 0; i < non_generic.length; i++) { |
| 281 exception = false; | 280 exception = false; |
| 282 try { | 281 try { |
| 283 mapping_functions[j].call(array, | 282 mapping_functions[j].call(array, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 304 | 303 |
| 305 | 304 |
| 306 // Reduce functions do a call with null as this argument. | 305 // Reduce functions do a call with null as this argument. |
| 307 for (var j = 0; j < reducing_functions.length; j++) { | 306 for (var j = 0; j < reducing_functions.length; j++) { |
| 308 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { | 307 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { |
| 309 exception = false; | 308 exception = false; |
| 310 try { | 309 try { |
| 311 reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]); | 310 reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]); |
| 312 } catch (e) { | 311 } catch (e) { |
| 313 exception = true; | 312 exception = true; |
| 314 assertTrue("called_on_null_or_undefined" == e.type || | 313 checkExpectedMessage(e); |
| 315 "null_to_object" == e.type); | |
| 316 } | 314 } |
| 317 assertTrue(exception); | 315 assertTrue(exception); |
| 318 | 316 |
| 319 exception = false; | 317 exception = false; |
| 320 try { | 318 try { |
| 321 reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]); | 319 reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]); |
| 322 } catch (e) { | 320 } catch (e) { |
| 323 exception = true; | 321 exception = true; |
| 324 assertTrue("called_on_null_or_undefined" == e.type || | 322 checkExpectedMessage(e); |
| 325 "null_to_object" == e.type); | |
| 326 } | 323 } |
| 327 assertTrue(exception); | 324 assertTrue(exception); |
| 328 } | 325 } |
| 329 } | 326 } |
| 330 | 327 |
| 331 for (var j = 0; j < reducing_functions.length; j++) { | 328 for (var j = 0; j < reducing_functions.length; j++) { |
| 332 for (var i = 0; i < non_generic.length; i++) { | 329 for (var i = 0; i < non_generic.length; i++) { |
| 333 exception = false; | 330 exception = false; |
| 334 try { | 331 try { |
| 335 reducing_functions[j].call(array, non_generic[i]); | 332 reducing_functions[j].call(array, non_generic[i]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 350 } | 347 } |
| 351 } | 348 } |
| 352 | 349 |
| 353 | 350 |
| 354 // Object.prototype.toString() | 351 // Object.prototype.toString() |
| 355 assertEquals(Object.prototype.toString.call(null), | 352 assertEquals(Object.prototype.toString.call(null), |
| 356 '[object Null]') | 353 '[object Null]') |
| 357 | 354 |
| 358 assertEquals(Object.prototype.toString.call(undefined), | 355 assertEquals(Object.prototype.toString.call(undefined), |
| 359 '[object Undefined]') | 356 '[object Undefined]') |
| OLD | NEW |