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

Side by Side Diff: src/collection.js

Issue 553413002: Array.prototype.{every, filter, find, findIndex, forEach, map, some}: Use fresh primitive wrapper f… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed nits from last patch. Created 6 years, 2 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/array.js ('k') | src/harmony-array.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
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 function SetForEach(f, receiver) { 99 function SetForEach(f, receiver) {
100 if (!IS_SET(this)) { 100 if (!IS_SET(this)) {
101 throw MakeTypeError('incompatible_method_receiver', 101 throw MakeTypeError('incompatible_method_receiver',
102 ['Set.prototype.forEach', this]); 102 ['Set.prototype.forEach', this]);
103 } 103 }
104 104
105 if (!IS_SPEC_FUNCTION(f)) { 105 if (!IS_SPEC_FUNCTION(f)) {
106 throw MakeTypeError('called_non_callable', [f]); 106 throw MakeTypeError('called_non_callable', [f]);
107 } 107 }
108 var needs_wrapper = false;
109 if (IS_NULL_OR_UNDEFINED(receiver)) {
110 receiver = %GetDefaultReceiver(f) || receiver;
111 } else {
112 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
113 }
108 114
109 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES); 115 var iterator = new SetIterator(this, ITERATOR_KIND_VALUES);
110 var key; 116 var key;
111 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 117 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
112 var value_array = [UNDEFINED]; 118 var value_array = [UNDEFINED];
113 while (%SetIteratorNext(iterator, value_array)) { 119 while (%SetIteratorNext(iterator, value_array)) {
114 if (stepping) %DebugPrepareStepInIfStepping(f); 120 if (stepping) %DebugPrepareStepInIfStepping(f);
115 key = value_array[0]; 121 key = value_array[0];
116 %_CallFunction(receiver, key, key, this, f); 122 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
123 %_CallFunction(new_receiver, key, key, this, f);
117 } 124 }
118 } 125 }
119 126
120 127
121 // ------------------------------------------------------------------- 128 // -------------------------------------------------------------------
122 129
123 function SetUpSet() { 130 function SetUpSet() {
124 %CheckIsBootstrapping(); 131 %CheckIsBootstrapping();
125 132
126 %SetCode($Set, SetConstructor); 133 %SetCode($Set, SetConstructor);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 249
243 function MapForEach(f, receiver) { 250 function MapForEach(f, receiver) {
244 if (!IS_MAP(this)) { 251 if (!IS_MAP(this)) {
245 throw MakeTypeError('incompatible_method_receiver', 252 throw MakeTypeError('incompatible_method_receiver',
246 ['Map.prototype.forEach', this]); 253 ['Map.prototype.forEach', this]);
247 } 254 }
248 255
249 if (!IS_SPEC_FUNCTION(f)) { 256 if (!IS_SPEC_FUNCTION(f)) {
250 throw MakeTypeError('called_non_callable', [f]); 257 throw MakeTypeError('called_non_callable', [f]);
251 } 258 }
259 var needs_wrapper = false;
260 if (IS_NULL_OR_UNDEFINED(receiver)) {
261 receiver = %GetDefaultReceiver(f) || receiver;
262 } else {
263 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
264 }
252 265
253 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES); 266 var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES);
254 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 267 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
255 var value_array = [UNDEFINED, UNDEFINED]; 268 var value_array = [UNDEFINED, UNDEFINED];
256 while (%MapIteratorNext(iterator, value_array)) { 269 while (%MapIteratorNext(iterator, value_array)) {
257 if (stepping) %DebugPrepareStepInIfStepping(f); 270 if (stepping) %DebugPrepareStepInIfStepping(f);
258 %_CallFunction(receiver, value_array[1], value_array[0], this, f); 271 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
272 %_CallFunction(new_receiver, value_array[1], value_array[0], this, f);
259 } 273 }
260 } 274 }
261 275
262 276
263 // ------------------------------------------------------------------- 277 // -------------------------------------------------------------------
264 278
265 function SetUpMap() { 279 function SetUpMap() {
266 %CheckIsBootstrapping(); 280 %CheckIsBootstrapping();
267 281
268 %SetCode($Map, MapConstructor); 282 %SetCode($Map, MapConstructor);
269 %FunctionSetPrototype($Map, new $Object()); 283 %FunctionSetPrototype($Map, new $Object());
270 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); 284 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
271 285
272 %FunctionSetLength(MapForEach, 1); 286 %FunctionSetLength(MapForEach, 1);
273 287
274 // Set up the non-enumerable functions on the Map prototype object. 288 // Set up the non-enumerable functions on the Map prototype object.
275 InstallGetter($Map.prototype, "size", MapGetSizeJS); 289 InstallGetter($Map.prototype, "size", MapGetSizeJS);
276 InstallFunctions($Map.prototype, DONT_ENUM, $Array( 290 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
277 "get", MapGetJS, 291 "get", MapGetJS,
278 "set", MapSetJS, 292 "set", MapSetJS,
279 "has", MapHasJS, 293 "has", MapHasJS,
280 "delete", MapDeleteJS, 294 "delete", MapDeleteJS,
281 "clear", MapClearJS, 295 "clear", MapClearJS,
282 "forEach", MapForEach 296 "forEach", MapForEach
283 )); 297 ));
284 } 298 }
285 299
286 SetUpMap(); 300 SetUpMap();
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/harmony-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698