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

Side by Side Diff: src/collection.js

Issue 956623003: Use for-of loops in collection constructors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | src/weak-collection.js » ('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
11 var $Set = global.Set; 11 var $Set = global.Set;
12 var $Map = global.Map; 12 var $Map = global.Map;
13 13
14 14
15 // ------------------------------------------------------------------- 15 // -------------------------------------------------------------------
16 // Harmony Set 16 // Harmony Set
17 17
18 function SetConstructor(iterable) { 18 function SetConstructor(iterable) {
19 if (!%_IsConstructCall()) { 19 if (!%_IsConstructCall()) {
20 throw MakeTypeError('constructor_not_function', ['Set']); 20 throw MakeTypeError('constructor_not_function', ['Set']);
21 } 21 }
22 22
23 var iter, adder;
24
25 if (!IS_NULL_OR_UNDEFINED(iterable)) {
26 adder = this.add;
27 if (!IS_SPEC_FUNCTION(adder)) {
28 throw MakeTypeError('property_not_function', ['add', this]);
29 }
30 iter = GetIterator(iterable);
31 }
32
33 %_SetInitialize(this); 23 %_SetInitialize(this);
34 24
35 if (IS_UNDEFINED(iter)) return; 25 if (!IS_NULL_OR_UNDEFINED(iterable)) {
26 var adder = this.add;
27 if (!IS_SPEC_FUNCTION(adder)) {
28 throw MakeTypeError('property_not_function', ['add', this]);
29 }
36 30
37 var next, done; 31 for (var value of iterable) {
38 while (!(next = iter.next()).done) { 32 %_CallFunction(this, value, adder);
39 if (!IS_SPEC_OBJECT(next)) {
40 throw MakeTypeError('iterator_result_not_an_object', [next]);
41 } 33 }
42 %_CallFunction(this, next.value, adder);
43 } 34 }
44 } 35 }
45 36
46 37
47 function SetAddJS(key) { 38 function SetAddJS(key) {
48 if (!IS_SET(this)) { 39 if (!IS_SET(this)) {
49 throw MakeTypeError('incompatible_method_receiver', 40 throw MakeTypeError('incompatible_method_receiver',
50 ['Set.prototype.add', this]); 41 ['Set.prototype.add', this]);
51 } 42 }
52 // Normalize -0 to +0 as required by the spec. 43 // Normalize -0 to +0 as required by the spec.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 144
154 145
155 // ------------------------------------------------------------------- 146 // -------------------------------------------------------------------
156 // Harmony Map 147 // Harmony Map
157 148
158 function MapConstructor(iterable) { 149 function MapConstructor(iterable) {
159 if (!%_IsConstructCall()) { 150 if (!%_IsConstructCall()) {
160 throw MakeTypeError('constructor_not_function', ['Map']); 151 throw MakeTypeError('constructor_not_function', ['Map']);
161 } 152 }
162 153
163 var iter, adder;
164
165 if (!IS_NULL_OR_UNDEFINED(iterable)) {
166 adder = this.set;
167 if (!IS_SPEC_FUNCTION(adder)) {
168 throw MakeTypeError('property_not_function', ['set', this]);
169 }
170 iter = GetIterator(iterable);
171 }
172
173 %_MapInitialize(this); 154 %_MapInitialize(this);
174 155
175 if (IS_UNDEFINED(iter)) return; 156 if (!IS_NULL_OR_UNDEFINED(iterable)) {
157 var adder = this.set;
158 if (!IS_SPEC_FUNCTION(adder)) {
159 throw MakeTypeError('property_not_function', ['set', this]);
160 }
176 161
177 var next, done, nextItem; 162 for (var nextItem of iterable) {
178 while (!(next = iter.next()).done) { 163 if (!IS_SPEC_OBJECT(nextItem)) {
179 if (!IS_SPEC_OBJECT(next)) { 164 throw MakeTypeError('iterator_value_not_an_object', [nextItem]);
180 throw MakeTypeError('iterator_result_not_an_object', [next]); 165 }
166 %_CallFunction(this, nextItem[0], nextItem[1], adder);
181 } 167 }
182 nextItem = next.value;
183 if (!IS_SPEC_OBJECT(nextItem)) {
184 throw MakeTypeError('iterator_value_not_an_object', [nextItem]);
185 }
186 %_CallFunction(this, nextItem[0], nextItem[1], adder);
187 } 168 }
188 } 169 }
189 170
190 171
191 function MapGetJS(key) { 172 function MapGetJS(key) {
192 if (!IS_MAP(this)) { 173 if (!IS_MAP(this)) {
193 throw MakeTypeError('incompatible_method_receiver', 174 throw MakeTypeError('incompatible_method_receiver',
194 ['Map.prototype.get', this]); 175 ['Map.prototype.get', this]);
195 } 176 }
196 return %_MapGet(this, key); 177 return %_MapGet(this, key);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 "get", MapGetJS, 276 "get", MapGetJS,
296 "set", MapSetJS, 277 "set", MapSetJS,
297 "has", MapHasJS, 278 "has", MapHasJS,
298 "delete", MapDeleteJS, 279 "delete", MapDeleteJS,
299 "clear", MapClearJS, 280 "clear", MapClearJS,
300 "forEach", MapForEach 281 "forEach", MapForEach
301 )); 282 ));
302 } 283 }
303 284
304 SetUpMap(); 285 SetUpMap();
OLDNEW
« no previous file with comments | « no previous file | src/weak-collection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698