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

Issue 236143002: ES6: Add support for Map.prototype.forEach and Set.prototype.forEach (Closed)

Created:
6 years, 8 months ago by arv (Not doing code reviews)
Modified:
6 years, 8 months ago
CC:
v8-dev
Visibility:
Public.

Description

ES6: Add support for Map/Set forEach This implements MapIterator and SetIterator which matches the same constructs in the ES6 spec. However, these 2 iterators are not exposed to user code yet. They are only used internally to implement Map.prototype.forEach and Set.prototype.forEach. Each iterator has a reference to the OrderedHashTable where it directly accesses the hash table's entries. The OrderedHashTable has a reference to the newest iterator and each iterator has a reference to the next and previous iterator, effectively creating a double linked list. When the OrderedHashTable is mutated (or replaced) all the iterators are updated. When the iterator iterates passed the end of the data table it closes itself. Closed iterators no longer have a reference to the OrderedHashTable and they are removed from the double linked list. In the case of Map/Set forEach, we manually call Close on the iterator in case an exception was thrown so that the iterator never reached the end. At this point the OrderedHashTable keeps all the non finished iterators alive but since the only thing we currently expose is forEach there are no unfinished iterators outside a forEach call. Once we expose the iterators to user code we will need to make the references from the OrderedHashTable to the iterators weak and have some mechanism to close an iterator when it is garbage collected. BUG=1793, 2323 LOG=Y R=adamk@chromium.org, mstarzinger@chromium.org Committed: https://code.google.com/p/v8/source/detail?r=20781

Patch Set 1 #

Total comments: 46

Patch Set 2 : Code review changes #

Patch Set 3 : Fix issue with closing the iterator too early #

Patch Set 4 : static-ify #

Total comments: 14

Patch Set 5 : Store map in native context and use InObjectPropertyAtPut #

Patch Set 6 : Handle-ify and UsedCapacity #

Total comments: 15

Patch Set 7 : less handles #

Patch Set 8 : Refactor to pass table into Create and remove CreateIterator #

Total comments: 19

Patch Set 9 : Use IS_SPEC_FUNCTION instead #

Total comments: 2

Patch Set 10 : Michael's code review #

Patch Set 11 : Add test that calls gc() #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1193 lines, -71 lines) Patch
M src/arm/full-codegen-arm.cc View 1 chunk +1 line, -1 line 0 comments Download
M src/arm64/full-codegen-arm64.cc View 1 chunk +1 line, -1 line 0 comments Download
M src/array-iterator.js View 1 2 3 4 5 6 7 8 9 2 chunks +5 lines, -10 lines 0 comments Download
M src/bootstrapper.cc View 1 2 3 4 5 6 7 8 9 2 chunks +27 lines, -16 lines 0 comments Download
M src/collection.js View 1 2 3 4 5 6 7 8 9 5 chunks +54 lines, -6 lines 0 comments Download
M src/contexts.h View 1 2 3 4 2 chunks +6 lines, -2 lines 0 comments Download
M src/factory.h View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -0 lines 0 comments Download
M src/factory.cc View 1 2 3 4 5 6 7 8 9 2 chunks +13 lines, -0 lines 0 comments Download
M src/ia32/full-codegen-ia32.cc View 1 chunk +1 line, -1 line 0 comments Download
M src/macros.py View 1 2 3 4 5 6 7 8 9 1 chunk +5 lines, -0 lines 0 comments Download
M src/mips/full-codegen-mips.cc View 1 chunk +1 line, -1 line 0 comments Download
M src/objects.h View 1 2 3 4 5 6 7 14 chunks +177 lines, -9 lines 0 comments Download
M src/objects.cc View 1 2 3 4 5 6 7 8 9 11 chunks +262 lines, -20 lines 0 comments Download
M src/objects-debug.cc View 1 3 chunks +40 lines, -0 lines 0 comments Download
M src/objects-inl.h View 4 chunks +34 lines, -0 lines 0 comments Download
M src/objects-printer.cc View 1 2 3 4 5 6 7 8 9 4 chunks +41 lines, -3 lines 0 comments Download
M src/objects-visiting.cc View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -0 lines 0 comments Download
M src/runtime.h View 1 chunk +10 lines, -0 lines 0 comments Download
M src/runtime.cc View 1 2 3 4 5 6 7 4 chunks +85 lines, -0 lines 0 comments Download
M src/x64/full-codegen-x64.cc View 1 chunk +1 line, -1 line 0 comments Download
M test/cctest/test-ordered-hash-table.cc View 1 2 3 4 5 6 7 8 chunks +81 lines, -0 lines 0 comments Download
M test/mjsunit/harmony/collections.js View 1 2 3 4 5 6 7 8 9 10 1 chunk +344 lines, -0 lines 0 comments Download

Messages

Total messages: 32 (0 generated)
arv (Not doing code reviews)
Hi Adam, this is now ready for an initial review. TODOs [ ] Extensive CL ...
6 years, 8 months ago (2014-04-11 23:21:29 UTC) #1
adamk
Mostly looking good. I think there might be an edge case with the final element ...
6 years, 8 months ago (2014-04-14 19:15:42 UTC) #2
arv (Not doing code reviews)
I'll look into changing things to use static next https://codereview.chromium.org/236143002/diff/1/src/collection.js File src/collection.js (right): https://codereview.chromium.org/236143002/diff/1/src/collection.js#newcode130 src/collection.js:130: ...
6 years, 8 months ago (2014-04-14 19:51:48 UTC) #3
arv (Not doing code reviews)
Fix issue with closing the iterator too early
6 years, 8 months ago (2014-04-14 20:30:10 UTC) #4
arv (Not doing code reviews)
static-ify
6 years, 8 months ago (2014-04-14 20:59:05 UTC) #5
adamk
Needs moar Handles. Basically, in a function that does allocation, it's a Bad Idea to ...
6 years, 8 months ago (2014-04-14 21:25:53 UTC) #6
adamk
https://codereview.chromium.org/236143002/diff/60001/src/factory.cc File src/factory.cc (right): https://codereview.chromium.org/236143002/diff/60001/src/factory.cc#newcode2003 src/factory.cc:2003: JSObject::SetProperty(result, value_string(), value, NONE, SLOPPY).Assert(); I think you can ...
6 years, 8 months ago (2014-04-14 21:33:01 UTC) #7
arv (Not doing code reviews)
Store map in native context and use InObjectPropertyAtPut
6 years, 8 months ago (2014-04-14 21:41:45 UTC) #8
arv (Not doing code reviews)
https://codereview.chromium.org/236143002/diff/1/src/objects.cc File src/objects.cc (right): https://codereview.chromium.org/236143002/diff/1/src/objects.cc#newcode16090 src/objects.cc:16090: return factory->CreateIteratorResultObject(value, false); On 2014/04/14 19:51:49, arv wrote: > ...
6 years, 8 months ago (2014-04-14 21:41:55 UTC) #9
arv (Not doing code reviews)
Handle-ify and UsedCapacity
6 years, 8 months ago (2014-04-14 22:13:04 UTC) #10
arv (Not doing code reviews)
PTAL https://codereview.chromium.org/236143002/diff/60001/src/objects.cc File src/objects.cc (right): https://codereview.chromium.org/236143002/diff/60001/src/objects.cc#newcode15918 src/objects.cc:15918: Object* undefined = table->GetHeap()->undefined_value(); On 2014/04/14 21:25:54, adamk ...
6 years, 8 months ago (2014-04-14 22:13:26 UTC) #11
arv (Not doing code reviews)
Michael, Andreas, I've been working with Adam on this over the last week. I think ...
6 years, 8 months ago (2014-04-14 22:39:04 UTC) #12
adamk
https://codereview.chromium.org/236143002/diff/90001/src/bootstrapper.cc File src/bootstrapper.cc (right): https://codereview.chromium.org/236143002/diff/90001/src/bootstrapper.cc#newcode1295 src/bootstrapper.cc:1295: if (FLAG_harmony_collections) { Can you move those map constructions ...
6 years, 8 months ago (2014-04-14 22:46:38 UTC) #13
arv (Not doing code reviews)
less handless
6 years, 8 months ago (2014-04-15 00:23:39 UTC) #14
arv (Not doing code reviews)
https://codereview.chromium.org/236143002/diff/90001/src/bootstrapper.cc File src/bootstrapper.cc (right): https://codereview.chromium.org/236143002/diff/90001/src/bootstrapper.cc#newcode1295 src/bootstrapper.cc:1295: if (FLAG_harmony_collections) { On 2014/04/14 22:46:38, adamk wrote: > ...
6 years, 8 months ago (2014-04-15 00:29:16 UTC) #15
adamk
lgtm from my end, but of course I'm no v8 OWNER; looking forward to what ...
6 years, 8 months ago (2014-04-15 01:12:41 UTC) #16
arv (Not doing code reviews)
Refactor to pass table into Create and remove CreateIterator
6 years, 8 months ago (2014-04-15 02:44:19 UTC) #17
Michael Starzinger
One high-level comment: Is there a particular reason why SetIterator and MapIterator are JSObjects (with ...
6 years, 8 months ago (2014-04-15 10:47:23 UTC) #18
rossberg
https://codereview.chromium.org/236143002/diff/1/src/collection.js File src/collection.js (right): https://codereview.chromium.org/236143002/diff/1/src/collection.js#newcode130 src/collection.js:130: if (typeof f !== 'function') { On 2014/04/14 19:51:49, ...
6 years, 8 months ago (2014-04-15 10:49:29 UTC) #19
arv (Not doing code reviews)
On 2014/04/15 10:47:23, Michael Starzinger wrote: > One high-level comment: Is there a particular reason ...
6 years, 8 months ago (2014-04-15 12:56:56 UTC) #20
arv (Not doing code reviews)
On 2014/04/15 10:49:29, rossberg wrote: > https://codereview.chromium.org/236143002/diff/1/src/collection.js > File src/collection.js (right): > > https://codereview.chromium.org/236143002/diff/1/src/collection.js#newcode130 > ...
6 years, 8 months ago (2014-04-15 13:05:23 UTC) #21
rossberg
On 2014/04/15 13:05:23, arv wrote: > How are the callables in DOM represented? We use ...
6 years, 8 months ago (2014-04-15 13:21:58 UTC) #22
arv (Not doing code reviews)
Use IS_SPEC_FUNCTION instead
6 years, 8 months ago (2014-04-15 15:12:04 UTC) #23
Michael Starzinger
Looking good. One round of comments, mostly nits. https://codereview.chromium.org/236143002/diff/120001/src/bootstrapper.cc File src/bootstrapper.cc (right): https://codereview.chromium.org/236143002/diff/120001/src/bootstrapper.cc#newcode1370 src/bootstrapper.cc:1370: ASSERT(object_function->initial_map()->inobject_properties() ...
6 years, 8 months ago (2014-04-15 16:13:56 UTC) #24
Michael Starzinger
One more comment. https://codereview.chromium.org/236143002/diff/140001/test/mjsunit/harmony/collections.js File test/mjsunit/harmony/collections.js (right): https://codereview.chromium.org/236143002/diff/140001/test/mjsunit/harmony/collections.js#newcode820 test/mjsunit/harmony/collections.js:820: })(); Also can we have a ...
6 years, 8 months ago (2014-04-15 16:18:13 UTC) #25
arv (Not doing code reviews)
Michael's code review
6 years, 8 months ago (2014-04-15 16:56:03 UTC) #26
arv (Not doing code reviews)
Add test that calls gc()
6 years, 8 months ago (2014-04-15 17:06:14 UTC) #27
arv (Not doing code reviews)
PTAL Michael, I'm not sure what your concern about GC is? At this point the ...
6 years, 8 months ago (2014-04-15 17:07:22 UTC) #28
Michael Starzinger
LGTM. https://codereview.chromium.org/236143002/diff/120001/src/objects-visiting.h File src/objects-visiting.h (right): https://codereview.chromium.org/236143002/diff/120001/src/objects-visiting.h#newcode101 src/objects-visiting.h:101: V(JSMapIterator) \ On 2014/04/15 17:07:23, arv wrote: > ...
6 years, 8 months ago (2014-04-15 22:02:30 UTC) #29
arv (Not doing code reviews)
On 2014/04/15 22:02:30, Michael Starzinger wrote: > LGTM. Thanks for the review. Can you land ...
6 years, 8 months ago (2014-04-15 22:23:41 UTC) #30
adamk
Committed patchset #11 manually as r20781 (presubmit successful).
6 years, 8 months ago (2014-04-16 00:40:18 UTC) #31
adamk
6 years, 8 months ago (2014-04-16 01:06:45 UTC) #32
Message was sent while issue was closed.
On 2014/04/16 00:40:18, adamk wrote:
> Committed patchset #11 manually as r20781 (presubmit successful).

This got reverted in https://code.google.com/p/v8/source/detail?r=20782 for
breaking the Win32 build due to some unresolved symbols:

http://build.chromium.org/p/client.v8/builders/V8%20Win32%20-%20debug%20build...

Needs to be guarded with DECLARE_PRINTER():

3>e:\b\build\slave\win-dbg-b\build\v8\src\objects.h(10115): warning C4661: 'void
v8::internal::OrderedHashTableIterator<Derived,TableType>::OrderedHashTableIteratorPrint(FILE
*)' : no suitable definition provided for explicit template instantiation
request

Needs forced instantiations:

10>test-dictionary.obj :error LNK2019: unresolved external symbol "public: int
__thiscall v8::internal::OrderedHashTable<class
v8::internal::OrderedHashMap,class
v8::internal::JSMapIterator,2>::FindEntry(class v8::internal::Object *)"
(?FindEntry@?$OrderedHashTable@VOrderedHashMap@internal@v8@@VJSMapIterator@23@$01@internal@v8@@QAEHPAVObject@23@@Z)
referenced in function "void __cdecl `anonymous namespace'::TestHashMap<class
v8::internal::OrderedHashMap>(class v8::internal::Handle<class
v8::internal::OrderedHashMap>)"
(??$TestHashMap@VOrderedHashMap@internal@v8@@@?A0xf5b4ac9d@@YAXV?$Handle@VOrderedHashMap@internal@v8@@@internal@v8@@@Z)

10>test-ordered-hash-table.obj :error LNK2019: unresolved external symbol
"public: static class v8::internal::Handle<class v8::internal::JSObject> __cdecl
v8::internal::OrderedHashTableIterator<class v8::internal::JSSetIterator,class
v8::internal::OrderedHashSet>::Next(class v8::internal::Handle<class
v8::internal::JSSetIterator>)"
(?Next@?$OrderedHashTableIterator@VJSSetIterator@internal@v8@@VOrderedHashSet@23@@internal@v8@@SA?AV?$Handle@VJSObject@internal@v8@@@23@V?$Handle@VJSSetIterator@internal@v8@@@23@@Z)
referenced in function "void __cdecl `anonymous namespace'::TestSet(void)"
(?TestSet@?A0x835bb4df@@YAXXZ)

10>test-ordered-hash-table.obj :error LNK2019: unresolved external symbol
"public: static class v8::internal::Handle<class v8::internal::JSObject> __cdecl
v8::internal::OrderedHashTableIterator<class v8::internal::JSMapIterator,class
v8::internal::OrderedHashMap>::Next(class v8::internal::Handle<class
v8::internal::JSMapIterator>)"
(?Next@?$OrderedHashTableIterator@VJSMapIterator@internal@v8@@VOrderedHashMap@23@@internal@v8@@SA?AV?$Handle@VJSObject@internal@v8@@@23@V?$Handle@VJSMapIterator@internal@v8@@@23@@Z)
referenced in function "void __cdecl `anonymous namespace'::TestMap(void)"
(?TestMap@?A0x835bb4df@@YAXXZ)


I don't understand:

10>test-ordered-hash-table.obj :error LNK2019: unresolved external symbol
"public: static class v8::internal::Handle<class v8::internal::JSSetIterator>
__cdecl v8::internal::JSSetIterator::Create(class v8::internal::Handle<class
v8::internal::OrderedHashSet>,int)"
(?Create@JSSetIterator@internal@v8@@SA?AV?$Handle@VJSSetIterator@internal@v8@@@23@V?$Handle@VOrderedHashSet@internal@v8@@@23@H@Z)
referenced in function "void __cdecl `anonymous namespace'::TestSet(void)"
(?TestSet@?A0x835bb4df@@YAXXZ)

10>test-ordered-hash-table.obj :error LNK2019: unresolved external symbol
"public: static class v8::internal::Handle<class v8::internal::JSMapIterator>
__cdecl v8::internal::JSMapIterator::Create(class v8::internal::Handle<class
v8::internal::OrderedHashMap>,int)"
(?Create@JSMapIterator@internal@v8@@SA?AV?$Handle@VJSMapIterator@internal@v8@@@23@V?$Handle@VOrderedHashMap@internal@v8@@@23@H@Z)
referenced in function "void __cdecl `anonymous namespace'::TestMap(void)"
(?TestMap@?A0x835bb4df@@YAXXZ)

Powered by Google App Engine
This is Rietveld 408576698