OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --strong-mode --allow-natives-syntax | 5 // Flags: --strong-mode --allow-natives-syntax |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 // Boolean indicates whether an operator can be part of a compound assignment. | 9 // Boolean indicates whether an operator can be part of a compound assignment. |
10 let strongNumberBinops = [ | 10 let strongNumberBinops = [ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 "'0'", | 54 "'0'", |
55 "'NaN'" | 55 "'NaN'" |
56 ]; | 56 ]; |
57 | 57 |
58 let nonNumberValues = nonStringOrNumberValues.concat(stringValues); | 58 let nonNumberValues = nonStringOrNumberValues.concat(stringValues); |
59 | 59 |
60 let numberValues = [ | 60 let numberValues = [ |
61 "0", | 61 "0", |
62 "(-0)", | 62 "(-0)", |
63 "1", | 63 "1", |
64 "0.79", | |
65 "(-0.79)", | |
66 "4294967295", | |
67 "4294967296", | |
68 "(-4294967295)", | 64 "(-4294967295)", |
69 "(-4294967296)", | 65 "(-4294967296)", |
70 "9999999999999", | 66 "9999999999999", |
71 "(-9999999999999)", | 67 "(-9999999999999)", |
72 "1.5e10", | |
73 "(-1.5e10)", | |
74 "0xFFF", | |
75 "(-0xFFF)", | |
76 "NaN", | 68 "NaN", |
77 "Infinity", | 69 "Infinity", |
78 "(-Infinity)" | 70 "(-Infinity)" |
79 ]; | 71 ]; |
80 | 72 |
| 73 //****************************************************************************** |
| 74 // Relational comparison function declarations |
81 function add_strong(x, y) { | 75 function add_strong(x, y) { |
82 "use strong"; | 76 "use strong"; |
83 return x + y; | 77 return x + y; |
84 } | 78 } |
85 | 79 |
86 function add_num_strong(x, y) { | 80 function add_num_strong(x, y) { |
87 "use strong"; | 81 "use strong"; |
88 return x + y; | 82 return x + y; |
89 } | 83 } |
90 | 84 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 function typed_less_equal_strong(x, y) { | 240 function typed_less_equal_strong(x, y) { |
247 "use strong"; | 241 "use strong"; |
248 return (+x) <= (+y); | 242 return (+x) <= (+y); |
249 } | 243 } |
250 | 244 |
251 function typed_greater_equal_strong(x, y) { | 245 function typed_greater_equal_strong(x, y) { |
252 "use strong"; | 246 "use strong"; |
253 return (+x) >= (+y); | 247 return (+x) >= (+y); |
254 } | 248 } |
255 | 249 |
| 250 //****************************************************************************** |
| 251 // (in)equality function declarations |
| 252 function str_equal_strong(x, y) { |
| 253 "use strong"; |
| 254 return x === y; |
| 255 } |
| 256 |
| 257 function str_ineq_strong(x, y) { |
| 258 "use strong"; |
| 259 return x !== y; |
| 260 } |
| 261 |
256 let strongNumberFuncs = [add_num_strong, sub_strong, mul_strong, div_strong, | 262 let strongNumberFuncs = [add_num_strong, sub_strong, mul_strong, div_strong, |
257 mod_strong, or_strong, and_strong, xor_strong, | 263 mod_strong, or_strong, and_strong, xor_strong, |
258 shl_strong, shr_strong, sar_strong, less_num_strong, | 264 shl_strong, shr_strong, sar_strong, less_num_strong, |
259 greater_num_strong, less_equal_num_strong, | 265 greater_num_strong, less_equal_num_strong, |
260 greater_equal_num_strong, typed_add_strong, | 266 greater_equal_num_strong, typed_add_strong, |
261 typed_sub_strong, typed_mul_strong, typed_div_strong, | 267 typed_sub_strong, typed_mul_strong, typed_div_strong, |
262 typed_mod_strong, typed_or_strong, typed_and_strong, | 268 typed_mod_strong, typed_or_strong, typed_and_strong, |
263 typed_xor_strong, typed_shl_strong, typed_shr_strong, | 269 typed_xor_strong, typed_shl_strong, typed_shr_strong, |
264 typed_sar_strong, typed_less_strong, | 270 typed_sar_strong, typed_less_strong, |
265 typed_greater_strong, typed_less_equal_strong, | 271 typed_greater_strong, typed_less_equal_strong, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 for (let value of numberValues) { | 331 for (let value of numberValues) { |
326 assertStrongNonThrowBehaviour("(" + op + value + ")"); | 332 assertStrongNonThrowBehaviour("(" + op + value + ")"); |
327 } | 333 } |
328 for (let value of nonNumberValues) { | 334 for (let value of nonNumberValues) { |
329 assertStrongThrowBehaviour("(" + op + value + ")"); | 335 assertStrongThrowBehaviour("(" + op + value + ")"); |
330 } | 336 } |
331 } | 337 } |
332 | 338 |
333 for (let func of strongNumberFuncs) { | 339 for (let func of strongNumberFuncs) { |
334 // Check IC None*None->None throws | 340 // Check IC None*None->None throws |
335 assertThrows(function(){func(2, "foo");}, TypeError); | 341 for (let v of nonNumberValues) { |
336 %OptimizeFunctionOnNextCall(func); | 342 let value = eval(v); |
337 assertThrows(function(){func(2, "foo");}, TypeError); | 343 assertThrows(function(){func(2, value);}, TypeError); |
338 %DeoptimizeFunction(func); | 344 %OptimizeFunctionOnNextCall(func); |
| 345 assertThrows(function(){func(2, value);}, TypeError); |
| 346 %DeoptimizeFunction(func); |
| 347 } |
339 func(4, 5); | 348 func(4, 5); |
340 func(4, 5); | 349 func(4, 5); |
341 // Check IC Smi*Smi->Smi throws | 350 // Check IC Smi*Smi->Smi throws |
342 assertThrows(function(){func(2, "foo");}, TypeError); | 351 for (let v of nonNumberValues) { |
343 %OptimizeFunctionOnNextCall(func); | 352 let value = eval(v); |
344 assertThrows(function(){func(2, "foo");}, TypeError); | 353 assertThrows(function(){func(2, value);}, TypeError); |
345 %DeoptimizeFunction(func); | 354 %OptimizeFunctionOnNextCall(func); |
| 355 assertThrows(function(){func(2, value);}, TypeError); |
| 356 %DeoptimizeFunction(func); |
| 357 } |
346 func(NaN, NaN); | 358 func(NaN, NaN); |
347 func(NaN, NaN); | 359 func(NaN, NaN); |
348 // Check IC Number*Number->Number throws | 360 // Check IC Number*Number->Number throws |
349 assertThrows(function(){func(2, "foo");}, TypeError); | 361 for (let v of nonNumberValues) { |
350 %OptimizeFunctionOnNextCall(func); | 362 let value = eval(v); |
351 assertThrows(function(){func(2, "foo");}, TypeError); | 363 assertThrows(function(){func(2, value);}, TypeError); |
352 %DeoptimizeFunction(func); | 364 %OptimizeFunctionOnNextCall(func); |
| 365 assertThrows(function(){func(2, value);}, TypeError); |
| 366 %DeoptimizeFunction(func); |
| 367 } |
353 } | 368 } |
354 | 369 |
355 for (let func of strongStringOrNumberFuncs) { | 370 for (let func of strongStringOrNumberFuncs) { |
356 // Check IC None*None->None throws | 371 // Check IC None*None->None throws |
357 assertThrows(function(){func(2, "foo");}, TypeError); | 372 for (let v of nonNumberValues) { |
358 %OptimizeFunctionOnNextCall(func); | 373 let value = eval(v); |
359 assertThrows(function(){func(2, "foo");}, TypeError); | 374 assertThrows(function(){func(2, value);}, TypeError); |
360 %DeoptimizeFunction(func); | 375 %OptimizeFunctionOnNextCall(func); |
| 376 assertThrows(function(){func(2, value);}, TypeError); |
| 377 %DeoptimizeFunction(func); |
| 378 } |
361 func("foo", "bar"); | 379 func("foo", "bar"); |
362 func("foo", "bar"); | 380 func("foo", "bar"); |
363 // Check IC String*String->String throws | 381 // Check IC String*String->String throws |
364 assertThrows(function(){func(2, "foo");}, TypeError); | 382 for (let v of nonNumberValues) { |
365 %OptimizeFunctionOnNextCall(func); | 383 let value = eval(v); |
366 assertThrows(function(){func(2, "foo");}, TypeError); | 384 assertThrows(function(){func(2, value);}, TypeError); |
367 %DeoptimizeFunction(func); | 385 %OptimizeFunctionOnNextCall(func); |
| 386 assertThrows(function(){func(2, value);}, TypeError); |
| 387 %DeoptimizeFunction(func); |
| 388 } |
368 func(NaN, NaN); | 389 func(NaN, NaN); |
369 func(NaN, NaN); | 390 func(NaN, NaN); |
370 // Check IC Generic*Generic->Generic throws | 391 // Check IC Generic*Generic->Generic throws |
371 assertThrows(function(){func(2, "foo");}, TypeError); | 392 for (let v of nonNumberValues) { |
| 393 let value = eval(v); |
| 394 assertThrows(function(){func(2, value);}, TypeError); |
| 395 %OptimizeFunctionOnNextCall(func); |
| 396 assertThrows(function(){func(2, value);}, TypeError); |
| 397 %DeoptimizeFunction(func); |
| 398 } |
| 399 } |
| 400 |
| 401 for (let func of [str_equal_strong, str_ineq_strong]) { |
| 402 assertDoesNotThrow(function(){func(2, undefined)}); |
| 403 assertDoesNotThrow(function(){func(2, undefined)}); |
372 %OptimizeFunctionOnNextCall(func); | 404 %OptimizeFunctionOnNextCall(func); |
373 assertThrows(function(){func(2, "foo");}, TypeError); | 405 assertDoesNotThrow(function(){func(2, undefined)}); |
| 406 %DeoptimizeFunction(func); |
| 407 assertDoesNotThrow(function(){func(true, {})}); |
| 408 assertDoesNotThrow(function(){func(true, {})}); |
| 409 %OptimizeFunctionOnNextCall(func); |
| 410 assertDoesNotThrow(function(){func(true, {})}); |
374 %DeoptimizeFunction(func); | 411 %DeoptimizeFunction(func); |
375 } | 412 } |
OLD | NEW |