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

Unified Diff: test/mjsunit/harmony/to-length.js

Issue 1412963002: [runtime] Implement %_ToLength via ToLengthStub. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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/harmony/to-length.js
diff --git a/test/mjsunit/harmony/to-length.js b/test/mjsunit/harmony/to-length.js
new file mode 100644
index 0000000000000000000000000000000000000000..b805e5cffe08546274fa405803948326e99ad208
--- /dev/null
+++ b/test/mjsunit/harmony/to-length.js
@@ -0,0 +1,76 @@
+// 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: --allow-natives-syntax
+
+assertEquals(0, %ToLength(NaN));
+assertEquals(0, %_ToLength(NaN));
+
+assertEquals(0, %ToLength(-Infinity));
+assertEquals(0, %_ToLength(-Infinity));
+
+assertEquals(0, %ToLength(0));
+assertEquals(0, %_ToLength(0));
+
+assertEquals(0, %ToLength(.5));
+assertEquals(0, %_ToLength(.5));
+
+assertEquals(42, %ToLength(42.99999));
+assertEquals(42, %_ToLength(42.99999));
+
+assertEquals(9007199254740991, %ToLength(9007199254740991));
+assertEquals(9007199254740991, %_ToLength(9007199254740991));
+
+assertEquals(9007199254740991, %ToLength(Infinity));
+assertEquals(9007199254740991, %_ToLength(Infinity));
+
+assertEquals(0, %ToLength(null));
+assertEquals(0, %_ToLength(null));
+
+assertEquals(1, %ToLength(true));
+assertEquals(1, %_ToLength(true));
+
+assertEquals(0, %ToLength(false));
+assertEquals(0, %_ToLength(false));
+
+assertEquals(0, %ToLength(undefined));
+assertEquals(0, %_ToLength(undefined));
+
+assertEquals(0, %ToLength("-1"));
+assertEquals(0, %_ToLength("-1"));
+assertEquals(123, %ToLength("123"));
+assertEquals(123, %_ToLength("123"));
+assertEquals(0, %ToLength("random text"));
+assertEquals(0, %_ToLength("random text"));
+
+assertThrows(function() { %ToLength(Symbol.toPrimitive) }, TypeError);
+assertThrows(function() { %_ToLength(Symbol.toPrimitive) }, TypeError);
+
+var a = { toString: function() { return 54321 }};
+assertEquals(54321, %ToLength(a));
+assertEquals(54321, %_ToLength(a));
+
+var b = { valueOf: function() { return 42 }};
+assertEquals(42, %ToLength(b));
+assertEquals(42, %_ToLength(b));
+
+var c = {
+ toString: function() { return "x"},
+ valueOf: function() { return 123 }
+};
+assertEquals(123, %ToLength(c));
+assertEquals(123, %_ToLength(c));
+
+var d = {
+ [Symbol.toPrimitive]: function(hint) {
+ assertEquals("number", hint);
+ return 987654321;
+ }
+};
+assertEquals(987654321, %ToLength(d));
+assertEquals(987654321, %_ToLength(d));
+
+var e = new Date(0);
+assertEquals(0, %ToLength(e));
+assertEquals(0, %_ToLength(e));
« src/full-codegen/arm/full-codegen-arm.cc ('K') | « src/x64/interface-descriptors-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698