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

Unified 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: Apply same changes to MapForEach and SetForEach Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index 0027bd732041f94ccf81dbfe3256c4f75d680c5a..7c7dd8bb728cda1f4c5262d32080834acb8fef0e 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -105,15 +105,22 @@ function SetForEach(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [f]);
}
+ if (IS_NULL_OR_UNDEFINED(receiver)) {
+ receiver = %GetDefaultReceiver(f) || receiver;
+ }
var iterator = new SetIterator(this, ITERATOR_KIND_VALUES);
var key;
var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
var value_array = [UNDEFINED];
while (%SetIteratorNext(iterator, value_array)) {
+ var new_receiver = receiver;
+ if (!IS_NULL_OR_UNDEFINED(receiver)) {
arv (Not doing code reviews) 2014/09/12 16:29:17 Why is this one different? Can you verify with the
Diego Pino 2014/09/16 10:45:46 I tried to preserve the semantics of the old code.
+ new_receiver = ToObject(receiver);
+ }
if (stepping) %DebugPrepareStepInIfStepping(f);
key = value_array[0];
- %_CallFunction(receiver, key, key, this, f);
+ %_CallFunction(new_receiver, key, key, this, f);
}
}
@@ -249,13 +256,20 @@ function MapForEach(f, receiver) {
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [f]);
}
+ if (IS_NULL_OR_UNDEFINED(receiver)) {
+ receiver = %GetDefaultReceiver(f) || receiver;
+ }
var iterator = new MapIterator(this, ITERATOR_KIND_ENTRIES);
var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
var value_array = [UNDEFINED, UNDEFINED];
while (%MapIteratorNext(iterator, value_array)) {
+ var new_receiver = receiver;
+ if (!IS_NULL_OR_UNDEFINED(receiver)) {
wingo 2014/09/15 09:12:21 Same comment here as Erik's comment above.
+ new_receiver = ToObject(receiver);
+ }
if (stepping) %DebugPrepareStepInIfStepping(f);
- %_CallFunction(receiver, value_array[1], value_array[0], this, f);
+ %_CallFunction(new_receiver, value_array[1], value_array[0], this, f);
}
}

Powered by Google App Engine
This is Rietveld 408576698