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

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: Fix last issues. 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
« no previous file with comments | « src/array.js ('k') | src/harmony-array.js » ('j') | src/harmony-array.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index 0027bd732041f94ccf81dbfe3256c4f75d680c5a..e2911ea1f6c95c6e143109a90873f0945d891afd 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -105,6 +105,10 @@ 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 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
var iterator = new SetIterator(this, ITERATOR_KIND_VALUES);
var key;
@@ -113,7 +117,8 @@ function SetForEach(f, receiver) {
while (%SetIteratorNext(iterator, value_array)) {
if (stepping) %DebugPrepareStepInIfStepping(f);
key = value_array[0];
- %_CallFunction(receiver, key, key, this, f);
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
+ %_CallFunction(new_receiver, key, key, this, f);
}
}
@@ -249,13 +254,18 @@ 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 needs_wrapper = SHOULD_CREATE_WRAPPER(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)) {
if (stepping) %DebugPrepareStepInIfStepping(f);
- %_CallFunction(receiver, value_array[1], value_array[0], this, f);
+ var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
+ %_CallFunction(new_receiver, value_array[1], value_array[0], this, f);
}
}
« no previous file with comments | « src/array.js ('k') | src/harmony-array.js » ('j') | src/harmony-array.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698