fb29a554e8
This CL extends IterableToListWithSymbolLookup with fast paths for spreading keys/values iterators of JSMap, and values iterator of JSSet (which is also the iterator of Set.prototype.keys() and Set.prototype[Symbol.iterator]()). The fast paths are only taken if the target still has original iteration behavior. For iterators it is also required that the iterator is not partially consumed. After spreading, to be spec-compliant, the iterator is exhausted. Tests are added. Bug: v8:7980 Change-Id: Ida74e5ecbbc5ba5488d13a40f2c4bda14c781cbf Reviewed-on: https://chromium-review.googlesource.com/c/1276632 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Georg Neis <neis@chromium.org> Commit-Queue: Hai Dang <dhai@google.com> Cr-Commit-Position: refs/heads/master@{#56716}
36 lines
896 B
JavaScript
36 lines
896 B
JavaScript
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
var map = new Map([[1,2], [2,3], [3,4]]);
|
|
|
|
var iterator = map.keys();
|
|
assertEquals([1,2,3], [...map.keys()]);
|
|
assertEquals([1,2,3], [...iterator]);
|
|
assertEquals([], [...iterator]);
|
|
|
|
iterator = map.values();
|
|
assertEquals([2,3,4], [...iterator]);
|
|
assertEquals([], [...iterator]);
|
|
|
|
iterator = map.keys();
|
|
iterator.next();
|
|
assertEquals([2,3], [...iterator]);
|
|
assertEquals([], [...iterator]);
|
|
|
|
iterator = map.values();
|
|
var iterator2 = map.values();
|
|
|
|
map.delete(1);
|
|
assertEquals([3,4], [...iterator]);
|
|
assertEquals([], [...iterator]);
|
|
|
|
map.set(1,5);
|
|
assertEquals([3,4,5], [...iterator2]);
|
|
assertEquals([], [...iterator2]);
|
|
|
|
iterator = map.keys();
|
|
map.set(4,6);
|
|
assertEquals([2,3,1,4], [...iterator]);
|
|
assertEquals([], [...iterator]);
|