Index: test/mjsunit/array-iteration.js |
diff --git a/test/mjsunit/array-iteration.js b/test/mjsunit/array-iteration.js |
index d11f984bee43be0a7e54794c52d2e05421bd74bb..7186194b765798c211b6b07d02d2031b121b1949 100644 |
--- a/test/mjsunit/array-iteration.js |
+++ b/test/mjsunit/array-iteration.js |
@@ -68,6 +68,23 @@ |
assertEquals(3, count); |
for (var i in a) assertEquals(2, a[i]); |
+ // When evaluating 'this', primitive values should be coerced to an object. |
wingo
2014/09/23 18:39:01
previous comment was more correct -- the wrapper h
Diego Pino
2014/09/24 10:13:01
Acknowledged.
|
+ // See ECMA-262, Annex C. |
+ a = []; |
+ [1, 2].filter(function() { a.push(this) }, ""); |
+ assertTrue(a[0] !== a[1]); |
+ |
+ // When evaluating 'this', non-primitive values are not coerced to an object. |
+ a = []; |
+ [1, 2].filter(function() { a.push(this) }, {}); |
+ assertFalse(a[0] !== a[1]); |
+ |
+ // In strict mode, when evaluating 'this', primitive values should not be |
+ // coerced to an object. |
+ a = []; |
+ [1, 2].filter(function() { 'use strict'; a.push(this); }, ""); |
wingo
2014/09/23 18:39:01
great test.
|
+ assertTrue(a[0] === "" && a[0] === a[1]); |
+ |
})(); |
@@ -109,6 +126,23 @@ |
a.forEach(function(n) { count++; }); |
assertEquals(1, count); |
+ // When evaluating 'this', primitive values should be coerced to an object. |
+ // See ECMA-262, Annex C. |
+ a = []; |
+ [1, 2].forEach(function() { a.push(this) }, ""); |
+ assertTrue(a[0] !== a[1]); |
+ |
+ // When evaluating 'this', non-primitive values are not coerced to an object. |
+ a = []; |
+ [1, 2].forEach(function() { a.push(this) }, {}); |
+ assertFalse(a[0] !== a[1]); |
+ |
+ // In strict mode, when evaluating 'this', primitive values should not be |
+ // coerced to an object. |
+ a = []; |
+ [1, 2].forEach(function() { 'use strict'; a.push(this); }, ""); |
+ assertTrue(a[0] === "" && a[0] === a[1]); |
+ |
})(); |
@@ -149,6 +183,23 @@ |
assertTrue(a.every(function(n) { count++; return n == 2; })); |
assertEquals(2, count); |
+ // When evaluating 'this', primitive values should be coerced to an object. |
+ // See ECMA-262, Annex C. |
+ a = []; |
+ [1, 2].every(function() { a.push(this); return true; }, ""); |
+ assertTrue(a[0] !== a[1]); |
+ |
+ // When evaluating 'this', non-primitive values are not coerced to an object. |
+ a = []; |
+ [1, 2].every(function() { a.push(this); return true; }, {}); |
+ assertFalse(a[0] !== a[1]); |
+ |
+ // In strict mode, when evaluating 'this', primitive values should not be |
+ // coerced to an object. |
+ a = []; |
+ [1, 2].every(function() { 'use strict'; a.push(this); return true; }, ""); |
+ assertTrue(a[0] === "" && a[0] === a[1]); |
+ |
})(); |
// |
@@ -186,6 +237,23 @@ |
a = a.map(function(n) { return 2*n; }); |
for (var i in a) assertEquals(4, a[i]); |
+ // When evaluating 'this', primitive values should be coerced to an object. |
+ // See ECMA-262, Annex C. |
+ a = []; |
+ [1, 2].map(function() { a.push(this) }, ""); |
+ assertTrue(a[0] !== a[1]); |
+ |
+ // When evaluating 'this', non-primitive values are not coerced to an object. |
+ a = []; |
+ [1, 2].map(function() { a.push(this) }, {}); |
+ assertFalse(a[0] !== a[1]); |
+ |
+ // In strict mode, when evaluating 'this', primitive values should not be |
+ // coerced to an object. |
+ a = []; |
+ [1, 2].map(function() { 'use strict'; a.push(this); }, ""); |
+ assertTrue(a[0] === "" && a[0] === a[1]); |
+ |
})(); |
// |
@@ -224,4 +292,21 @@ |
assertTrue(a.some(function(n) { count++; return n == 2; })); |
assertEquals(2, count); |
+ // When evaluating 'this', primitive values should be coerced to an object. |
+ // See ECMA-262, Annex C. |
+ a = []; |
+ [1, 2].some(function() { a.push(this) }, ""); |
+ assertTrue(a[0] !== a[1]); |
+ |
+ // When evaluating 'this', non-primitive values are not coerced to an object. |
+ a = []; |
+ [1, 2].some(function() { a.push(this) }, {}); |
+ assertFalse(a[0] !== a[1]); |
+ |
+ // In strict mode, when evaluating 'this', primitive values should not be |
+ // coerced to an object. |
+ a = []; |
+ [1, 2].some(function() { 'use strict'; a.push(this); }, ""); |
+ assertTrue(a[0] === "" && a[0] === a[1]); |
+ |
})(); |