| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 e.message.indexOf("Cannot convert undefined or null to object") >= 0); | 155 e.message.indexOf("Cannot convert undefined or null to object") >= 0); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // 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. |
| 159 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++) { |
| 160 // Sanity check that all functions are correct | 160 // Sanity check that all functions are correct |
| 161 assertEquals(typeof(should_throw_on_null_and_undefined[i]), "function"); | 161 assertEquals(typeof(should_throw_on_null_and_undefined[i]), "function"); |
| 162 | 162 |
| 163 var exception = false; | 163 var exception = false; |
| 164 try { | 164 try { |
| 165 // We call all functions with no parameters, which means that essential | 165 // We need to pass a dummy object argument ({}) to these functions because |
| 166 // parameters will have the undefined value. | 166 // of Object.prototype.isPrototypeOf's special behavior, see issue 3483 |
| 167 // The test for whether the "this" value is null or undefined is always | 167 // for more details. |
| 168 // performed before access to the other parameters, so even if the | 168 should_throw_on_null_and_undefined[i].call(null, {}); |
| 169 // undefined value is an invalid argument value, it mustn't change | |
| 170 // the result of the test. | |
| 171 should_throw_on_null_and_undefined[i].call(null); | |
| 172 } catch (e) { | 169 } catch (e) { |
| 173 exception = true; | 170 exception = true; |
| 174 checkExpectedMessage(e); | 171 checkExpectedMessage(e); |
| 175 } | 172 } |
| 176 assertTrue(exception); | 173 assertTrue(exception); |
| 177 | 174 |
| 178 exception = false; | 175 exception = false; |
| 179 try { | 176 try { |
| 180 should_throw_on_null_and_undefined[i].call(undefined); | 177 should_throw_on_null_and_undefined[i].call(undefined, {}); |
| 181 } catch (e) { | 178 } catch (e) { |
| 182 exception = true; | 179 exception = true; |
| 183 checkExpectedMessage(e); | 180 checkExpectedMessage(e); |
| 184 } | 181 } |
| 185 assertTrue(exception); | 182 assertTrue(exception); |
| 186 | 183 |
| 187 exception = false; | 184 exception = false; |
| 188 try { | 185 try { |
| 189 should_throw_on_null_and_undefined[i].apply(null); | 186 should_throw_on_null_and_undefined[i].apply(null, [{}]); |
| 190 } catch (e) { | 187 } catch (e) { |
| 191 exception = true; | 188 exception = true; |
| 192 checkExpectedMessage(e); | 189 checkExpectedMessage(e); |
| 193 } | 190 } |
| 194 assertTrue(exception); | 191 assertTrue(exception); |
| 195 | 192 |
| 196 exception = false; | 193 exception = false; |
| 197 try { | 194 try { |
| 198 should_throw_on_null_and_undefined[i].apply(undefined); | 195 should_throw_on_null_and_undefined[i].apply(undefined, [{}]); |
| 199 } catch (e) { | 196 } catch (e) { |
| 200 exception = true; | 197 exception = true; |
| 201 checkExpectedMessage(e); | 198 checkExpectedMessage(e); |
| 202 } | 199 } |
| 203 assertTrue(exception); | 200 assertTrue(exception); |
| 204 } | 201 } |
| 205 | 202 |
| 206 // Test that all natives that are non generic throw on null and undefined. | 203 // Test that all natives that are non generic throw on null and undefined. |
| 207 for (var i = 0; i < non_generic.length; i++) { | 204 for (var i = 0; i < non_generic.length; i++) { |
| 208 // Sanity check that all functions are correct | 205 // Sanity check that all functions are correct |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } catch (e) { | 238 } catch (e) { |
| 242 exception = true; | 239 exception = true; |
| 243 assertTrue(e instanceof TypeError); | 240 assertTrue(e instanceof TypeError); |
| 244 } | 241 } |
| 245 assertTrue(exception); | 242 assertTrue(exception); |
| 246 } | 243 } |
| 247 | 244 |
| 248 | 245 |
| 249 // Test that we still throw when calling with thisArg null or undefined | 246 // Test that we still throw when calling with thisArg null or undefined |
| 250 // through an array mapping function. | 247 // through an array mapping function. |
| 251 var array = [1,2,3,4,5]; | 248 // We need to make sure that the elements of `array` are all object values, |
| 249 // see issue 3483 for more details. |
| 250 var array = [{}, [], new Number, new Map, new WeakSet]; |
| 252 for (var j = 0; j < mapping_functions.length; j++) { | 251 for (var j = 0; j < mapping_functions.length; j++) { |
| 253 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { | 252 for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) { |
| 254 exception = false; | 253 exception = false; |
| 255 try { | 254 try { |
| 256 mapping_functions[j].call(array, | 255 mapping_functions[j].call(array, |
| 257 should_throw_on_null_and_undefined[i], | 256 should_throw_on_null_and_undefined[i], |
| 258 null); | 257 null); |
| 259 } catch (e) { | 258 } catch (e) { |
| 260 exception = true; | 259 exception = true; |
| 261 checkExpectedMessage(e); | 260 checkExpectedMessage(e); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 346 } |
| 348 } | 347 } |
| 349 | 348 |
| 350 | 349 |
| 351 // Object.prototype.toString() | 350 // Object.prototype.toString() |
| 352 assertEquals(Object.prototype.toString.call(null), | 351 assertEquals(Object.prototype.toString.call(null), |
| 353 '[object Null]') | 352 '[object Null]') |
| 354 | 353 |
| 355 assertEquals(Object.prototype.toString.call(undefined), | 354 assertEquals(Object.prototype.toString.call(undefined), |
| 356 '[object Undefined]') | 355 '[object Undefined]') |
| OLD | NEW |