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

Side by Side Diff: test/mjsunit/harmony/to-primitive.js

Issue 1324713002: [es6] Implement Date.prototype[@@toPrimitive] as C++ builtin. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Michi's comments. Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/to-number.js ('k') | test/mjsunit/harmony/to-string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --allow-natives-syntax 5 // Flags: --allow-natives-syntax
6 6
7 assertEquals(1, %ToPrimitive(1)); 7 assertEquals(1, %ToPrimitive(1));
8 assertEquals(1, %ToPrimitive_Number(1)); 8 assertEquals(1, %ToPrimitive_Number(1));
9 assertEquals(1, %ToPrimitive_String(1)); 9 assertEquals(1, %ToPrimitive_String(1));
10 assertEquals(1, %_ToPrimitive(1)); 10 assertEquals(1, %_ToPrimitive(1));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 assertEquals(Symbol.toPrimitive, %_ToPrimitive_Number(Symbol.toPrimitive)); 60 assertEquals(Symbol.toPrimitive, %_ToPrimitive_Number(Symbol.toPrimitive));
61 assertEquals(Symbol.toPrimitive, %_ToPrimitive_String(Symbol.toPrimitive)); 61 assertEquals(Symbol.toPrimitive, %_ToPrimitive_String(Symbol.toPrimitive));
62 62
63 var a = { toString: function() { return "xyz" }}; 63 var a = { toString: function() { return "xyz" }};
64 assertEquals("xyz", %ToPrimitive(a)); 64 assertEquals("xyz", %ToPrimitive(a));
65 assertEquals("xyz", %ToPrimitive_Number(a)); 65 assertEquals("xyz", %ToPrimitive_Number(a));
66 assertEquals("xyz", %ToPrimitive_String(a)); 66 assertEquals("xyz", %ToPrimitive_String(a));
67 assertEquals("xyz", %_ToPrimitive(a)); 67 assertEquals("xyz", %_ToPrimitive(a));
68 assertEquals("xyz", %_ToPrimitive_Number(a)); 68 assertEquals("xyz", %_ToPrimitive_Number(a));
69 assertEquals("xyz", %_ToPrimitive_String(a)); 69 assertEquals("xyz", %_ToPrimitive_String(a));
70 assertEquals("xyz", %OrdinaryToPrimitive(a, "number"));
71 assertEquals("xyz", %OrdinaryToPrimitive(a, "string"));
72 assertEquals("xyz", %_OrdinaryToPrimitive(a, "number"));
73 assertEquals("xyz", %_OrdinaryToPrimitive(a, "string"));
74 70
75 var b = { valueOf: function() { return 42 }}; 71 var b = { valueOf: function() { return 42 }};
76 assertEquals(42, %ToPrimitive(b)); 72 assertEquals(42, %ToPrimitive(b));
77 assertEquals(42, %ToPrimitive_Number(b)); 73 assertEquals(42, %ToPrimitive_Number(b));
78 assertEquals("[object Object]", %ToPrimitive_String(b)); 74 assertEquals("[object Object]", %ToPrimitive_String(b));
79 assertEquals(42, %_ToPrimitive(b)); 75 assertEquals(42, %_ToPrimitive(b));
80 assertEquals(42, %_ToPrimitive_Number(b)); 76 assertEquals(42, %_ToPrimitive_Number(b));
81 assertEquals("[object Object]", %_ToPrimitive_String(b)); 77 assertEquals("[object Object]", %_ToPrimitive_String(b));
82 assertEquals(42, %OrdinaryToPrimitive(b, "number"));
83 assertEquals("[object Object]", %OrdinaryToPrimitive(b, "string"));
84 assertEquals(42, %_OrdinaryToPrimitive(b, "number"));
85 assertEquals("[object Object]", %_OrdinaryToPrimitive(b, "string"));
86 78
87 var c = { 79 var c = {
88 toString: function() { return "x"}, 80 toString: function() { return "x"},
89 valueOf: function() { return 123 } 81 valueOf: function() { return 123 }
90 }; 82 };
91 assertEquals(123, %ToPrimitive(c)); 83 assertEquals(123, %ToPrimitive(c));
92 assertEquals(123, %ToPrimitive_Number(c)); 84 assertEquals(123, %ToPrimitive_Number(c));
93 assertEquals("x", %ToPrimitive_String(c)); 85 assertEquals("x", %ToPrimitive_String(c));
94 assertEquals(123, %_ToPrimitive(c)); 86 assertEquals(123, %_ToPrimitive(c));
95 assertEquals(123, %_ToPrimitive_Number(c)); 87 assertEquals(123, %_ToPrimitive_Number(c));
96 assertEquals("x", %_ToPrimitive_String(c)); 88 assertEquals("x", %_ToPrimitive_String(c));
97 assertEquals(123, %OrdinaryToPrimitive(c, "number"));
98 assertEquals("x", %OrdinaryToPrimitive(c, "string"));
99 assertEquals(123, %_OrdinaryToPrimitive(c, "number"));
100 assertEquals("x", %_OrdinaryToPrimitive(c, "string"));
101 89
102 var d = { 90 var d = {
103 [Symbol.toPrimitive]: function(hint) { return hint } 91 [Symbol.toPrimitive]: function(hint) { return hint }
104 }; 92 };
105 assertEquals("default", %ToPrimitive(d)); 93 assertEquals("default", %ToPrimitive(d));
106 assertEquals("number", %ToPrimitive_Number(d)); 94 assertEquals("number", %ToPrimitive_Number(d));
107 assertEquals("string", %ToPrimitive_String(d)); 95 assertEquals("string", %ToPrimitive_String(d));
108 assertEquals("default", %_ToPrimitive(d)); 96 assertEquals("default", %_ToPrimitive(d));
109 assertEquals("number", %_ToPrimitive_Number(d)); 97 assertEquals("number", %_ToPrimitive_Number(d));
110 assertEquals("string", %_ToPrimitive_String(d)); 98 assertEquals("string", %_ToPrimitive_String(d));
99
100 var e = new Date(0);
101 assertEquals(e.toString(), %ToPrimitive(e));
102 assertEquals(0, %ToPrimitive_Number(e));
103 assertEquals(e.toString(), %ToPrimitive_String(e));
104 assertEquals(e.toString(), %_ToPrimitive(e));
105 assertEquals(0, %_ToPrimitive_Number(e));
106 assertEquals(e.toString(), %_ToPrimitive_String(e));
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/to-number.js ('k') | test/mjsunit/harmony/to-string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698