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

Side by Side Diff: test/mjsunit/harmony/private.js

Issue 118553003: Upgrade Symbol implementation to match current ES6 behavior. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Allow valueOf()/toString() to be called over Symbol values. Created 6 years, 10 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 TestNew() 43 TestNew()
44 44
45 45
46 function TestType() { 46 function TestType() {
47 for (var i in symbols) { 47 for (var i in symbols) {
48 assertEquals("symbol", typeof symbols[i]) 48 assertEquals("symbol", typeof symbols[i])
49 assertTrue(typeof symbols[i] === "symbol") 49 assertTrue(typeof symbols[i] === "symbol")
50 assertTrue(%SymbolIsPrivate(symbols[i])) 50 assertTrue(%SymbolIsPrivate(symbols[i]))
51 assertEquals(null, %_ClassOf(symbols[i])) 51 assertEquals(null, %_ClassOf(symbols[i]))
52 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i])))
53 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) 52 assertEquals("Symbol", %_ClassOf(Object(symbols[i])))
54 } 53 }
55 } 54 }
56 TestType() 55 TestType()
57 56
58 57
59 function TestPrototype() { 58 function TestPrototype() {
60 for (var i in symbols) { 59 for (var i in symbols) {
61 assertSame(Symbol.prototype, symbols[i].__proto__) 60 assertSame(Symbol.prototype, symbols[i].__proto__)
62 } 61 }
63 } 62 }
64 TestPrototype() 63 TestPrototype()
65 64
66 65
67 function TestConstructor() { 66 function TestConstructor() {
68 for (var i in symbols) { 67 for (var i in symbols) {
69 assertSame(Symbol, symbols[i].__proto__.constructor) 68 assertSame(Symbol, symbols[i].__proto__.constructor)
69 assertSame(Symbol, Object(symbols[i]).__proto__.constructor)
70 } 70 }
71 } 71 }
72 TestConstructor() 72 TestConstructor()
73 73
74 74
75 function TestName() {
76 for (var i in symbols) {
77 var name = symbols[i].name
78 assertTrue(name === "66")
79 }
80 }
81 TestName()
82
83
84 function TestToString() { 75 function TestToString() {
85 for (var i in symbols) { 76 for (var i in symbols) {
86 assertThrows(function() { String(symbols[i]) }, TypeError) 77 assertThrows(function() { String(symbols[i]) }, TypeError)
87 assertThrows(function() { symbols[i] + "" }, TypeError) 78 assertThrows(function() { symbols[i] + "" }, TypeError)
88 assertThrows(function() { symbols[i].toString() }, TypeError) 79 assertDoesNotThrow(function() { symbols[i].toString() })
rossberg 2014/02/14 10:55:30 We should check the actual results here, not just
sof 2014/02/14 14:20:02 Done, carrying over the predicate from symbols.js
89 assertThrows(function() { (new Symbol(symbols[i])).toString() }, TypeError) 80 assertDoesNotThrow(function() { Object(symbols[i]).toString() })
90 assertThrows(function() { Object(symbols[i]).toString() }, TypeError) 81 assertDoesNotThrow(function() { Symbol.prototype.toString.call(symbols[i]) } )
rossberg 2014/02/14 10:55:30 Nit: line length
91 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i])) 82 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i]))
92 } 83 }
93 } 84 }
94 TestToString() 85 TestToString()
95 86
96 87
97 function TestToBoolean() { 88 function TestToBoolean() {
98 for (var i in symbols) { 89 for (var i in symbols) {
99 assertTrue(Boolean(symbols[i]).valueOf()) 90 assertTrue(Boolean(symbols[i]).valueOf())
100 assertFalse(!symbols[i]) 91 assertFalse(!symbols[i])
(...skipping 20 matching lines...) Expand all
121 112
122 113
123 function TestEquality() { 114 function TestEquality() {
124 // Every symbol should equal itself, and non-strictly equal its wrapper. 115 // Every symbol should equal itself, and non-strictly equal its wrapper.
125 for (var i in symbols) { 116 for (var i in symbols) {
126 assertSame(symbols[i], symbols[i]) 117 assertSame(symbols[i], symbols[i])
127 assertEquals(symbols[i], symbols[i]) 118 assertEquals(symbols[i], symbols[i])
128 assertTrue(Object.is(symbols[i], symbols[i])) 119 assertTrue(Object.is(symbols[i], symbols[i]))
129 assertTrue(symbols[i] === symbols[i]) 120 assertTrue(symbols[i] === symbols[i])
130 assertTrue(symbols[i] == symbols[i]) 121 assertTrue(symbols[i] == symbols[i])
131 assertFalse(symbols[i] === new Symbol(symbols[i])) 122 assertTrue(symbols[i] === symbols[i].valueOf())
rossberg 2014/02/14 10:55:30 We should keep the equivalent of the previous test
sof 2014/02/14 14:20:02 Done.
132 assertFalse(new Symbol(symbols[i]) === symbols[i]) 123 assertTrue(symbols[i].valueOf() === symbols[i])
133 assertTrue(symbols[i] == new Symbol(symbols[i])) 124 assertTrue(symbols[i] == symbols[i].valueOf())
134 assertTrue(new Symbol(symbols[i]) == symbols[i]) 125 assertTrue(symbols[i].valueOf() == symbols[i])
135 } 126 }
136 127
137 // All symbols should be distinct. 128 // All symbols should be distinct.
138 for (var i = 0; i < symbols.length; ++i) { 129 for (var i = 0; i < symbols.length; ++i) {
139 for (var j = i + 1; j < symbols.length; ++j) { 130 for (var j = i + 1; j < symbols.length; ++j) {
140 assertFalse(Object.is(symbols[i], symbols[j])) 131 assertFalse(Object.is(symbols[i], symbols[j]))
141 assertFalse(symbols[i] === symbols[j]) 132 assertFalse(symbols[i] === symbols[j])
142 assertFalse(symbols[i] == symbols[j]) 133 assertFalse(symbols[i] == symbols[j])
143 } 134 }
144 } 135 }
145 136
146 // Symbols should not be equal to any other value (and the test terminates). 137 // Symbols should not be equal to any other value (and the test terminates).
147 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}] 138 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}]
148 for (var i in symbols) { 139 for (var i in symbols) {
149 for (var j in values) { 140 for (var j in values) {
150 assertFalse(symbols[i] === values[j]) 141 assertFalse(symbols[i] === values[j])
151 assertFalse(values[j] === symbols[i]) 142 assertFalse(values[j] === symbols[i])
152 assertFalse(symbols[i] == values[j]) 143 assertFalse(symbols[i] == values[j])
153 assertFalse(values[j] == symbols[i]) 144 assertFalse(values[j] == symbols[i])
154 } 145 }
155 } 146 }
156 } 147 }
157 TestEquality() 148 TestEquality()
158 149
159 150
160 function TestGet() { 151 function TestGet() {
161 for (var i in symbols) { 152 for (var i in symbols) {
162 assertThrows(function() { symbols[i].toString() }, TypeError) 153 assertDoesNotThrow(function() { symbols[i].toString() })
rossberg 2014/02/14 10:55:30 Check result.
sof 2014/02/14 14:20:02 Done.
163 assertEquals(symbols[i], symbols[i].valueOf()) 154 assertEquals(symbols[i], symbols[i].valueOf())
164 assertEquals(undefined, symbols[i].a) 155 assertEquals(undefined, symbols[i].a)
165 assertEquals(undefined, symbols[i]["a" + "b"]) 156 assertEquals(undefined, symbols[i]["a" + "b"])
166 assertEquals(undefined, symbols[i]["" + "1"]) 157 assertEquals(undefined, symbols[i]["" + "1"])
167 assertEquals(undefined, symbols[i][62]) 158 assertEquals(undefined, symbols[i][62])
168 } 159 }
169 } 160 }
170 TestGet() 161 TestGet()
171 162
172 163
173 function TestSet() { 164 function TestSet() {
174 for (var i in symbols) { 165 for (var i in symbols) {
175 symbols[i].toString = 0 166 symbols[i].toString = 0
176 assertThrows(function() { symbols[i].toString() }, TypeError) 167 assertDoesNotThrow(function() { symbols[i].toString() })
rossberg 2014/02/14 10:55:30 Check result.
sof 2014/02/14 14:20:02 Done.
177 symbols[i].valueOf = 0 168 symbols[i].valueOf = 0
178 assertEquals(symbols[i], symbols[i].valueOf()) 169 assertEquals(symbols[i], symbols[i].valueOf())
179 symbols[i].a = 0 170 symbols[i].a = 0
180 assertEquals(undefined, symbols[i].a) 171 assertEquals(undefined, symbols[i].a)
181 symbols[i]["a" + "b"] = 0 172 symbols[i]["a" + "b"] = 0
182 assertEquals(undefined, symbols[i]["a" + "b"]) 173 assertEquals(undefined, symbols[i]["a" + "b"])
183 symbols[i][62] = 0 174 symbols[i][62] = 0
184 assertEquals(undefined, symbols[i][62]) 175 assertEquals(undefined, symbols[i][62])
185 } 176 }
186 } 177 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // but not between scavenges. This must also apply for symbol keys. 306 // but not between scavenges. This must also apply for symbol keys.
316 var key = Symbol("key"); 307 var key = Symbol("key");
317 var a = {}; 308 var a = {};
318 a[key] = "abc"; 309 a[key] = "abc";
319 310
320 for (var i = 0; i < 100000; i++) { 311 for (var i = 0; i < 100000; i++) {
321 a[key] += "a"; // Allocations cause a scavenge. 312 a[key] += "a"; // Allocations cause a scavenge.
322 } 313 }
323 } 314 }
324 TestCachedKeyAfterScavenge(); 315 TestCachedKeyAfterScavenge();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698