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

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

Issue 1216463003: [strong] Implement strong mode semantics for the count operation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cl feedback + eliminate runtime check Created 5 years, 6 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
« no previous file with comments | « test/mjsunit/strong/implicit-conversions-constants.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/strong/implicit-conversions-count.js
diff --git a/test/mjsunit/strong/implicit-conversions-count.js b/test/mjsunit/strong/implicit-conversions-count.js
new file mode 100644
index 0000000000000000000000000000000000000000..88ed3c2068cbbb5f8c6820376024701b28db8a44
--- /dev/null
+++ b/test/mjsunit/strong/implicit-conversions-count.js
@@ -0,0 +1,168 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// 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";
+
+function pre_inc(x) {
+ return ++x;
+}
+
+function post_inc(x) {
+ return x++;
+}
+
+function pre_dec(x) {
+ return --x;
+}
+
+function post_dec(x) {
+ return x--;
+}
+
+function getTestFuncs() {
+ return [
+ function(x){
+ "use strong";
+ let y = x;
+ assertEquals(++y, pre_inc(x));
+ try {
+ assertEquals(x+1, y)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ function(x){
+ "use strong";
+ let y = x;
+ assertEquals(y++, post_inc(x));
+ try {
+ assertEquals(x+1, y)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ function(x){
+ "use strong";
+ let y = x;
+ assertEquals(--y, pre_dec(x));
+ try {
+ assertEquals(x-1, y)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ function(x){
+ "use strong";
+ let y = x;
+ assertEquals(y--, post_dec(x));
+ try {
+ assertEquals(x-1, y)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ function(x){
+ "use strong";
+ let obj = { foo: x };
+ let y = ++obj.foo;
+ assertEquals(y, pre_inc(x));
+ try {
+ assertEquals(x+1, obj.foo)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ function(x){
+ "use strong";
+ let obj = { foo: x };
+ let y = obj.foo++;
+ assertEquals(y, post_inc(x));
+ try {
+ assertEquals(x+1, obj.foo)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ function(x){
+ "use strong";
+ let obj = { foo: x };
+ let y = --obj.foo;
+ assertEquals(y, pre_dec(x));
+ try {
+ assertEquals(x-1, obj.foo)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ function(x){
+ "use strong";
+ let obj = { foo: x };
+ let y = obj.foo--;
+ assertEquals(y, post_dec(x));
+ try {
+ assertEquals(x-1, obj.foo)
+ } catch (e) {
+ assertUnreachable();
+ }
+ },
+ ];
+}
+
+let nonNumberValues = [
+ {},
+ (function(){}),
+ [],
+ (class Foo {}),
+ "",
+ "foo",
+ "NaN",
+ Object(""),
+ false,
+ null,
+ undefined
+];
+
+// Check prior input of None works
+for (let func of getTestFuncs()) {
+ for (let value of nonNumberValues) {
+ assertThrows(function(){func(value)}, TypeError);
+ assertThrows(function(){func(value)}, TypeError);
+ assertThrows(function(){func(value)}, TypeError);
+ %OptimizeFunctionOnNextCall(func);
+ assertThrows(function(){func(value)}, TypeError);
+ %DeoptimizeFunction(func);
+ }
+}
+
+// Check prior input of Smi works
+for (let func of getTestFuncs()) {
+ func(1);
+ func(1);
+ func(1);
+ for (let value of nonNumberValues) {
+ assertThrows(function(){func(value)}, TypeError);
+ assertThrows(function(){func(value)}, TypeError);
+ assertThrows(function(){func(value)}, TypeError);
+ %OptimizeFunctionOnNextCall(func);
+ assertThrows(function(){func(value)}, TypeError);
+ %DeoptimizeFunction(func);
+ }
+}
+
+// Check prior input of Number works
+for (let func of getTestFuncs()) {
+ func(9999999999999);
+ func(9999999999999);
+ func(9999999999999);
+ for (let value of nonNumberValues) {
+ assertThrows(function(){func(value)}, TypeError);
+ assertThrows(function(){func(value)}, TypeError);
+ assertThrows(function(){func(value)}, TypeError);
+ %OptimizeFunctionOnNextCall(func);
+ assertThrows(function(){func(value)}, TypeError);
+ %DeoptimizeFunction(func);
+ }
+}
« no previous file with comments | « test/mjsunit/strong/implicit-conversions-constants.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698