Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1484)

Unified Diff: test/mjsunit/strong/implicit-conversions.js

Issue 1102923002: [strong] Disallow implicit conversions for bitwise ops, shifts (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: more test formatting Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f5870770ff02a1bef180e5cdb49a27a1038b13fc 100644
--- a/test/mjsunit/strong/implicit-conversions.js
+++ b/test/mjsunit/strong/implicit-conversions.js
@@ -7,69 +7,114 @@
'use strict';
// 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 strong_binops = [
arv (Not doing code reviews) 2015/04/24 15:39:42 FYI. Our js style does not allow underscores in va
conradw 2015/04/27 11:20:47 Hah! I should at least try and be consistent, sinc
+ "-",
+ "*",
+ "/",
+ "%",
+ "|",
+ "&",
+ "^",
+ "<<",
+ ">>",
+ ">>>",
+];
+
+let strong_unops = [
+ "~"
+];
+
+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;
}
-let strong_funcs = [sub_strong, mul_strong, div_strong, mod_strong];
+function sar_strong(x, y) {
+ "use strong";
+ return x >>> y;
+}
+
+function not_strong(x, y) {
arv (Not doing code reviews) 2015/04/24 15:39:42 Not clear why you need this function. You are test
conradw 2015/04/27 11:20:47 Yeah, it was a mistake to put this here.
+ "use strong";
+ let v1 = ~x;
+ let v2 = ~y;
+ return v1 | v2;
+}
+
+let strong_funcs = [sub_strong, mul_strong, div_strong, mod_strong, or_strong,
+ and_strong, xor_strong, shl_strong, shr_strong, sar_strong,
+ not_strong];
function inline_sub_strong(x, y) {
"use strong";
@@ -91,17 +136,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 strong_binops) {
+ 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 +154,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,6 +165,22 @@ for (let op of strong_arith) {
}
}
+for (let op of strong_unops) {
+ 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 strong_funcs) {
let a = func(4, 5);
let b = func(4, 5);
@@ -143,8 +204,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);});

Powered by Google App Engine
This is Rietveld 408576698