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

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

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/harmony/microtask-delivery.js ('k') | test/mjsunit/harmony/proxies.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
43 // Test different forms of constructor calls, all equivalent. 33 // Test different forms of constructor calls, all equivalent.
44 function TestNew() { 34 function TestNew() {
45 for (var i = 0; i < 2; ++i) { 35 for (var i = 0; i < 2; ++i) {
46 for (var j = 0; j < 5; ++j) { 36 for (var j = 0; j < 5; ++j) {
47 symbols.push(%CreatePrivateSymbol("66")) 37 symbols.push(%CreatePrivateSymbol("66"))
48 symbols.push(Object(%CreatePrivateSymbol("66")).valueOf()) 38 symbols.push(Object(%CreatePrivateSymbol("66")).valueOf())
49 } 39 }
50 gc() // Promote existing symbols and then allocate some more. 40 gc() // Promote existing symbols and then allocate some more.
51 } 41 }
52 } 42 }
53 TestNew() 43 TestNew()
54 44
55 45
56 function TestType() { 46 function TestType() {
57 for (var i in symbols) { 47 for (var i in symbols) {
58 assertEquals("symbol", typeof symbols[i]) 48 assertEquals("symbol", typeof symbols[i])
59 assertTrue(typeof symbols[i] === "symbol") 49 assertTrue(typeof symbols[i] === "symbol")
60 assertTrue(%SymbolIsPrivate(symbols[i])) 50 assertTrue(%SymbolIsPrivate(symbols[i]))
61 assertEquals(null, %_ClassOf(symbols[i])) 51 assertEquals(null, %_ClassOf(symbols[i]))
52 assertEquals("Symbol", %_ClassOf(new Symbol(symbols[i])))
62 assertEquals("Symbol", %_ClassOf(Object(symbols[i]))) 53 assertEquals("Symbol", %_ClassOf(Object(symbols[i])))
63 } 54 }
64 } 55 }
65 TestType() 56 TestType()
66 57
67 58
68 function TestPrototype() { 59 function TestPrototype() {
69 for (var i in symbols) { 60 for (var i in symbols) {
70 assertSame(Symbol.prototype, symbols[i].__proto__) 61 assertSame(Symbol.prototype, symbols[i].__proto__)
71 } 62 }
72 } 63 }
73 TestPrototype() 64 TestPrototype()
74 65
75 66
76 function TestConstructor() { 67 function TestConstructor() {
77 for (var i in symbols) { 68 for (var i in symbols) {
78 assertSame(Symbol, symbols[i].__proto__.constructor) 69 assertSame(Symbol, symbols[i].__proto__.constructor)
79 assertSame(Symbol, Object(symbols[i]).__proto__.constructor)
80 } 70 }
81 } 71 }
82 TestConstructor() 72 TestConstructor()
83 73
84 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
85 function TestToString() { 84 function TestToString() {
86 for (var i in symbols) { 85 for (var i in symbols) {
87 assertThrows(function() { String(symbols[i]) }, TypeError) 86 assertThrows(function() { String(symbols[i]) }, TypeError)
88 assertThrows(function() { symbols[i] + "" }, TypeError) 87 assertThrows(function() { symbols[i] + "" }, TypeError)
89 assertTrue(isValidSymbolString(symbols[i].toString())) 88 assertThrows(function() { symbols[i].toString() }, TypeError)
90 assertTrue(isValidSymbolString(Object(symbols[i]).toString())) 89 assertThrows(function() { (new Symbol(symbols[i])).toString() }, TypeError)
91 assertTrue(isValidSymbolString(Symbol.prototype.toString.call(symbols[i]))) 90 assertThrows(function() { Object(symbols[i]).toString() }, TypeError)
92 assertEquals( 91 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i]))
93 "[object Symbol]", Object.prototype.toString.call(symbols[i]))
94 } 92 }
95 } 93 }
96 TestToString() 94 TestToString()
97 95
98 96
99 function TestToBoolean() { 97 function TestToBoolean() {
100 for (var i in symbols) { 98 for (var i in symbols) {
101 assertTrue(Boolean(symbols[i]).valueOf()) 99 assertTrue(Boolean(symbols[i]).valueOf())
102 assertFalse(!symbols[i]) 100 assertFalse(!symbols[i])
103 assertTrue(!!symbols[i]) 101 assertTrue(!!symbols[i])
(...skipping 19 matching lines...) Expand all
123 121
124 122
125 function TestEquality() { 123 function TestEquality() {
126 // Every symbol should equal itself, and non-strictly equal its wrapper. 124 // Every symbol should equal itself, and non-strictly equal its wrapper.
127 for (var i in symbols) { 125 for (var i in symbols) {
128 assertSame(symbols[i], symbols[i]) 126 assertSame(symbols[i], symbols[i])
129 assertEquals(symbols[i], symbols[i]) 127 assertEquals(symbols[i], symbols[i])
130 assertTrue(Object.is(symbols[i], symbols[i])) 128 assertTrue(Object.is(symbols[i], symbols[i]))
131 assertTrue(symbols[i] === symbols[i]) 129 assertTrue(symbols[i] === symbols[i])
132 assertTrue(symbols[i] == symbols[i]) 130 assertTrue(symbols[i] == symbols[i])
133 assertFalse(symbols[i] === Object(symbols[i])) 131 assertFalse(symbols[i] === new Symbol(symbols[i]))
134 assertFalse(Object(symbols[i]) === symbols[i]) 132 assertFalse(new Symbol(symbols[i]) === symbols[i])
135 assertFalse(symbols[i] == Object(symbols[i])) 133 assertTrue(symbols[i] == new Symbol(symbols[i]))
136 assertFalse(Object(symbols[i]) == symbols[i]) 134 assertTrue(new Symbol(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])
141 } 135 }
142 136
143 // All symbols should be distinct. 137 // All symbols should be distinct.
144 for (var i = 0; i < symbols.length; ++i) { 138 for (var i = 0; i < symbols.length; ++i) {
145 for (var j = i + 1; j < symbols.length; ++j) { 139 for (var j = i + 1; j < symbols.length; ++j) {
146 assertFalse(Object.is(symbols[i], symbols[j])) 140 assertFalse(Object.is(symbols[i], symbols[j]))
147 assertFalse(symbols[i] === symbols[j]) 141 assertFalse(symbols[i] === symbols[j])
148 assertFalse(symbols[i] == symbols[j]) 142 assertFalse(symbols[i] == symbols[j])
149 } 143 }
150 } 144 }
151 145
152 // Symbols should not be equal to any other value (and the test terminates). 146 // Symbols should not be equal to any other value (and the test terminates).
153 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}] 147 var values = [347, 1.275, NaN, "string", null, undefined, {}, function() {}]
154 for (var i in symbols) { 148 for (var i in symbols) {
155 for (var j in values) { 149 for (var j in values) {
156 assertFalse(symbols[i] === values[j]) 150 assertFalse(symbols[i] === values[j])
157 assertFalse(values[j] === symbols[i]) 151 assertFalse(values[j] === symbols[i])
158 assertFalse(symbols[i] == values[j]) 152 assertFalse(symbols[i] == values[j])
159 assertFalse(values[j] == symbols[i]) 153 assertFalse(values[j] == symbols[i])
160 } 154 }
161 } 155 }
162 } 156 }
163 TestEquality() 157 TestEquality()
164 158
165 159
166 function TestGet() { 160 function TestGet() {
167 for (var i in symbols) { 161 for (var i in symbols) {
168 assertTrue(isValidSymbolString(symbols[i].toString())) 162 assertThrows(function() { symbols[i].toString() }, TypeError)
169 assertEquals(symbols[i], symbols[i].valueOf()) 163 assertEquals(symbols[i], symbols[i].valueOf())
170 assertEquals(undefined, symbols[i].a) 164 assertEquals(undefined, symbols[i].a)
171 assertEquals(undefined, symbols[i]["a" + "b"]) 165 assertEquals(undefined, symbols[i]["a" + "b"])
172 assertEquals(undefined, symbols[i]["" + "1"]) 166 assertEquals(undefined, symbols[i]["" + "1"])
173 assertEquals(undefined, symbols[i][62]) 167 assertEquals(undefined, symbols[i][62])
174 } 168 }
175 } 169 }
176 TestGet() 170 TestGet()
177 171
178 172
179 function TestSet() { 173 function TestSet() {
180 for (var i in symbols) { 174 for (var i in symbols) {
181 symbols[i].toString = 0 175 symbols[i].toString = 0
182 assertTrue(isValidSymbolString(symbols[i].toString())) 176 assertThrows(function() { symbols[i].toString() }, TypeError)
183 symbols[i].valueOf = 0 177 symbols[i].valueOf = 0
184 assertEquals(symbols[i], symbols[i].valueOf()) 178 assertEquals(symbols[i], symbols[i].valueOf())
185 symbols[i].a = 0 179 symbols[i].a = 0
186 assertEquals(undefined, symbols[i].a) 180 assertEquals(undefined, symbols[i].a)
187 symbols[i]["a" + "b"] = 0 181 symbols[i]["a" + "b"] = 0
188 assertEquals(undefined, symbols[i]["a" + "b"]) 182 assertEquals(undefined, symbols[i]["a" + "b"])
189 symbols[i][62] = 0 183 symbols[i][62] = 0
190 assertEquals(undefined, symbols[i][62]) 184 assertEquals(undefined, symbols[i][62])
191 } 185 }
192 } 186 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // but not between scavenges. This must also apply for symbol keys. 315 // but not between scavenges. This must also apply for symbol keys.
322 var key = Symbol("key"); 316 var key = Symbol("key");
323 var a = {}; 317 var a = {};
324 a[key] = "abc"; 318 a[key] = "abc";
325 319
326 for (var i = 0; i < 100000; i++) { 320 for (var i = 0; i < 100000; i++) {
327 a[key] += "a"; // Allocations cause a scavenge. 321 a[key] += "a"; // Allocations cause a scavenge.
328 } 322 }
329 } 323 }
330 TestCachedKeyAfterScavenge(); 324 TestCachedKeyAfterScavenge();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/microtask-delivery.js ('k') | test/mjsunit/harmony/proxies.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698