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

Side by Side Diff: src/collection.js

Issue 289503002: ES6 Map/Set iterators/forEach improvements (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: git rebase to fix merge conflict Created 6 years, 7 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 | « no previous file | src/objects.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 throw MakeTypeError('incompatible_method_receiver', 99 throw MakeTypeError('incompatible_method_receiver',
100 ['Set.prototype.forEach', this]); 100 ['Set.prototype.forEach', this]);
101 } 101 }
102 102
103 if (!IS_SPEC_FUNCTION(f)) { 103 if (!IS_SPEC_FUNCTION(f)) {
104 throw MakeTypeError('called_non_callable', [f]); 104 throw MakeTypeError('called_non_callable', [f]);
105 } 105 }
106 106
107 var iterator = %SetCreateIterator(this, ITERATOR_KIND_VALUES); 107 var iterator = %SetCreateIterator(this, ITERATOR_KIND_VALUES);
108 var entry; 108 var entry;
109 try { 109 while (!(entry = %SetIteratorNext(iterator)).done) {
110 while (!(entry = %SetIteratorNext(iterator)).done) { 110 %_CallFunction(receiver, entry.value, entry.value, this, f);
111 %_CallFunction(receiver, entry.value, entry.value, this, f);
112 }
113 } finally {
114 %SetIteratorClose(iterator);
115 } 111 }
116 } 112 }
117 113
118 114
119 // ------------------------------------------------------------------- 115 // -------------------------------------------------------------------
120 116
121 function SetUpSet() { 117 function SetUpSet() {
122 %CheckIsBootstrapping(); 118 %CheckIsBootstrapping();
123 119
124 %SetCode($Set, SetConstructor); 120 %SetCode($Set, SetConstructor);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 throw MakeTypeError('incompatible_method_receiver', 208 throw MakeTypeError('incompatible_method_receiver',
213 ['Map.prototype.forEach', this]); 209 ['Map.prototype.forEach', this]);
214 } 210 }
215 211
216 if (!IS_SPEC_FUNCTION(f)) { 212 if (!IS_SPEC_FUNCTION(f)) {
217 throw MakeTypeError('called_non_callable', [f]); 213 throw MakeTypeError('called_non_callable', [f]);
218 } 214 }
219 215
220 var iterator = %MapCreateIterator(this, ITERATOR_KIND_ENTRIES); 216 var iterator = %MapCreateIterator(this, ITERATOR_KIND_ENTRIES);
221 var entry; 217 var entry;
222 try { 218 while (!(entry = %MapIteratorNext(iterator)).done) {
223 while (!(entry = %MapIteratorNext(iterator)).done) { 219 %_CallFunction(receiver, entry.value[1], entry.value[0], this, f);
224 %_CallFunction(receiver, entry.value[1], entry.value[0], this, f);
225 }
226 } finally {
227 %MapIteratorClose(iterator);
228 } 220 }
229 } 221 }
230 222
231 223
232 // ------------------------------------------------------------------- 224 // -------------------------------------------------------------------
233 225
234 function SetUpMap() { 226 function SetUpMap() {
235 %CheckIsBootstrapping(); 227 %CheckIsBootstrapping();
236 228
237 %SetCode($Map, MapConstructor); 229 %SetCode($Map, MapConstructor);
238 %FunctionSetPrototype($Map, new $Object()); 230 %FunctionSetPrototype($Map, new $Object());
239 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); 231 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
240 232
241 %FunctionSetLength(MapForEach, 1); 233 %FunctionSetLength(MapForEach, 1);
242 234
243 // Set up the non-enumerable functions on the Map prototype object. 235 // Set up the non-enumerable functions on the Map prototype object.
244 InstallGetter($Map.prototype, "size", MapGetSizeJS); 236 InstallGetter($Map.prototype, "size", MapGetSizeJS);
245 InstallFunctions($Map.prototype, DONT_ENUM, $Array( 237 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
246 "get", MapGetJS, 238 "get", MapGetJS,
247 "set", MapSetJS, 239 "set", MapSetJS,
248 "has", MapHasJS, 240 "has", MapHasJS,
249 "delete", MapDeleteJS, 241 "delete", MapDeleteJS,
250 "clear", MapClearJS, 242 "clear", MapClearJS,
251 "forEach", MapForEach 243 "forEach", MapForEach
252 )); 244 ));
253 } 245 }
254 246
255 SetUpMap(); 247 SetUpMap();
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698