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

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: Created 6 years, 11 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 24 matching lines...) Expand all
35 for (var i = 0; i < 2; ++i) { 35 for (var i = 0; i < 2; ++i) {
36 for (var j = 0; j < 5; ++j) { 36 for (var j = 0; j < 5; ++j) {
37 symbols.push(%CreatePrivateSymbol("66")) 37 symbols.push(%CreatePrivateSymbol("66"))
38 symbols.push(Object(%CreatePrivateSymbol("66")).valueOf()) 38 symbols.push(Object(%CreatePrivateSymbol("66")).valueOf())
39 } 39 }
40 gc() // Promote existing symbols and then allocate some more. 40 gc() // Promote existing symbols and then allocate some more.
41 } 41 }
42 } 42 }
43 TestNew() 43 TestNew()
44 44
45
46 function TestType() { 45 function TestType() {
47 for (var i in symbols) { 46 for (var i in symbols) {
48 assertEquals("symbol", typeof symbols[i]) 47 assertEquals("symbol", typeof symbols[i])
49 assertTrue(typeof symbols[i] === "symbol") 48 assertTrue(typeof symbols[i] === "symbol")
50 assertTrue(%SymbolIsPrivate(symbols[i])) 49 assertTrue(%SymbolIsPrivate(symbols[i]))
51 assertEquals(null, %_ClassOf(symbols[i])) 50 assertEquals(null, %_ClassOf(symbols[i]))
52 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i])))
53 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) 51 assertEquals("Symbol", %_ClassOf(Object(symbols[i])))
54 } 52 }
55 } 53 }
56 TestType() 54 TestType()
57 55
58 56
59 function TestPrototype() { 57 function TestPrototype() {
60 for (var i in symbols) { 58 for (var i in symbols) {
61 assertSame(Symbol.prototype, symbols[i].__proto__) 59 assertSame(Symbol.prototype, symbols[i].__proto__)
62 } 60 }
63 } 61 }
64 TestPrototype() 62 TestPrototype()
65 63
66 64
67 function TestConstructor() { 65 function TestConstructor() {
68 for (var i in symbols) { 66 for (var i in symbols) {
69 assertSame(Symbol, symbols[i].__proto__.constructor) 67 assertSame(Function, symbols[i].__proto__.constructor)
68 assertSame(Symbol, Object(symbols[i]).__proto__.constructor)
70 } 69 }
71 } 70 }
72 TestConstructor() 71 TestConstructor()
73 72
74 73
75 function TestName() { 74 function TestValueOf() {
76 for (var i in symbols) { 75 for (var i in symbols) {
77 var name = symbols[i].name 76 var value = Object(symbols[i]).valueOf()
78 assertTrue(name === "66") 77 assertTrue(value === symbols[i])
79 } 78 }
80 } 79 }
81 TestName() 80 TestValueOf()
82 81
83 82
84 function TestToString() { 83 function TestToString() {
85 for (var i in symbols) { 84 for (var i in symbols) {
86 assertThrows(function() { String(symbols[i]) }, TypeError) 85 assertThrows(function() { String(symbols[i]) }, TypeError)
87 assertThrows(function() { symbols[i] + "" }, TypeError) 86 assertThrows(function() { symbols[i] + "" }, TypeError)
88 assertThrows(function() { symbols[i].toString() }, TypeError) 87 assertThrows(function() { symbols[i].toString() }, TypeError)
89 assertThrows(function() { (new Symbol(symbols[i])).toString() }, TypeError) 88 assertThrows(function() { (Symbol(symbols[i])).toString() }, TypeError)
90 assertThrows(function() { Object(symbols[i]).toString() }, TypeError) 89 assertDoesNotThrow(function() { Object(symbols[i]).toString() })
91 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i])) 90 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i]))
92 } 91 }
93 } 92 }
94 TestToString() 93 TestToString()
95 94
96 95
97 function TestToBoolean() { 96 function TestToBoolean() {
98 for (var i in symbols) { 97 for (var i in symbols) {
99 assertTrue(Boolean(symbols[i]).valueOf()) 98 assertTrue(Boolean(symbols[i]).valueOf())
100 assertFalse(!symbols[i]) 99 assertFalse(!symbols[i])
(...skipping 20 matching lines...) Expand all
121 120
122 121
123 function TestEquality() { 122 function TestEquality() {
124 // Every symbol should equal itself, and non-strictly equal its wrapper. 123 // Every symbol should equal itself, and non-strictly equal its wrapper.
125 for (var i in symbols) { 124 for (var i in symbols) {
126 assertSame(symbols[i], symbols[i]) 125 assertSame(symbols[i], symbols[i])
127 assertEquals(symbols[i], symbols[i]) 126 assertEquals(symbols[i], symbols[i])
128 assertTrue(Object.is(symbols[i], symbols[i])) 127 assertTrue(Object.is(symbols[i], symbols[i]))
129 assertTrue(symbols[i] === symbols[i]) 128 assertTrue(symbols[i] === symbols[i])
130 assertTrue(symbols[i] == symbols[i]) 129 assertTrue(symbols[i] == symbols[i])
131 assertFalse(symbols[i] === new Symbol(symbols[i])) 130 assertTrue(symbols[i] === (Object(symbols[i])).valueOf())
132 assertFalse(new Symbol(symbols[i]) === symbols[i]) 131 assertTrue((Object(symbols[i])).valueOf() === symbols[i])
133 assertTrue(symbols[i] == new Symbol(symbols[i])) 132 assertTrue(symbols[i] == (Object(symbols[i])).valueOf())
134 assertTrue(new Symbol(symbols[i]) == symbols[i]) 133 assertTrue((Object(symbols[i])).valueOf() == symbols[i])
135 } 134 }
136 135
137 // All symbols should be distinct. 136 // All symbols should be distinct.
138 for (var i = 0; i < symbols.length; ++i) { 137 for (var i = 0; i < symbols.length; ++i) {
139 for (var j = i + 1; j < symbols.length; ++j) { 138 for (var j = i + 1; j < symbols.length; ++j) {
140 assertFalse(Object.is(symbols[i], symbols[j])) 139 assertFalse(Object.is(symbols[i], symbols[j]))
141 assertFalse(symbols[i] === symbols[j]) 140 assertFalse(symbols[i] === symbols[j])
142 assertFalse(symbols[i] == symbols[j]) 141 assertFalse(symbols[i] == symbols[j])
143 } 142 }
144 } 143 }
145 144
146 // Symbols should not be equal to any other value (and the test terminates). 145 // Symbols should not be equal to any other value (and the test terminates).
147 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}] 146 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}]
148 for (var i in symbols) { 147 for (var i in symbols) {
149 for (var j in values) { 148 for (var j in values) {
150 assertFalse(symbols[i] === values[j]) 149 assertFalse(symbols[i] === values[j])
151 assertFalse(values[j] === symbols[i]) 150 assertFalse(values[j] === symbols[i])
152 assertFalse(symbols[i] == values[j]) 151 assertFalse(symbols[i] == values[j])
153 assertFalse(values[j] == symbols[i]) 152 assertFalse(values[j] == symbols[i])
154 } 153 }
155 } 154 }
156 } 155 }
157 TestEquality() 156 TestEquality()
158 157
159 158
160 function TestGet() { 159 function TestGet() {
161 for (var i in symbols) { 160 for (var i in symbols) {
162 assertThrows(function() { symbols[i].toString() }, TypeError) 161 assertThrows(function() { symbols[i].toString() }, TypeError)
163 assertEquals(symbols[i], symbols[i].valueOf()) 162 assertEquals(symbols[i], Object(symbols[i]).valueOf())
164 assertEquals(undefined, symbols[i].a) 163 assertEquals(undefined, symbols[i].a)
165 assertEquals(undefined, symbols[i]["a" + "b"]) 164 assertEquals(undefined, symbols[i]["a" + "b"])
166 assertEquals(undefined, symbols[i]["" + "1"]) 165 assertEquals(undefined, symbols[i]["" + "1"])
167 assertEquals(undefined, symbols[i][62]) 166 assertEquals(undefined, symbols[i][62])
168 } 167 }
169 } 168 }
170 TestGet() 169 TestGet()
171 170
172 171
173 function TestSet() { 172 function TestSet() {
174 for (var i in symbols) { 173 for (var i in symbols) {
175 symbols[i].toString = 0 174 symbols[i].toString = 0
176 assertThrows(function() { symbols[i].toString() }, TypeError) 175 assertThrows(function() { symbols[i].toString() }, TypeError)
177 symbols[i].valueOf = 0 176 symbols[i].valueOf = 0
178 assertEquals(symbols[i], symbols[i].valueOf()) 177 assertEquals(symbols[i], Object(symbols[i]).valueOf())
179 symbols[i].a = 0 178 symbols[i].a = 0
180 assertEquals(undefined, symbols[i].a) 179 assertEquals(undefined, symbols[i].a)
181 symbols[i]["a" + "b"] = 0 180 symbols[i]["a" + "b"] = 0
182 assertEquals(undefined, symbols[i]["a" + "b"]) 181 assertEquals(undefined, symbols[i]["a" + "b"])
183 symbols[i][62] = 0 182 symbols[i][62] = 0
184 assertEquals(undefined, symbols[i][62]) 183 assertEquals(undefined, symbols[i][62])
185 } 184 }
186 } 185 }
187 TestSet() 186 TestSet()
188 187
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // but not between scavenges. This must also apply for symbol keys. 314 // but not between scavenges. This must also apply for symbol keys.
316 var key = Symbol("key"); 315 var key = Symbol("key");
317 var a = {}; 316 var a = {};
318 a[key] = "abc"; 317 a[key] = "abc";
319 318
320 for (var i = 0; i < 100000; i++) { 319 for (var i = 0; i < 100000; i++) {
321 a[key] += "a"; // Allocations cause a scavenge. 320 a[key] += "a"; // Allocations cause a scavenge.
322 } 321 }
323 } 322 }
324 TestCachedKeyAfterScavenge(); 323 TestCachedKeyAfterScavenge();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698