OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 symbols[i]["a" + "b"] = 0 | 102 symbols[i]["a" + "b"] = 0 |
103 assertEquals(undefined, symbols[i]["a" + "b"]) | 103 assertEquals(undefined, symbols[i]["a" + "b"]) |
104 symbols[i][62] = 0 | 104 symbols[i][62] = 0 |
105 assertEquals(undefined, symbols[i][62]) | 105 assertEquals(undefined, symbols[i][62]) |
106 } | 106 } |
107 } | 107 } |
108 TestSet() | 108 TestSet() |
109 | 109 |
110 | 110 |
111 function TestMap() { | 111 function TestMap() { |
112 var map = new Map; | 112 var map = new Map |
113 for (var i in symbols) { | 113 for (var i in symbols) { |
114 map.set(symbols[i], i) | 114 map.set(symbols[i], i) |
115 } | 115 } |
116 for (var i in symbols) { | 116 for (var i in symbols) { |
| 117 assertTrue(map.has(symbols[i])) |
117 assertEquals(i, map.get(symbols[i])) | 118 assertEquals(i, map.get(symbols[i])) |
118 } | 119 } |
119 } | 120 } |
120 TestMap() | 121 TestMap() |
| 122 |
| 123 |
| 124 |
| 125 function TestKeySet(obj) { |
| 126 // Set the even symbols via assignment. |
| 127 for (var i = 0; i < symbols.length; i += 2) { |
| 128 obj[symbols[i]] = i |
| 129 } |
| 130 } |
| 131 |
| 132 |
| 133 function TestKeyDefine(obj) { |
| 134 // Set the odd symbols via defineProperty (as non-enumerable). |
| 135 for (var i = 1; i < symbols.length; i += 2) { |
| 136 Object.defineProperty(obj, symbols[i], {value: i, configurable: true}) |
| 137 } |
| 138 } |
| 139 |
| 140 |
| 141 function TestKeyGet(obj) { |
| 142 var obj2 = Object.create(obj) |
| 143 for (var i in symbols) { |
| 144 assertEquals(i|0, obj[symbols[i]]) |
| 145 assertEquals(i|0, obj2[symbols[i]]) |
| 146 } |
| 147 } |
| 148 |
| 149 |
| 150 function TestKeyHas() { |
| 151 for (var i in symbols) { |
| 152 assertTrue(symbols[i] in obj) |
| 153 assertTrue(Object.hasOwnProperty.call(obj, symbols[i])) |
| 154 } |
| 155 } |
| 156 |
| 157 |
| 158 function TestKeyEnum(obj) { |
| 159 // TODO(rossberg): symbols should not show up at all in for-in. |
| 160 var found = []; |
| 161 names: for (var name in obj) { |
| 162 for (var i in symbols) { |
| 163 if (name === symbols[i]) { |
| 164 found[i] = true; |
| 165 continue names; |
| 166 } |
| 167 } |
| 168 } |
| 169 // All even symbols should have been enumerated. |
| 170 for (var i = 0; i < symbols.length; i += 2) { |
| 171 assertTrue(i in found) |
| 172 } |
| 173 } |
| 174 |
| 175 |
| 176 function TestKeyKeys(obj) { |
| 177 // TODO(rossberg): symbols should not be returned by Object.keys. |
| 178 assertEquals(symbols.length / 2, Object.keys(obj).length) |
| 179 assertTrue(symbols.length <= Object.getOwnPropertyNames(obj).length) |
| 180 } |
| 181 |
| 182 |
| 183 function TestKeyDescriptor(obj) { |
| 184 for (var i in symbols) { |
| 185 var desc = Object.getOwnPropertyDescriptor(obj, symbols[i]); |
| 186 assertEquals(i|0, desc.value) |
| 187 assertTrue(desc.configurable) |
| 188 assertEquals(i % 2 == 0, desc.writable) |
| 189 assertEquals(i % 2 == 0, desc.enumerable) |
| 190 assertEquals(i % 2 == 0, |
| 191 Object.prototype.propertyIsEnumerable.call(obj, symbols[i])) |
| 192 } |
| 193 } |
| 194 |
| 195 |
| 196 function TestKeyDelete(obj) { |
| 197 for (var i in symbols) { |
| 198 delete obj[symbols[i]] |
| 199 } |
| 200 for (var i in symbols) { |
| 201 assertEquals(undefined, Object.getOwnPropertyDescriptor(obj, symbols[i])) |
| 202 } |
| 203 } |
| 204 |
| 205 |
| 206 var objs = [{}, [], Object.create(null), Object(1), new Map, function(){}] |
| 207 |
| 208 for (var i in objs) { |
| 209 var obj = objs[i] |
| 210 TestKeySet(obj) |
| 211 TestKeyDefine(obj) |
| 212 TestKeyGet(obj) |
| 213 TestKeyHas(obj) |
| 214 TestKeyEnum(obj) |
| 215 TestKeyKeys(obj) |
| 216 TestKeyDescriptor(obj) |
| 217 TestKeyDelete(obj) |
| 218 } |
OLD | NEW |