Skip to content
Snippets Groups Projects
Commit a321e87a authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Add tests for `for..of` iteration over built-ins

parent 42d16da9
No related branches found
No related tags found
No related merge requests found
Showing
with 614 additions and 0 deletions
// 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);
// 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 instances should be able to be traversed using a `for..of` loop.
features: [TypedArray]
---*/
var iterationCount = 0;
var array = new Int8Array([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) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Map entry removal and re-insertion during traversal using for..of
info: >
Entries removed from a Map instance during traversal should be visited if
they are re-inserted prior to iterator exhaustion.
es6id: 13.6.4
features: [Map]
---*/
var map = new Map();
var iterationCount = 0;
var first = [0, 'a'];
var second = [1, 'b'];
map.set(0, 'a');
map.set(1, 'b');
for (var x of map) {
assert.sameValue(x[0], first[0]);
assert.sameValue(x[1], first[1]);
first = second;
second = null;
if (first !== null) {
map.delete(1);
map.set(1, 'b');
}
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: >
Entries removed from a Map instance during traversal should not be visited.
es6id: 13.6.4
features: [Map]
---*/
var map = new Map();
var iterationCount = 0;
map.set(0, 'a');
map.set(1, 'b');
for (var x of map) {
assert.sameValue(x[0], 0);
assert.sameValue(x[1], 'a');
map.delete(1);
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: Map entry insertion during traversal using for..of
info: >
New entries inserted into a Map instance during traversal should not be
visited if they are removed prior to visitation.
es6id: 13.6.4
features: [Map]
---*/
var map = new Map();
var iterationCount = 0;
map.set(0, 'a');
for (var x of map) {
assert.sameValue(x[0], 0);
assert.sameValue(x[1], 'a');
map.set(1, 'b');
map.delete(1);
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: Map entry insertion during traversal using for..of
info: >
New entries inserted into a Map instance during traversal should be
visited.
es6id: 13.6.4
features: [Map]
---*/
var map = new Map();
var iterationCount = 0;
var first = [0, 'a'];
var second = [1, 'b'];
map.set(0, 'a');
for (var x of map) {
assert.sameValue(x[0], first[0]);
assert.sameValue(x[1], first[1]);
first = second;
second = null;
map.set(1, 'b');
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: Map traversal using for..of
info: >
Map instances should be able to be traversed using a `for...of` loop.
es6id: 13.6.4
features: [Map]
---*/
var map = new Map();
var obj = {};
var iterationCount = 0;
var first = [0, 'a'];
var second = [true, false];
var third = [null, undefined];
var fourth = [NaN, obj];
map.set(0, 'a');
map.set(true, false);
map.set(null, undefined);
map.set(NaN, obj);
for (var x of map) {
assert.sameValue(x[0], first[0]);
assert.sameValue(x[1], first[1]);
first = second;
second = third;
third = fourth;
fourth = null;
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