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

Side by Side Diff: src/collection-iterator.js

Issue 259883002: ES6: Add support for Map and Set Iterator (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review changes Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/collection.js ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7
8 // This file relies on the fact that the following declaration has been made
9 // in runtime.js:
10 // var $Set = global.Set;
11 // var $Map = global.Map;
12
13
14 function SetIteratorConstructor(set, kind) {
15 %SetIteratorInitialize(this, set, kind);
16 }
17
18
19 function SetIteratorNextJS() {
20 if (!IS_SET_ITERATOR(this)) {
21 throw MakeTypeError('incompatible_method_receiver',
22 ['Set Iterator.prototype.next', this]);
23 }
24 return %SetIteratorNext(this);
25 }
26
27
28 function SetIteratorSymbolIterator() {
29 return this;
30 }
31
32
33 function SetEntries() {
34 if (!IS_SET(this)) {
35 throw MakeTypeError('incompatible_method_receiver',
36 ['Set.prototype.entries', this]);
37 }
38 return new SetIterator(this, ITERATOR_KIND_ENTRIES);
39 }
40
41
42 function SetValues() {
43 if (!IS_SET(this)) {
44 throw MakeTypeError('incompatible_method_receiver',
45 ['Set.prototype.values', this]);
46 }
47 return new SetIterator(this, ITERATOR_KIND_VALUES);
48 }
49
50
51 function SetUpSetIterator() {
52 %CheckIsBootstrapping();
53
54 %SetCode(SetIterator, SetIteratorConstructor);
55 %FunctionSetPrototype(SetIterator, new $Object());
56 %FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
57 InstallFunctions(SetIterator.prototype, DONT_ENUM, $Array(
58 'next', SetIteratorNextJS
59 ));
60
61 %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
62 %SetProperty(SetIterator.prototype, InternalSymbol('Symbol.iterator'),
63 SetIteratorSymbolIterator, DONT_ENUM);
64 }
65
66 SetUpSetIterator();
67
68
69 function ExtendSetPrototype() {
70 %CheckIsBootstrapping();
71
72 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
73 'entries', SetEntries,
74 'values', SetValues
75 ));
76
77 %SetProperty($Set.prototype, InternalSymbol('Symbol.iterator'), SetValues,
78 DONT_ENUM);
79 }
80
81 ExtendSetPrototype();
82
83
84
85 function MapIteratorConstructor(map, kind) {
86 %MapIteratorInitialize(this, map, kind);
87 }
88
89
90 function MapIteratorSymbolIterator() {
91 return this;
92 }
93
94
95 function MapIteratorNextJS() {
96 if (!IS_MAP_ITERATOR(this)) {
97 throw MakeTypeError('incompatible_method_receiver',
98 ['Map Iterator.prototype.next', this]);
99 }
100 return %MapIteratorNext(this);
101 }
102
103
104 function MapEntries() {
105 if (!IS_MAP(this)) {
106 throw MakeTypeError('incompatible_method_receiver',
107 ['Map.prototype.entries', this]);
108 }
109 return new MapIterator(this, ITERATOR_KIND_ENTRIES);
110 }
111
112
113 function MapKeys() {
114 if (!IS_MAP(this)) {
115 throw MakeTypeError('incompatible_method_receiver',
116 ['Map.prototype.keys', this]);
117 }
118 return new MapIterator(this, ITERATOR_KIND_KEYS);
119 }
120
121
122 function MapValues() {
123 if (!IS_MAP(this)) {
124 throw MakeTypeError('incompatible_method_receiver',
125 ['Map.prototype.values', this]);
126 }
127 return new MapIterator(this, ITERATOR_KIND_VALUES);
128 }
129
130
131 function SetUpMapIterator() {
132 %CheckIsBootstrapping();
133
134 %SetCode(MapIterator, MapIteratorConstructor);
135 %FunctionSetPrototype(MapIterator, new $Object());
136 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
137 InstallFunctions(MapIterator.prototype, DONT_ENUM, $Array(
138 'next', MapIteratorNextJS
139 ));
140
141 %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
142 %SetProperty(MapIterator.prototype, InternalSymbol('Symbol.iterator'),
143 MapIteratorSymbolIterator, DONT_ENUM);
144 }
145
146 SetUpMapIterator();
147
148
149 function ExtendMapPrototype() {
150 %CheckIsBootstrapping();
151
152 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
153 'entries', MapEntries,
154 'keys', MapKeys,
155 'values', MapValues
156 ));
157
158 %SetProperty($Map.prototype, InternalSymbol('Symbol.iterator'), MapEntries,
159 DONT_ENUM);
160 }
161
162 ExtendMapPrototype();
OLDNEW
« no previous file with comments | « src/collection.js ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698