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

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: Some test improvements. 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/harmony/symbols.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 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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --harmony-symbols --harmony-collections 28 // Flags: --harmony-symbols --harmony-collections
29 // Flags: --expose-gc --allow-natives-syntax 29 // Flags: --expose-gc --allow-natives-syntax
30 30
31 var symbols = [] 31 var symbols = []
32 32
33
34 // Returns true if the string is a valid
35 // serialization of Symbols added to the 'symbols'
36 // array. Adjust if you extend 'symbols' with other
37 // values.
38 function isValidSymbolString(s) {
39 return ["Symbol(66)"].indexOf(s) >= 0;
40 }
41
42
33 // Test different forms of constructor calls, all equivalent. 43 // Test different forms of constructor calls, all equivalent.
34 function TestNew() { 44 function TestNew() {
35 for (var i = 0; i < 2; ++i) { 45 for (var i = 0; i < 2; ++i) {
36 for (var j = 0; j < 5; ++j) { 46 for (var j = 0; j < 5; ++j) {
37 symbols.push(%CreatePrivateSymbol("66")) 47 symbols.push(%CreatePrivateSymbol("66"))
38 symbols.push(Object(%CreatePrivateSymbol("66")).valueOf()) 48 symbols.push(Object(%CreatePrivateSymbol("66")).valueOf())
39 } 49 }
40 gc() // Promote existing symbols and then allocate some more. 50 gc() // Promote existing symbols and then allocate some more.
41 } 51 }
42 } 52 }
43 TestNew() 53 TestNew()
44 54
45 55
46 function TestType() { 56 function TestType() {
47 for (var i in symbols) { 57 for (var i in symbols) {
48 assertEquals("symbol", typeof symbols[i]) 58 assertEquals("symbol", typeof symbols[i])
49 assertTrue(typeof symbols[i] === "symbol") 59 assertTrue(typeof symbols[i] === "symbol")
50 assertTrue(%SymbolIsPrivate(symbols[i])) 60 assertTrue(%SymbolIsPrivate(symbols[i]))
51 assertEquals(null, %_ClassOf(symbols[i])) 61 assertEquals(null, %_ClassOf(symbols[i]))
52 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i])))
53 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) 62 assertEquals("Symbol", %_ClassOf(Object(symbols[i])))
54 } 63 }
55 } 64 }
56 TestType() 65 TestType()
57 66
58 67
59 function TestPrototype() { 68 function TestPrototype() {
60 for (var i in symbols) { 69 for (var i in symbols) {
61 assertSame(Symbol.prototype, symbols[i].__proto__) 70 assertSame(Symbol.prototype, symbols[i].__proto__)
62 } 71 }
63 } 72 }
64 TestPrototype() 73 TestPrototype()
65 74
66 75
67 function TestConstructor() { 76 function TestConstructor() {
68 for (var i in symbols) { 77 for (var i in symbols) {
69 assertSame(Symbol, symbols[i].__proto__.constructor) 78 assertSame(Symbol, symbols[i].__proto__.constructor)
79 assertSame(Symbol, Object(symbols[i]).__proto__.constructor)
70 } 80 }
71 } 81 }
72 TestConstructor() 82 TestConstructor()
73 83
74 84
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() { 85 function TestToString() {
85 for (var i in symbols) { 86 for (var i in symbols) {
86 assertThrows(function() { String(symbols[i]) }, TypeError) 87 assertThrows(function() { String(symbols[i]) }, TypeError)
87 assertThrows(function() { symbols[i] + "" }, TypeError) 88 assertThrows(function() { symbols[i] + "" }, TypeError)
88 assertThrows(function() { symbols[i].toString() }, TypeError) 89 assertTrue(isValidSymbolString(symbols[i].toString()))
89 assertThrows(function() { (new Symbol(symbols[i])).toString() }, TypeError) 90 assertTrue(isValidSymbolString(Object(symbols[i]).toString()))
90 assertThrows(function() { Object(symbols[i]).toString() }, TypeError) 91 assertTrue(isValidSymbolString(Symbol.prototype.toString.call(symbols[i])))
91 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i])) 92 assertEquals(
93 "[object Symbol]", Object.prototype.toString.call(symbols[i]))
92 } 94 }
93 } 95 }
94 TestToString() 96 TestToString()
95 97
96 98
97 function TestToBoolean() { 99 function TestToBoolean() {
98 for (var i in symbols) { 100 for (var i in symbols) {
99 assertTrue(Boolean(symbols[i]).valueOf()) 101 assertTrue(Boolean(symbols[i]).valueOf())
100 assertFalse(!symbols[i]) 102 assertFalse(!symbols[i])
101 assertTrue(!!symbols[i]) 103 assertTrue(!!symbols[i])
(...skipping 19 matching lines...) Expand all
121 123
122 124
123 function TestEquality() { 125 function TestEquality() {
124 // Every symbol should equal itself, and non-strictly equal its wrapper. 126 // Every symbol should equal itself, and non-strictly equal its wrapper.
125 for (var i in symbols) { 127 for (var i in symbols) {
126 assertSame(symbols[i], symbols[i]) 128 assertSame(symbols[i], symbols[i])
127 assertEquals(symbols[i], symbols[i]) 129 assertEquals(symbols[i], symbols[i])
128 assertTrue(Object.is(symbols[i], symbols[i])) 130 assertTrue(Object.is(symbols[i], symbols[i]))
129 assertTrue(symbols[i] === symbols[i]) 131 assertTrue(symbols[i] === symbols[i])
130 assertTrue(symbols[i] == symbols[i]) 132 assertTrue(symbols[i] == symbols[i])
131 assertFalse(symbols[i] === new Symbol(symbols[i])) 133 assertFalse(symbols[i] === Object(symbols[i]))
132 assertFalse(new Symbol(symbols[i]) === symbols[i]) 134 assertFalse(Object(symbols[i]) === symbols[i])
133 assertTrue(symbols[i] == new Symbol(symbols[i])) 135 assertFalse(symbols[i] == Object(symbols[i]))
134 assertTrue(new Symbol(symbols[i]) == symbols[i]) 136 assertFalse(Object(symbols[i]) == symbols[i])
137 assertTrue(symbols[i] === symbols[i].valueOf())
138 assertTrue(symbols[i].valueOf() === symbols[i])
139 assertTrue(symbols[i] == symbols[i].valueOf())
140 assertTrue(symbols[i].valueOf() == symbols[i])
135 } 141 }
136 142
137 // All symbols should be distinct. 143 // All symbols should be distinct.
138 for (var i = 0; i < symbols.length; ++i) { 144 for (var i = 0; i < symbols.length; ++i) {
139 for (var j = i + 1; j < symbols.length; ++j) { 145 for (var j = i + 1; j < symbols.length; ++j) {
140 assertFalse(Object.is(symbols[i], symbols[j])) 146 assertFalse(Object.is(symbols[i], symbols[j]))
141 assertFalse(symbols[i] === symbols[j]) 147 assertFalse(symbols[i] === symbols[j])
142 assertFalse(symbols[i] == symbols[j]) 148 assertFalse(symbols[i] == symbols[j])
143 } 149 }
144 } 150 }
145 151
146 // Symbols should not be equal to any other value (and the test terminates). 152 // Symbols should not be equal to any other value (and the test terminates).
147 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}] 153 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}]
148 for (var i in symbols) { 154 for (var i in symbols) {
149 for (var j in values) { 155 for (var j in values) {
150 assertFalse(symbols[i] === values[j]) 156 assertFalse(symbols[i] === values[j])
151 assertFalse(values[j] === symbols[i]) 157 assertFalse(values[j] === symbols[i])
152 assertFalse(symbols[i] == values[j]) 158 assertFalse(symbols[i] == values[j])
153 assertFalse(values[j] == symbols[i]) 159 assertFalse(values[j] == symbols[i])
154 } 160 }
155 } 161 }
156 } 162 }
157 TestEquality() 163 TestEquality()
158 164
159 165
160 function TestGet() { 166 function TestGet() {
161 for (var i in symbols) { 167 for (var i in symbols) {
162 assertThrows(function() { symbols[i].toString() }, TypeError) 168 assertTrue(isValidSymbolString(symbols[i].toString()))
163 assertEquals(symbols[i], symbols[i].valueOf()) 169 assertEquals(symbols[i], symbols[i].valueOf())
164 assertEquals(undefined, symbols[i].a) 170 assertEquals(undefined, symbols[i].a)
165 assertEquals(undefined, symbols[i]["a" + "b"]) 171 assertEquals(undefined, symbols[i]["a" + "b"])
166 assertEquals(undefined, symbols[i]["" + "1"]) 172 assertEquals(undefined, symbols[i]["" + "1"])
167 assertEquals(undefined, symbols[i][62]) 173 assertEquals(undefined, symbols[i][62])
168 } 174 }
169 } 175 }
170 TestGet() 176 TestGet()
171 177
172 178
173 function TestSet() { 179 function TestSet() {
174 for (var i in symbols) { 180 for (var i in symbols) {
175 symbols[i].toString = 0 181 symbols[i].toString = 0
176 assertThrows(function() { symbols[i].toString() }, TypeError) 182 assertTrue(isValidSymbolString(symbols[i].toString()))
177 symbols[i].valueOf = 0 183 symbols[i].valueOf = 0
178 assertEquals(symbols[i], symbols[i].valueOf()) 184 assertEquals(symbols[i], symbols[i].valueOf())
179 symbols[i].a = 0 185 symbols[i].a = 0
180 assertEquals(undefined, symbols[i].a) 186 assertEquals(undefined, symbols[i].a)
181 symbols[i]["a" + "b"] = 0 187 symbols[i]["a" + "b"] = 0
182 assertEquals(undefined, symbols[i]["a" + "b"]) 188 assertEquals(undefined, symbols[i]["a" + "b"])
183 symbols[i][62] = 0 189 symbols[i][62] = 0
184 assertEquals(undefined, symbols[i][62]) 190 assertEquals(undefined, symbols[i][62])
185 } 191 }
186 } 192 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // but not between scavenges. This must also apply for symbol keys. 321 // but not between scavenges. This must also apply for symbol keys.
316 var key = Symbol("key"); 322 var key = Symbol("key");
317 var a = {}; 323 var a = {};
318 a[key] = "abc"; 324 a[key] = "abc";
319 325
320 for (var i = 0; i < 100000; i++) { 326 for (var i = 0; i < 100000; i++) {
321 a[key] += "a"; // Allocations cause a scavenge. 327 a[key] += "a"; // Allocations cause a scavenge.
322 } 328 }
323 } 329 }
324 TestCachedKeyAfterScavenge(); 330 TestCachedKeyAfterScavenge();
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698