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

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: Add back @iterator part 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
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,
64 DONT_ENUM);
65 }
66
67 SetUpSetIterator();
68
69
70 function ExtendSetPrototype() {
71 %CheckIsBootstrapping();
72
73 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
74 'entries', SetEntries,
75 'values', SetValues
76 ));
77
78 %SetProperty($Set.prototype, InternalSymbol('Symbol.iterator'), SetValues,
79 DONT_ENUM);
80 }
81
82 ExtendSetPrototype();
83
84
85
86 function MapIteratorConstructor(map, kind) {
87 %MapIteratorInitialize(this, map, kind);
88 }
89
90
91 function MapIteratorSymbolIterator() {
92 return this;
93 }
94
95
96 function MapIteratorNextJS() {
97 if (!IS_MAP_ITERATOR(this)) {
98 throw MakeTypeError('incompatible_method_receiver',
99 ['Map Iterator.prototype.next', this]);
100 }
101 return %MapIteratorNext(this);
102 }
103
104
105 function MapEntries() {
106 if (!IS_MAP(this)) {
107 throw MakeTypeError('incompatible_method_receiver',
108 ['Map.prototype.entries', this]);
109 }
110 return new MapIterator(this, ITERATOR_KIND_ENTRIES);
111 }
112
113
114 function MapKeys() {
115 if (!IS_MAP(this)) {
116 throw MakeTypeError('incompatible_method_receiver',
117 ['Map.prototype.keys', this]);
118 }
119 return new MapIterator(this, ITERATOR_KIND_KEYS);
120 }
121
122
123 function MapValues() {
124 if (!IS_MAP(this)) {
125 throw MakeTypeError('incompatible_method_receiver',
126 ['Map.prototype.values', this]);
127 }
128 return new MapIterator(this, ITERATOR_KIND_VALUES);
129 }
130
131
132 function SetUpMapIterator() {
133 %CheckIsBootstrapping();
134
135 %SetCode(MapIterator, MapIteratorConstructor);
136 %FunctionSetPrototype(MapIterator, new $Object());
137 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
138 InstallFunctions(MapIterator.prototype, DONT_ENUM, $Array(
139 'next', MapIteratorNextJS
140 ));
141
142 %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
143 %SetProperty(MapIterator.prototype, InternalSymbol('Symbol.iterator'),
144 MapIteratorSymbolIterator,
145 DONT_ENUM);
146 }
147
148 SetUpMapIterator();
149
150
151 function ExtendMapPrototype() {
152 %CheckIsBootstrapping();
153
154 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
155 'entries', MapEntries,
156 'keys', MapKeys,
157 'values', MapValues
158 ));
159
160 %SetProperty($Map.prototype, InternalSymbol('Symbol.iterator'), MapEntries,
161 DONT_ENUM);
162 }
163
164 ExtendMapPrototype();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698