1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Flags: --allow-natives-syntax
7 assertEquals("1", %ToString(1));
8 assertEquals("1", %_ToString(1));
10 assertEquals("0.5", %ToString(.5));
11 assertEquals("0.5", %_ToString(.5));
13 assertEquals("null", %ToString(null));
14 assertEquals("null", %_ToString(null));
16 assertEquals("true", %ToString(true));
17 assertEquals("true", %_ToString(true));
19 assertEquals("false", %ToString(false));
20 assertEquals("false", %_ToString(false));
22 assertEquals("undefined", %ToString(undefined));
23 assertEquals("undefined", %_ToString(undefined));
25 assertEquals("random text", %ToString("random text"));
26 assertEquals("random text", %_ToString("random text"));
28 assertThrows(function() { %ToString(Symbol.toPrimitive) }, TypeError);
29 assertThrows(function() { %_ToString(Symbol.toPrimitive) }, TypeError);
31 var a = { toString: function() { return "xyz" }};
32 assertEquals("xyz", %ToString(a));
33 assertEquals("xyz", %_ToString(a));
35 var b = { valueOf: function() { return 42 }};
36 assertEquals("[object Object]", %ToString(b));
37 assertEquals("[object Object]", %_ToString(b));
40 toString: function() { return "x"},
41 valueOf: function() { return 123 }
43 assertEquals("x", %ToString(c));
44 assertEquals("x", %_ToString(c));
47 [Symbol.toPrimitive]: function(hint) { return hint }
49 assertEquals("string", %ToString(d));
50 assertEquals("string", %_ToString(d));