Chromium Code Reviews| Index: test/mjsunit/strong/implicit-conversions.js |
| diff --git a/test/mjsunit/strong/implicit-conversions.js b/test/mjsunit/strong/implicit-conversions.js |
| index dd22db152eb3aae91133383cf0cdfb4dd106f787..b5b5c05a9595f592e95db72fd33dcf7157d633ef 100644 |
| --- a/test/mjsunit/strong/implicit-conversions.js |
| +++ b/test/mjsunit/strong/implicit-conversions.js |
| @@ -7,69 +7,162 @@ |
| 'use strict'; |
|
arv (Not doing code reviews)
2015/04/27 14:02:49
Use double quotes here too for consistency.
conradw
2015/04/27 20:41:57
Done.
|
| // TODO(conradw): Implement other strong operators |
| -let strong_arith = [ |
| - "-", |
| - "*", |
| - "/", |
| - "%" |
| -] |
| - |
| -let nonnumber_values = [ |
| - "{}", |
| - "'foo'", |
| - "(function(){})", |
| - "[]", |
| - "'0'", |
| - "'NaN'", |
| - "(class Foo {})" |
| -] |
| - |
| -let number_values = [ |
| - "0", |
| - "(-0)", |
| - "1", |
| - "0.79", |
| - "(-0.79)", |
| - "4294967295", |
| - "4294967296", |
| - "(-4294967295)", |
| - "(-4294967296)", |
| - "9999999999999", |
| - "(-9999999999999)", |
| - "1.5e10", |
| - "(-1.5e10)", |
| - "0xFFF", |
| - "(-0xFFF)", |
| - "NaN", |
| - "Infinity", |
| - "(-Infinity)" |
| -] |
| +let strongBinops = [ |
| + "-", |
| + "*", |
| + "/", |
| + "%", |
| + "|", |
| + "&", |
| + "^", |
| + "<<", |
| + ">>", |
| + ">>>", |
| +]; |
| + |
| +let strongUnops = [ |
| + "~", |
| + "+", |
| + "-" |
| +]; |
| + |
| +let nonNumberValues = [ |
| + "{}", |
| + "'foo'", |
| + "(function(){})", |
| + "[]", |
| + "'0'", |
| + "'NaN'", |
| + "(class Foo {})" |
| +]; |
| + |
| +let numberValues = [ |
| + "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; |
| + return x - y; |
| } |
| function mul_strong(x, y) { |
| "use strong"; |
| - let v = x * y; |
| - return v; |
| + return x * y; |
| } |
| function div_strong(x, y) { |
| "use strong"; |
| - let v = x / y; |
| - return v; |
| + return x / y; |
| } |
| function mod_strong(x, y) { |
| "use strong"; |
| - let v = x % y; |
| - return v; |
| + return x % y; |
| +} |
| + |
| +function or_strong(x, y) { |
| + "use strong"; |
| + return x | y; |
| +} |
| + |
| +function and_strong(x, y) { |
| + "use strong"; |
| + return x & y; |
| +} |
| + |
| +function xor_strong(x, y) { |
| + "use strong"; |
| + return x ^ y; |
| +} |
| + |
| +function shl_strong(x, y) { |
| + "use strong"; |
| + return x << y; |
| +} |
| + |
| +function shr_strong(x, y) { |
| + "use strong"; |
| + return x >> y; |
| +} |
| + |
| +function sar_strong(x, y) { |
| + "use strong"; |
| + return x >>> y; |
| +} |
| + |
| +function typed_sub_strong(x, y) { |
| + "use strong"; |
| + return (+x) - (+y); |
| +} |
| + |
| +function typed_mul_strong(x, y) { |
| + "use strong"; |
| + return (+x) * (+y); |
| +} |
| + |
| +function typed_div_strong(x, y) { |
| + "use strong"; |
| + return (+x) / (+y); |
| +} |
| + |
| +function typed_mod_strong(x, y) { |
| + "use strong"; |
| + return (+x) % (+y); |
| +} |
| + |
| +function typed_or_strong(x, y) { |
| + "use strong"; |
| + return (+x) | (+y); |
| +} |
| + |
| +function typed_and_strong(x, y) { |
| + "use strong"; |
| + return (+x) & (+y); |
| +} |
| + |
| +function typed_xor_strong(x, y) { |
| + "use strong"; |
| + return (+x) ^ (+y); |
| +} |
| + |
| +function typed_shl_strong(x, y) { |
| + "use strong"; |
| + return (+x) << (+y); |
| } |
| -let strong_funcs = [sub_strong, mul_strong, div_strong, mod_strong]; |
| +function typed_shr_strong(x, y) { |
| + "use strong"; |
| + return (+x) >> (+y); |
| +} |
| + |
| +function typed_sar_strong(x, y) { |
| + "use strong"; |
| + return (+x) >>> (+y); |
| +} |
| + |
| +let strongFuncs = [sub_strong, mul_strong, div_strong, mod_strong, or_strong, |
| + and_strong, xor_strong, shl_strong, shr_strong, sar_strong, |
| + typed_sub_strong, typed_mul_strong, typed_div_strong, |
| + typed_mod_strong, typed_or_strong, typed_and_strong, |
| + typed_xor_strong, typed_shl_strong, typed_shr_strong, |
| + typed_sar_strong]; |
| function inline_sub_strong(x, y) { |
| "use strong"; |
| @@ -91,17 +184,17 @@ function inline_outer_strong(x, y) { |
| return inline_sub(x, y); |
| } |
| -for (let op of strong_arith) { |
| - for (let left of number_values) { |
| - for (let right of number_values) { |
| +for (let op of strongBinops) { |
| + for (let left of numberValues) { |
| + for (let right of numberValues) { |
| let expr = "(" + left + op + right + ")"; |
| assertEquals(eval(expr), eval("'use strong';" + expr)); |
| assertDoesNotThrow("'use strong'; " + expr + ";"); |
| assertDoesNotThrow("'use strong'; let v = " + expr + ";"); |
| } |
| } |
| - for (let left of number_values) { |
| - for (let right of nonnumber_values) { |
| + for (let left of numberValues) { |
| + for (let right of nonNumberValues) { |
| let expr = "(" + left + op + right + ")"; |
| assertDoesNotThrow("'use strict'; " + expr + ";"); |
| assertDoesNotThrow("'use strict'; let v = " + expr + ";"); |
| @@ -109,8 +202,8 @@ for (let op of strong_arith) { |
| assertThrows("'use strong'; let v = " + expr + ";", TypeError); |
| } |
| } |
| - for (let left of nonnumber_values) { |
| - for (let right of number_values.concat(nonnumber_values)) { |
| + for (let left of nonNumberValues) { |
| + for (let right of numberValues.concat(nonNumberValues)) { |
| let expr = "(" + left + op + right + ")"; |
| assertDoesNotThrow("'use strict'; " + expr + ";"); |
| assertDoesNotThrow("'use strict'; let v = " + expr + ";"); |
| @@ -120,7 +213,23 @@ for (let op of strong_arith) { |
| } |
| } |
| -for (let func of strong_funcs) { |
| +for (let op of strongUnops) { |
| + for (let value of numberValues) { |
| + let expr = "(" + op + value + ")"; |
| + assertEquals(eval(expr), eval("'use strong';" + expr)); |
| + assertDoesNotThrow("'use strong'; " + expr + ";"); |
| + assertDoesNotThrow("'use strong'; let v = " + expr + ";"); |
| + } |
| + for (let value of nonNumberValues) { |
| + let expr = "(" + op + value + ")"; |
| + 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 strongFuncs) { |
| let a = func(4, 5); |
| let b = func(4, 5); |
| assertTrue(a === b); |
| @@ -135,7 +244,7 @@ for (let func of strong_funcs) { |
| %ClearFunctionTypeFeedback(func); |
| } |
| -for (let func of strong_funcs) { |
| +for (let func of strongFuncs) { |
| try { |
| let a = func(2, 3); |
| let b = func(2, 3); |
| @@ -143,8 +252,8 @@ for (let func of strong_funcs) { |
| %OptimizeFunctionOnNextCall(func); |
| let c = func(2, "foo"); |
| assertUnreachable(); |
| - } catch(e) { |
| - assertTrue(e instanceof TypeError); |
| + } catch (e) { |
| + assertInstanceof(e, TypeError); |
| assertUnoptimized(func); |
| assertThrows(function(){func(2, "foo");}, TypeError); |
| assertDoesNotThrow(function(){func(2, 3);}); |