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

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

Issue 12296026: ES6 symbols: Implement Symbol intrinsic and basic functionality (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed more comments Created 7 years, 9 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 | « src/x64/stub-cache-x64.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 // Flags: --harmony-symbols --harmony-collections
29 // Flags: --expose-gc --allow-natives-syntax
30
31 var symbols = []
32
33 // Test different forms of constructor calls, all equivalent.
34 function TestNew() {
35 function IndirectSymbol() { return new Symbol }
36 function indirect() { return new IndirectSymbol() }
37 for (var i = 0; i < 10; ++i) {
38 symbols.push(new Symbol)
39 symbols.push(new Symbol())
40 symbols.push(Symbol())
41 symbols.push(indirect())
42 }
43 %OptimizeFunctionOnNextCall(indirect)
44 indirect() // Call once before GC throws away type feedback.
45 gc() // Promote existing symbols and then allocate some more.
46 for (var i = 0; i < 10; ++i) {
47 symbols.push(new Symbol)
48 symbols.push(new Symbol())
49 symbols.push(Symbol())
50 symbols.push(indirect())
51 }
52 }
53 TestNew()
54
55
56 function TestType() {
57 for (var i in symbols) {
58 assertTrue(%_IsSymbol(symbols[i]))
59 assertEquals("object", typeof symbols[i])
60 assertTrue(typeof symbols[i] === "object")
61 assertEquals("[object Symbol]", Object.prototype.toString.call(symbols[i]))
62 }
63 }
64 TestType()
65
66
67 function TestEquality() {
68 // Every symbol should equal itself.
69 for (var i in symbols) {
70 assertSame(symbols[i], symbols[i])
71 assertEquals(symbols[i], symbols[i])
72 assertTrue(Object.is(symbols[i], symbols[i]))
73 assertTrue(symbols[i] === symbols[i])
74 assertTrue(symbols[i] == symbols[i])
75 }
76
77 // All symbols should be distinct.
78 for (var i = 0; i < symbols.length; ++i) {
79 for (var j = i + 1; j < symbols.length; ++j) {
80 assertFalse(Object.is(symbols[i], symbols[j]))
81 assertFalse(symbols[i] === symbols[j])
82 assertFalse(symbols[i] == symbols[j])
83 }
84 }
85 }
86 TestEquality()
87
88
89 function TestGet() {
90 for (var i in symbols) {
91 assertEquals("[object Symbol]", symbols[i].toString())
92 assertEquals(undefined, symbols[i].valueOf)
93 assertEquals(undefined, symbols[i].a)
94 assertEquals(undefined, symbols[i]["a" + "b"])
95 assertEquals(undefined, symbols[i]["" + "1"])
96 assertEquals(undefined, symbols[i][62])
97 }
98 }
99 TestGet()
100
101
102 function TestSet() {
103 for (var i in symbols) {
104 symbols[i].toString = 0
105 assertEquals("[object Symbol]", symbols[i].toString())
106 symbols[i].a = 0
107 assertEquals(undefined, symbols[i].a)
108 symbols[i]["a" + "b"] = 0
109 assertEquals(undefined, symbols[i]["a" + "b"])
110 symbols[i][62] = 0
111 assertEquals(undefined, symbols[i][62])
112 }
113 }
114 TestSet()
115
116
117 function TestMap() {
118 var map = new Map;
119 for (var i in symbols) {
120 map.set(symbols[i], i)
121 }
122 for (var i in symbols) {
123 assertTrue(map.has(symbols[i]))
124 assertEquals(i, map.get(symbols[i]))
125 }
126 }
127 TestMap()
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698