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

Side by Side Diff: src/collection.js

Issue 239163012: Revert "ES6: Add support for Map/Set forEach" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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/bootstrapper.cc ('k') | src/contexts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 return %SetGetSize(this); 107 return %SetGetSize(this);
108 } 108 }
109 109
110 110
111 function SetClear() { 111 function SetClear() {
112 if (!IS_SET(this)) { 112 if (!IS_SET(this)) {
113 throw MakeTypeError('incompatible_method_receiver', 113 throw MakeTypeError('incompatible_method_receiver',
114 ['Set.prototype.clear', this]); 114 ['Set.prototype.clear', this]);
115 } 115 }
116 %SetClear(this); 116 // Replace the internal table with a new empty table.
117 %SetInitialize(this);
117 } 118 }
118 119
119 120
120 function SetForEach(f, receiver) {
121 if (!IS_SET(this)) {
122 throw MakeTypeError('incompatible_method_receiver',
123 ['Set.prototype.forEach', this]);
124 }
125
126 if (!IS_SPEC_FUNCTION(f)) {
127 throw MakeTypeError('called_non_callable', [f]);
128 }
129
130 var iterator = %SetCreateIterator(this, ITERATOR_KIND_VALUES);
131 var entry;
132 try {
133 while (!(entry = %SetIteratorNext(iterator)).done) {
134 %_CallFunction(receiver, entry.value, entry.value, this, f);
135 }
136 } finally {
137 %SetIteratorClose(iterator);
138 }
139 }
140
141
142 // ------------------------------------------------------------------- 121 // -------------------------------------------------------------------
143 122
144 function SetUpSet() { 123 function SetUpSet() {
145 %CheckIsBootstrapping(); 124 %CheckIsBootstrapping();
146 125
147 %SetCode($Set, SetConstructor); 126 %SetCode($Set, SetConstructor);
148 %FunctionSetPrototype($Set, new $Object()); 127 %FunctionSetPrototype($Set, new $Object());
149 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); 128 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
150 129
151 %FunctionSetLength(SetForEach, 1);
152
153 // Set up the non-enumerable functions on the Set prototype object. 130 // Set up the non-enumerable functions on the Set prototype object.
154 InstallGetter($Set.prototype, "size", SetGetSize); 131 InstallGetter($Set.prototype, "size", SetGetSize);
155 InstallFunctions($Set.prototype, DONT_ENUM, $Array( 132 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
156 "add", SetAdd, 133 "add", SetAdd,
157 "has", SetHas, 134 "has", SetHas,
158 "delete", SetDelete, 135 "delete", SetDelete,
159 "clear", SetClear, 136 "clear", SetClear
160 "forEach", SetForEach
161 )); 137 ));
162 } 138 }
163 139
164 SetUpSet(); 140 SetUpSet();
165 141
166 142
167 // ------------------------------------------------------------------- 143 // -------------------------------------------------------------------
168 // Harmony Map 144 // Harmony Map
169 145
170 function MapConstructor() { 146 function MapConstructor() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 195 }
220 return %MapGetSize(this); 196 return %MapGetSize(this);
221 } 197 }
222 198
223 199
224 function MapClear() { 200 function MapClear() {
225 if (!IS_MAP(this)) { 201 if (!IS_MAP(this)) {
226 throw MakeTypeError('incompatible_method_receiver', 202 throw MakeTypeError('incompatible_method_receiver',
227 ['Map.prototype.clear', this]); 203 ['Map.prototype.clear', this]);
228 } 204 }
229 %MapClear(this); 205 // Replace the internal table with a new empty table.
206 %MapInitialize(this);
230 } 207 }
231 208
232 209
233 function MapForEach(f, receiver) {
234 if (!IS_MAP(this)) {
235 throw MakeTypeError('incompatible_method_receiver',
236 ['Map.prototype.forEach', this]);
237 }
238
239 if (!IS_SPEC_FUNCTION(f)) {
240 throw MakeTypeError('called_non_callable', [f]);
241 }
242
243 var iterator = %MapCreateIterator(this, ITERATOR_KIND_ENTRIES);
244 var entry;
245 try {
246 while (!(entry = %MapIteratorNext(iterator)).done) {
247 %_CallFunction(receiver, entry.value[1], entry.value[0], this, f);
248 }
249 } finally {
250 %MapIteratorClose(iterator);
251 }
252 }
253
254
255 // ------------------------------------------------------------------- 210 // -------------------------------------------------------------------
256 211
257 function SetUpMap() { 212 function SetUpMap() {
258 %CheckIsBootstrapping(); 213 %CheckIsBootstrapping();
259 214
260 %SetCode($Map, MapConstructor); 215 %SetCode($Map, MapConstructor);
261 %FunctionSetPrototype($Map, new $Object()); 216 %FunctionSetPrototype($Map, new $Object());
262 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); 217 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
263 218
264 %FunctionSetLength(MapForEach, 1);
265
266 // Set up the non-enumerable functions on the Map prototype object. 219 // Set up the non-enumerable functions on the Map prototype object.
267 InstallGetter($Map.prototype, "size", MapGetSize); 220 InstallGetter($Map.prototype, "size", MapGetSize);
268 InstallFunctions($Map.prototype, DONT_ENUM, $Array( 221 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
269 "get", MapGet, 222 "get", MapGet,
270 "set", MapSet, 223 "set", MapSet,
271 "has", MapHas, 224 "has", MapHas,
272 "delete", MapDelete, 225 "delete", MapDelete,
273 "clear", MapClear, 226 "clear", MapClear
274 "forEach", MapForEach
275 )); 227 ));
276 } 228 }
277 229
278 SetUpMap(); 230 SetUpMap();
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698