v8/test/mjsunit/es6/set-iterator-11.js
Hai Dang fb29a554e8 Add fast path for spreading keys/values of JSMap and JSSet.
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}
2018-10-17 09:18:50 +00:00

34 lines
779 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 set = new Set([1,2,3]);
var iterator = set.keys();
assertEquals([1,2,3], [...set.keys()]);
assertEquals([1,2,3], [...iterator]);
assertEquals([], [...iterator]);
iterator = set.values();
assertEquals([1,2,3], [...iterator]);
assertEquals([], [...iterator]);
iterator = set.keys();
iterator.next();
assertEquals([2,3], [...iterator]);
assertEquals([], [...iterator]);
iterator = set.values();
var iterator2 = set.values();
set.delete(1);
assertEquals([2,3], [...iterator]);
set.add(4);
assertEquals([2,3,4], [...iterator2]);
iterator = set.keys();
set.add(1);
assertEquals([2,3,4,1], [...iterator]);