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

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

Issue 1319973007: [runtime] Add %ToString and %_ToString and remove the TO_STRING builtin. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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 | « src/x64/interface-descriptors-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/to-string.js
diff --git a/test/mjsunit/harmony/to-string.js b/test/mjsunit/harmony/to-string.js
new file mode 100644
index 0000000000000000000000000000000000000000..4f03c466ea4ceea8c559f406f380b4e2f99e287c
--- /dev/null
+++ b/test/mjsunit/harmony/to-string.js
@@ -0,0 +1,50 @@
+// 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("1", %ToString(1));
+assertEquals("1", %_ToString(1));
+
+assertEquals("0.5", %ToString(.5));
+assertEquals("0.5", %_ToString(.5));
+
+assertEquals("null", %ToString(null));
+assertEquals("null", %_ToString(null));
+
+assertEquals("true", %ToString(true));
+assertEquals("true", %_ToString(true));
+
+assertEquals("false", %ToString(false));
+assertEquals("false", %_ToString(false));
+
+assertEquals("undefined", %ToString(undefined));
+assertEquals("undefined", %_ToString(undefined));
+
+assertEquals("random text", %ToString("random text"));
+assertEquals("random text", %_ToString("random text"));
+
+assertThrows(function() { %ToString(Symbol.toPrimitive) }, TypeError);
+assertThrows(function() { %_ToString(Symbol.toPrimitive) }, TypeError);
+
+var a = { toString: function() { return "xyz" }};
+assertEquals("xyz", %ToString(a));
+assertEquals("xyz", %_ToString(a));
+
+var b = { valueOf: function() { return 42 }};
+assertEquals("[object Object]", %ToString(b));
+assertEquals("[object Object]", %_ToString(b));
+
+var c = {
+ toString: function() { return "x"},
+ valueOf: function() { return 123 }
+};
+assertEquals("x", %ToString(c));
+assertEquals("x", %_ToString(c));
+
+var d = {
+ [Symbol.toPrimitive]: function(hint) { return hint }
+};
+assertEquals("string", %ToString(d));
+assertEquals("string", %_ToString(d));
« no previous file with comments | « src/x64/interface-descriptors-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698