Skip to content
Snippets Groups Projects
Commit da374700 authored by Brian Terlson's avatar Brian Terlson
Browse files

Merge pull request #308 from bocoup/for-of-built-ins

Add tests for `for..of` iteration over built-ins
parents 55740e93 92a735da
No related branches found
No related tags found
No related merge requests found
Showing
with 519 additions and 9 deletions
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
/*--- /*---
es6id: 13.6.4 es6id: 13.6.4
description: > description: >
Arguments objects should be able to be traversed using a `for..of` loop, Mapped arguments object mutation via alias during traversal using for..of
and dynamic changes to their contents should be reflected in the iterated info: >
values. "Mapped" arguments objects should be able to be traversed using a `for..of`
loop, and dynamic changes to the formal parameters should be reflected in
the iterated values.
flags: [noStrict] flags: [noStrict]
---*/ ---*/
......
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
es6id: 13.6.4 es6id: 13.6.4
description: > description: Mapped arguments object mutation during traversal using for..of
Arguments objects should be able to be traversed using a `for..of` loop, info: >
and dynamic changes to their contents should be reflected in the iterated "Mapped" arguments objects should be able to be traversed using a `for..of`
values. loop, and dynamic changes to their contents should be reflected in the
iterated values.
flags: [noStrict]
---*/ ---*/
var expected = [1, 4, 6]; var expected = [1, 4, 6];
......
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
es6id: 13.6.4 es6id: 13.6.4
description: > description: Mapped arguments object traversal using for..of
Arguments objects should be able to be traversed using a `for..of` loop. info: >
"Mapped" arguments objects should be able to be traversed using a `for..of`
loop.
flags: [noStrict]
---*/ ---*/
var i = 0; var i = 0;
......
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: >
Unmapped arguments object mutation via alias during traversal using for..of
info: >
"Unmapped" arguments objects should be able to be traversed using a
`for..of` loop, and dynamic changes to the formal parameters should not be
reflected in the iterated values.
flags: [noStrict]
---*/
var expected = [1, 2, 3];
var i = 0;
(function(a, b, c) {
'use strict';
for (var value of arguments) {
a = b;
b = c;
c = i;
assert.sameValue(value, expected[i], 'argument at index ' + i);
i++;
}
}(1, 2, 3));
assert.sameValue(i, 3, 'Visits all arguments');
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Unmapped arguments object mutation during traversal using for..of
info: >
"Unmapped" arguments objects should be able to be traversed using a
`for..of` loop, and dynamic changes to their contents should be reflected
in the iterated values.
flags: [noStrict]
---*/
var expected = [1, 4, 6];
var i = 0;
(function() {
'use strict';
for (var value of arguments) {
assert.sameValue(value, expected[i], 'argument at index ' + i);
i++;
arguments[i] *= 2;
}
}(1, 2, 3));
assert.sameValue(i, 3, 'Visits all arguments');
// Copyright (C) Copyright 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Unmapped arguments object traversal using for..of
info: >
"Umapped" arguments objects should be able to be traversed using a
`for..of` loop.
flags: [noStrict]
---*/
var i = 0;
(function() {
'use strict';
for (var value of arguments) {
assert.sameValue(value, arguments[i], 'argument at index ' + i);
i++;
}
}(0, 'a', true, false, null, undefined, NaN));
assert.sameValue(i, 7, 'Visits all arguments');
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Array entry removal and re-insertion during traversal using for..of
info: >
Entries removed from an Array instance during traversal should be visited
if they are re-inserted prior to iterator exhaustion.
es6id: 13.6.4
---*/
var array = [0, 1];
var iterationCount = 0;
var first = 0;
var second = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = null;
if (first !== null) {
array.pop();
array.push(1);
}
iterationCount += 1;
}
assert.sameValue(iterationCount, 2);
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Array entry removal during traversal using for..of
info:
Entries removed from an Array instance during traversal should not be
visited.
es6id: 13.6.4
---*/
var array = [0, 1];
var iterationCount = 0;
for (var x of array) {
assert.sameValue(x, 0);
array.pop();
iterationCount += 1;
}
assert.sameValue(iterationCount, 1);
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Array entry insertion and removal items during traversal using for..of
info: >
New entries inserted into an Array instance during traversal should not be
visited if they are removed prior to visitation.
es6id: 13.6.4
---*/
var array = [0];
var iterationCount = 0;
for (var x of array) {
assert.sameValue(x, 0);
array.push(1);
array.pop();
iterationCount += 1;
}
assert.sameValue(iterationCount, 1);
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Array entry insertion during traversal using for..of
info: >
New entries inserted into an Array instance during traversal should be
visited.
es6id: 13.6.4
---*/
var array = [0];
var iterationCount = 0;
var first = 0;
var second = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = null;
if (first !== null) {
array.push(1);
}
iterationCount += 1;
}
assert.sameValue(iterationCount, 2);
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Error in Array entry access during traversal using for..of
info: >
If retrieving an element from the array produces an error, that error
should be forwarded to the run time.
es6id: 13.6.4
---*/
var array = [];
var iterationCount = 0;
Object.defineProperty(array, '0', {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
for (var value of array) {
iterationCount += 1;
}
});
assert.sameValue(iterationCount, 0, 'The loop body is not evaluated');
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Float32Array mutation during traversal using for..of
info: >
Float32Array instances should be able to be traversed using a `for..of`
loop, and dynamic changes to their contents should be reflected in the
iterated values.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Float32Array([3, 2, 4, 1]);
var first = 3;
var second = 64;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
array[1] = 64;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Float32Array traversal using for..of
info: >
Float32Array instances should be able to be traversed using a `for..of`
loop.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Float32Array([3, 2, 4, 1]);
var first = 3;
var second = 2;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Float64Array mutation during traversal using for..of
info: >
Float64Array instances should be able to be traversed using a `for..of`
loop, and dynamic changes to their contents should be reflected in the
iterated values.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Float64Array([3, 2, 4, 1]);
var first = 3;
var second = 64;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
array[1] = 64;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Float64Array traversal using for..of
info: >
Float64Array instances should be able to be traversed using a `for..of`
loop.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Float64Array([3, 2, 4, 1]);
var first = 3;
var second = 2;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Int16Array mutation during traversal using for..of
info: >
Int16Array instances should be able to be traversed using a `for..of` loop,
and dynamic changes to their contents should be reflected in the iterated
values.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Int16Array([3, 2, 4, 1]);
var first = 3;
var second = 64;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
array[1] = 64;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: >
Int16Array instances should be able to be traversed using a `for..of` loop.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Int16Array([3, 2, 4, 1]);
var first = 3;
var second = 2;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Int32Array mutation during traversal using for..of
info: >
Int32Array instances should be able to be traversed using a `for..of` loop,
and dynamic changes to their contents should be reflected in the iterated
values.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Int32Array([3, 2, 4, 1]);
var first = 3;
var second = 64;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
array[1] = 64;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: >
Int32Array instances should be able to be traversed using a `for..of` loop.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Int32Array([3, 2, 4, 1]);
var first = 3;
var second = 2;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4
description: Int8Array mutation during traversal using for..of
info: >
Int8Array instances should be able to be traversed using a `for..of` loop,
and dynamic changes to their contents should be reflected in the iterated
values.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Int8Array([3, 2, 4, 1]);
var first = 3;
var second = 64;
var third = 4;
var fourth = 1;
for (var x of array) {
assert.sameValue(x, first);
first = second;
second = third;
third = fourth;
fourth = null;
array[1] = 64;
iterationCount += 1;
}
assert.sameValue(iterationCount, 4);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment