Diff
Modified: trunk/LayoutTests/ChangeLog (91823 => 91824)
--- trunk/LayoutTests/ChangeLog 2011-07-27 03:48:27 UTC (rev 91823)
+++ trunk/LayoutTests/ChangeLog 2011-07-27 06:02:54 UTC (rev 91824)
@@ -1,3 +1,19 @@
+2011-07-26 Mark Hahnenberg <[email protected]>
+
+ reduce and reduceRight bind callback's this to null rather than undefined
+ https://bugs.webkit.org/show_bug.cgi?id=62264
+
+ Reviewed by Oliver Hunt.
+
+ Added additional tests to test Array.prototype.reduce and Array.prototype.reduceRight
+ when calling the callback function without an argument for this, which means it should
+ be undefined according to ES 15.4.4.21 and 15.4.4.22.
+
+ * fast/js/array-reduce-expected.txt:
+ * fast/js/array-reduceRight-expected.txt:
+ * fast/js/script-tests/array-reduce.js:
+ * fast/js/script-tests/array-reduceRight.js:
+
2011-07-26 Sheriff Bot <[email protected]>
Unreviewed, rolling out r91805.
Modified: trunk/LayoutTests/fast/js/array-reduce-expected.txt (91823 => 91824)
--- trunk/LayoutTests/fast/js/array-reduce-expected.txt 2011-07-27 03:48:27 UTC (rev 91823)
+++ trunk/LayoutTests/fast/js/array-reduce-expected.txt 2011-07-27 06:02:54 UTC (rev 91824)
@@ -33,6 +33,7 @@
PASS toUnorderedObject([[0,1], [2,3], [4,5]]).reduce(function(a,b) {return a.concat(b);}, []) is [0,1,2,3,4,5]
PASS toUnorderedObject([0,1,2,3,4,5]).reduce(function(a,b,i) {return a.concat([i,b]);}, []) is [0,0,1,1,2,2,3,3,4,4,5,5]
PASS [0,1,2,3,4,5].reduce(function(a,b,i) {return a.concat([i,b]);}, []) is [0,0,1,1,2,2,3,3,4,4,5,5]
+PASS [2,3].reduce(function() {'use strict'; return this;}) is undefined
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/fast/js/array-reduceRight-expected.txt (91823 => 91824)
--- trunk/LayoutTests/fast/js/array-reduceRight-expected.txt 2011-07-27 03:48:27 UTC (rev 91823)
+++ trunk/LayoutTests/fast/js/array-reduceRight-expected.txt 2011-07-27 06:02:54 UTC (rev 91824)
@@ -34,6 +34,7 @@
PASS toUnorderedObject([[0,1], [2,3], [4,5]]).reduceRight(function(a,b) {return a.concat(b);}, []) is [4,5,2,3,0,1]
PASS toUnorderedObject([0,1,2,3,4,5]).reduceRight(function(a,b,i) {return a.concat([i,b]);}, []) is [5,5,4,4,3,3,2,2,1,1,0,0]
PASS [0,1,2,3,4,5].reduceRight(function(a,b,i) {return a.concat([i,b]);}, []) is [5,5,4,4,3,3,2,2,1,1,0,0]
+PASS [2,3].reduceRight(function() {'use strict'; return this;}) is undefined
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/fast/js/script-tests/array-reduce.js (91823 => 91824)
--- trunk/LayoutTests/fast/js/script-tests/array-reduce.js 2011-07-27 03:48:27 UTC (rev 91823)
+++ trunk/LayoutTests/fast/js/script-tests/array-reduce.js 2011-07-27 06:02:54 UTC (rev 91824)
@@ -65,4 +65,5 @@
shouldBe("toUnorderedObject([[0,1], [2,3], [4,5]]).reduce(function(a,b) {return a.concat(b);}, [])", "[0,1,2,3,4,5]");
shouldBe("toUnorderedObject([0,1,2,3,4,5]).reduce(function(a,b,i) {return a.concat([i,b]);}, [])", "[0,0,1,1,2,2,3,3,4,4,5,5]");
shouldBe("[0,1,2,3,4,5].reduce(function(a,b,i) {return a.concat([i,b]);}, [])", "[0,0,1,1,2,2,3,3,4,4,5,5]");
+shouldBe("[2,3].reduce(function() {'use strict'; return this;})", "undefined");
successfullyParsed = true;
Modified: trunk/LayoutTests/fast/js/script-tests/array-reduceRight.js (91823 => 91824)
--- trunk/LayoutTests/fast/js/script-tests/array-reduceRight.js 2011-07-27 03:48:27 UTC (rev 91823)
+++ trunk/LayoutTests/fast/js/script-tests/array-reduceRight.js 2011-07-27 06:02:54 UTC (rev 91824)
@@ -67,4 +67,5 @@
shouldBe("toUnorderedObject([[0,1], [2,3], [4,5]]).reduceRight(function(a,b) {return a.concat(b);}, [])", "[4,5,2,3,0,1]");
shouldBe("toUnorderedObject([0,1,2,3,4,5]).reduceRight(function(a,b,i) {return a.concat([i,b]);}, [])", "[5,5,4,4,3,3,2,2,1,1,0,0]");
shouldBe("[0,1,2,3,4,5].reduceRight(function(a,b,i) {return a.concat([i,b]);}, [])", "[5,5,4,4,3,3,2,2,1,1,0,0]");
+shouldBe("[2,3].reduceRight(function() {'use strict'; return this;})", "undefined");
successfullyParsed = true;
Modified: trunk/Source/_javascript_Core/ChangeLog (91823 => 91824)
--- trunk/Source/_javascript_Core/ChangeLog 2011-07-27 03:48:27 UTC (rev 91823)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-07-27 06:02:54 UTC (rev 91824)
@@ -1,3 +1,18 @@
+2011-07-26 Mark Hahnenberg <[email protected]>
+
+ reduce and reduceRight bind callback's this to null rather than undefined
+ https://bugs.webkit.org/show_bug.cgi?id=62264
+
+ Reviewed by Oliver Hunt.
+
+ Fixed Array.prototype.reduce and Array.prototype.reduceRight so that they behave correctly
+ when calling the callback function without an argument for this, which means it should
+ be undefined according to ES 15.4.4.21 and 15.4.4.22.
+
+ * runtime/ArrayPrototype.cpp:
+ (JSC::arrayProtoFuncReduce):
+ (JSC::arrayProtoFuncReduceRight):
+
2011-07-26 Filip Pizlo <[email protected]>
JSC command-line tool does not come with any facility for
Modified: trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp (91823 => 91824)
--- trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2011-07-27 03:48:27 UTC (rev 91823)
+++ trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2011-07-27 06:02:54 UTC (rev 91824)
@@ -981,7 +981,7 @@
if (callType == CallTypeJS && array) {
CachedCall cachedCall(exec, asFunction(function), 4);
for (; i < length && !exec->hadException(); ++i) {
- cachedCall.setThis(jsNull());
+ cachedCall.setThis(jsUndefined());
cachedCall.setArgument(0, rv);
JSValue v;
if (LIKELY(array->canGetIndex(i)))
@@ -1010,7 +1010,7 @@
eachArguments.append(jsNumber(i));
eachArguments.append(thisObj);
- rv = call(exec, function, callType, callData, jsNull(), eachArguments);
+ rv = call(exec, function, callType, callData, jsUndefined(), eachArguments);
}
return JSValue::encode(rv);
}
@@ -1057,7 +1057,7 @@
CachedCall cachedCall(exec, asFunction(function), 4);
for (; i < length && !exec->hadException(); ++i) {
unsigned idx = length - i - 1;
- cachedCall.setThis(jsNull());
+ cachedCall.setThis(jsUndefined());
cachedCall.setArgument(0, rv);
if (UNLIKELY(!array->canGetIndex(idx)))
break; // length has been made unsafe while we enumerate fallback to slow path
@@ -1084,7 +1084,7 @@
eachArguments.append(jsNumber(idx));
eachArguments.append(thisObj);
- rv = call(exec, function, callType, callData, jsNull(), eachArguments);
+ rv = call(exec, function, callType, callData, jsUndefined(), eachArguments);
}
return JSValue::encode(rv);
}