OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-object-values-entries --harmony-proxies --harmony-reflect | 5 // Flags: --harmony-object-values-entries --harmony-proxies --harmony-reflect |
6 // Flags: --allow-natives-syntax | 6 // Flags: --allow-natives-syntax |
7 | 7 |
8 function TestMeta() { | 8 function TestMeta() { |
9 assertEquals(1, Object.entries.length); | 9 assertEquals(1, Object.entries.length); |
10 assertEquals(Function.prototype, Object.getPrototypeOf(Object.entries)); | 10 assertEquals(Function.prototype, Object.getPrototypeOf(Object.entries)); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 Object.defineProperty(this, "b", { enumerable: true }); | 240 Object.defineProperty(this, "b", { enumerable: true }); |
241 return 1; | 241 return 1; |
242 }, | 242 }, |
243 enumerable: true | 243 enumerable: true |
244 }); | 244 }); |
245 Object.defineProperty(aMakesBEnumerable, "b", { | 245 Object.defineProperty(aMakesBEnumerable, "b", { |
246 value: 2, configurable:true, enumerable: false }); | 246 value: 2, configurable:true, enumerable: false }); |
247 assertEquals([ [ "a", 1 ], [ "b", 2 ] ], Object.entries(aMakesBEnumerable)); | 247 assertEquals([ [ "a", 1 ], [ "b", 2 ] ], Object.entries(aMakesBEnumerable)); |
248 } | 248 } |
249 TestMutateDuringEnumeration(); | 249 TestMutateDuringEnumeration(); |
| 250 |
| 251 |
| 252 (function TestElementKinds() { |
| 253 var O1 = { name: "1" }, O2 = { name: "2" }, O3 = { name: "3" }; |
| 254 var PI = 3.141592653589793; |
| 255 var E = 2.718281828459045; |
| 256 function fastSloppyArguments(a, b, c) { |
| 257 delete arguments[0]; |
| 258 arguments[0] = a; |
| 259 return arguments; |
| 260 } |
| 261 |
| 262 function slowSloppyArguments(a, b, c) { |
| 263 delete arguments[0]; |
| 264 arguments[0] = a; |
| 265 Object.defineProperties(arguments, { |
| 266 0: { |
| 267 enumerable: true, |
| 268 value: a |
| 269 }, |
| 270 9999: { |
| 271 enumerable: false, |
| 272 value: "Y" |
| 273 } |
| 274 }); |
| 275 arguments[10000] = "X"; |
| 276 return arguments; |
| 277 } |
| 278 |
| 279 var element_kinds = { |
| 280 FAST_SMI_ELEMENTS: [ [1, 2, 3], [ ["0", 1], ["1", 2], ["2", 3] ] ], |
| 281 FAST_HOLEY_SMI_ELEMENTS: [ [, , 3], [ ["2", 3] ] ], |
| 282 FAST_ELEMENTS: [ [O1, O2, O3], [ ["0", O1], ["1", O2], ["2", O3] ] ], |
| 283 FAST_HOLEY_ELEMENTS: [ [, , O3], [ ["2", O3] ] ], |
| 284 FAST_DOUBLE_ELEMENTS: [ [E, NaN, PI], [ ["0", E], ["1", NaN], ["2", PI] ] ], |
| 285 FAST_HOLEY_DOUBLE_ELEMENTS: [ [, , NaN], [ ["2", NaN] ] ], |
| 286 |
| 287 DICTIONARY_ELEMENTS: [ Object.defineProperties({ 10000: "world" }, { |
| 288 100: { enumerable: true, value: "hello" }, |
| 289 99: { enumerable: false, value: "nope" } |
| 290 }), [ ["100", "hello"], ["10000", "world" ] ] ], |
| 291 FAST_SLOPPY_ARGUMENTS_ELEMENTS: [ |
| 292 fastSloppyArguments("a", "b", "c"), |
| 293 [ ["0", "a"], ["1", "b"], ["2", "c"] ] ], |
| 294 SLOW_SLOPPY_ARGUMENTS_ELEMENTS: [ |
| 295 slowSloppyArguments("a", "b", "c"), |
| 296 [ ["0", "a"], ["1", "b"], ["2", "c"], ["10000", "X"] ] ], |
| 297 |
| 298 FAST_STRING_WRAPPER_ELEMENTS: [ new String("str"), |
| 299 [ ["0", "s"], ["1", "t"], ["2", "r"]] ], |
| 300 SLOW_STRING_WRAPPER_ELEMENTS: [ |
| 301 Object.defineProperties(new String("str"), { |
| 302 10000: { enumerable: false, value: "X" }, |
| 303 9999: { enumerable: true, value: "Y" } |
| 304 }), [["0", "s"], ["1", "t"], ["2", "r"], ["9999", "Y"]] ], |
| 305 }; |
| 306 |
| 307 for (let [kind, [object, expected]] of Object.entries(element_kinds)) { |
| 308 let result1 = Object.entries(object); |
| 309 assertEquals(expected, result1, `fast Object.entries() with ${kind}`); |
| 310 |
| 311 let proxy = new Proxy(object, {}); |
| 312 let result2 = Object.entries(proxy); |
| 313 assertEquals(result1, result2, `slow Object.entries() with ${kind}`); |
| 314 } |
| 315 })(); |
OLD | NEW |