Chromium Code Reviews| Index: test/mjsunit/strong/implicit-casts.js |
| diff --git a/test/mjsunit/strong/implicit-casts.js b/test/mjsunit/strong/implicit-casts.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8de7d9cefb05bb719107519f363d498957ffb909 |
| --- /dev/null |
| +++ b/test/mjsunit/strong/implicit-casts.js |
| @@ -0,0 +1,164 @@ |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
|
rossberg
2015/04/23 13:29:37
Nit: rename file to implicit-conversions.js
conradw
2015/04/23 14:51:55
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --strong-mode --allow-natives-syntax |
| + |
| +'use strict'; |
| + |
| +//TODO(conradw): Implement other strong operators |
|
rossberg
2015/04/23 13:29:37
Nit: spacing
conradw
2015/04/23 14:51:55
Done.
|
| +let strong_arith = [ |
| + "-", |
| + "*", |
| + "/", |
| + "%" |
| +] |
| + |
| +let cast_values = [ |
|
rossberg
2015/04/23 13:29:37
Nit: nonnumber_values
conradw
2015/04/23 14:51:55
Done.
|
| + "{}", |
| + "'foo'", |
| + "(function(){})", |
| + "[]", |
| + "'0'", |
| + "'NaN'", |
| + "(class Foo {})" |
| +] |
| + |
| +let uncast_values = [ |
|
rossberg
2015/04/23 13:29:37
Nit: number_values
conradw
2015/04/23 14:51:55
Done.
|
| + "0", |
| + "(-0)", |
| + "1", |
| + "0.79", |
| + "(-0.79)", |
| + "4294967295", |
| + "4294967296", |
| + "(-4294967295)", |
| + "(-4294967296)", |
| + "9999999999999", |
| + "(-9999999999999)", |
| + "1.5e10", |
| + "(-1.5e10)", |
| + "0xFFF", |
| + "(-0xFFF)", |
| + "NaN", |
| + "Infinity", |
| + "(-Infinity)" |
| +] |
| + |
| +function sub_strong(x, y) { |
| + "use strong"; |
| + let v = x - y; |
| + return v; |
| +} |
| + |
| +function mul_strong(x, y) { |
| + "use strong"; |
| + let v = x * y; |
| + return v; |
| +} |
| + |
| +function div_strong(x, y) { |
| + "use strong"; |
| + let v = x / y; |
| + return v; |
| +} |
| + |
| +function mod_strong(x, y) { |
| + "use strong"; |
| + let v = x % y; |
| + return v; |
| +} |
| + |
| +let strong_funcs = [sub_strong, mul_strong, div_strong, mod_strong]; |
| + |
| +function inline_sub_strong(x, y) { |
| + "use strong"; |
| + let v = x - y; |
| + return v; |
| +} |
| + |
| +function inline_outer(x, y) { |
| + return inline_sub_strong(x, y); |
| +} |
| + |
| +function inline_sub(x, y) { |
| + let v = x - y; |
| + return v; |
| +} |
| + |
| +function inline_outer_strong(x, y) { |
| + "use strong"; |
| + return inline_sub(x, y); |
| +} |
| + |
| +for (let op of strong_arith) { |
| + for (let v_left of uncast_values) { |
|
rossberg
2015/04/23 13:29:37
Nit: drop the v_
conradw
2015/04/23 14:51:55
Done.
|
| + for (let v_right of uncast_values) { |
| + let expr = "(" + v_left + op + v_right + ")"; |
| + assertEquals(eval(expr), eval("'use strong';" + expr)); |
| + assertDoesNotThrow("'use strong'; " + expr + ";"); |
| + assertDoesNotThrow("'use strong'; let v = " + expr + ";"); |
| + } |
| + } |
| + for (let v_left of uncast_values) { |
| + for (let v_right of cast_values) { |
| + let expr = "(" + v_left + op + v_right + ")"; |
| + assertDoesNotThrow("'use strict'; " + expr + ";"); |
| + assertDoesNotThrow("'use strict'; let v = " + expr + ";"); |
| + assertThrows("'use strong'; " + expr + ";", TypeError); |
| + assertThrows("'use strong'; let v = " + expr + ";", TypeError); |
| + } |
| + } |
| + for (let v_left of cast_values) { |
| + for (let v_right of uncast_values.concat(cast_values)) { |
| + let expr = "(" + v_left + op + v_right + ")"; |
| + assertDoesNotThrow("'use strict'; " + expr + ";"); |
| + assertDoesNotThrow("'use strict'; let v = " + expr + ";"); |
| + assertThrows("'use strong'; " + expr + ";", TypeError); |
| + assertThrows("'use strong'; let v = " + expr + ";", TypeError); |
| + } |
| + } |
| +} |
| + |
| +for (let func of strong_funcs) { |
| + let a = func(4, 5); |
| + let b = func(4, 5); |
| + assertTrue(a === b); |
| + %OptimizeFunctionOnNextCall(func); |
| + let c = func(4, 5); |
| + assertOptimized(func); |
| + assertTrue(b === c); |
| + %DeoptimizeFunction(func); |
| + let d = func(4, 5); |
| + assertTrue(c === d); |
| + %DeoptimizeFunction(func); |
| + %ClearFunctionTypeFeedback(func); |
| +} |
| + |
| +for (let func of strong_funcs) { |
| + try { |
| + let a = func(2, 3); |
| + let b = func(2, 3); |
| + assertTrue(a === b); |
| + %OptimizeFunctionOnNextCall(func); |
| + let c = func(2, "foo"); |
| + assertUnreachable(); |
| + } catch(e) { |
| + assertTrue(e instanceof TypeError); |
| + assertUnoptimized(func); |
| + assertThrows(function(){func(2, "foo");}, TypeError); |
| + assertDoesNotThrow(function(){func(2, 3);}); |
| + } |
| +} |
| + |
| +assertThrows(function(){inline_outer(1, {})}, TypeError); |
| +for (var i = 0; i < 100; i++) { |
| + inline_outer(1, 2); |
| +} |
| +assertThrows(function(){inline_outer(1, {})}, TypeError); |
| + |
| +assertDoesNotThrow(function(){inline_outer_strong(1, {})}); |
| +for (var i = 0; i < 100; i++) { |
| + inline_outer_strong(1, 2); |
| +} |
| +assertDoesNotThrow(function(){inline_outer_strong(1, {})}); |