diff --git a/test/language/for-of/arguments-object-aliasing.js b/test/language/statements/for-of/arguments-mapped-aliasing.js similarity index 63% rename from test/language/for-of/arguments-object-aliasing.js rename to test/language/statements/for-of/arguments-mapped-aliasing.js index 8528e85224..c3c39154c5 100644 --- a/test/language/for-of/arguments-object-aliasing.js +++ b/test/language/statements/for-of/arguments-mapped-aliasing.js @@ -3,9 +3,11 @@ /*--- es6id: 13.6.4 description: > - 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. + Mapped arguments object mutation via alias during traversal using for..of +info: > + "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] ---*/ diff --git a/test/language/for-of/arguments-object-mutation.js b/test/language/statements/for-of/arguments-mapped-mutation.js similarity index 60% rename from test/language/for-of/arguments-object-mutation.js rename to test/language/statements/for-of/arguments-mapped-mutation.js index 6d9a0334ca..9191d4d827 100644 --- a/test/language/for-of/arguments-object-mutation.js +++ b/test/language/statements/for-of/arguments-mapped-mutation.js @@ -2,10 +2,12 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- es6id: 13.6.4 -description: > - 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. +description: Mapped arguments object mutation during traversal using for..of +info: > + "Mapped" 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]; diff --git a/test/language/for-of/arguments-object.js b/test/language/statements/for-of/arguments-mapped.js similarity index 69% rename from test/language/for-of/arguments-object.js rename to test/language/statements/for-of/arguments-mapped.js index 6c04da407f..58923c573a 100644 --- a/test/language/for-of/arguments-object.js +++ b/test/language/statements/for-of/arguments-mapped.js @@ -2,8 +2,11 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- es6id: 13.6.4 -description: > - Arguments objects should be able to be traversed using a `for..of` loop. +description: Mapped arguments object traversal using for..of +info: > + "Mapped" arguments objects should be able to be traversed using a `for..of` + loop. +flags: [noStrict] ---*/ var i = 0; diff --git a/test/language/statements/for-of/arguments-unmapped-aliasing.js b/test/language/statements/for-of/arguments-unmapped-aliasing.js new file mode 100644 index 0000000000..fac40f2ac7 --- /dev/null +++ b/test/language/statements/for-of/arguments-unmapped-aliasing.js @@ -0,0 +1,29 @@ +// 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'); diff --git a/test/language/statements/for-of/arguments-unmapped-mutation.js b/test/language/statements/for-of/arguments-unmapped-mutation.js new file mode 100644 index 0000000000..9c4f441ba7 --- /dev/null +++ b/test/language/statements/for-of/arguments-unmapped-mutation.js @@ -0,0 +1,25 @@ +// 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'); diff --git a/test/language/statements/for-of/arguments-unmapped.js b/test/language/statements/for-of/arguments-unmapped.js new file mode 100644 index 0000000000..21020a7af8 --- /dev/null +++ b/test/language/statements/for-of/arguments-unmapped.js @@ -0,0 +1,22 @@ +// 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'); diff --git a/test/language/statements/for-of/array-contract-expand.js b/test/language/statements/for-of/array-contract-expand.js new file mode 100644 index 0000000000..02da20ca10 --- /dev/null +++ b/test/language/statements/for-of/array-contract-expand.js @@ -0,0 +1,33 @@ +// 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); diff --git a/test/language/statements/for-of/array-contract.js b/test/language/statements/for-of/array-contract.js new file mode 100644 index 0000000000..b44a06f299 --- /dev/null +++ b/test/language/statements/for-of/array-contract.js @@ -0,0 +1,21 @@ +// 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); diff --git a/test/language/statements/for-of/array-expand-contract.js b/test/language/statements/for-of/array-expand-contract.js new file mode 100644 index 0000000000..990fccae9c --- /dev/null +++ b/test/language/statements/for-of/array-expand-contract.js @@ -0,0 +1,25 @@ +// 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); diff --git a/test/language/statements/for-of/array-expand.js b/test/language/statements/for-of/array-expand.js new file mode 100644 index 0000000000..ef39b62fd3 --- /dev/null +++ b/test/language/statements/for-of/array-expand.js @@ -0,0 +1,31 @@ +// 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); diff --git a/test/language/statements/for-of/array-key-get-error.js b/test/language/statements/for-of/array-key-get-error.js new file mode 100644 index 0000000000..eab5cf1cfd --- /dev/null +++ b/test/language/statements/for-of/array-key-get-error.js @@ -0,0 +1,27 @@ +// 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'); diff --git a/test/language/statements/for-of/float32array-mutate.js b/test/language/statements/for-of/float32array-mutate.js new file mode 100644 index 0000000000..a457b9fb2c --- /dev/null +++ b/test/language/statements/for-of/float32array-mutate.js @@ -0,0 +1,34 @@ +// 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); diff --git a/test/language/statements/for-of/float32array.js b/test/language/statements/for-of/float32array.js new file mode 100644 index 0000000000..16075f2ff3 --- /dev/null +++ b/test/language/statements/for-of/float32array.js @@ -0,0 +1,31 @@ +// 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); diff --git a/test/language/statements/for-of/float64array-mutate.js b/test/language/statements/for-of/float64array-mutate.js new file mode 100644 index 0000000000..adc9cb2e17 --- /dev/null +++ b/test/language/statements/for-of/float64array-mutate.js @@ -0,0 +1,34 @@ +// 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); diff --git a/test/language/statements/for-of/float64array.js b/test/language/statements/for-of/float64array.js new file mode 100644 index 0000000000..d69df76bf6 --- /dev/null +++ b/test/language/statements/for-of/float64array.js @@ -0,0 +1,31 @@ +// 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); diff --git a/test/language/statements/for-of/int16array-mutate.js b/test/language/statements/for-of/int16array-mutate.js new file mode 100644 index 0000000000..7851a9ee8c --- /dev/null +++ b/test/language/statements/for-of/int16array-mutate.js @@ -0,0 +1,34 @@ +// 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); diff --git a/test/language/statements/for-of/int16array.js b/test/language/statements/for-of/int16array.js new file mode 100644 index 0000000000..2eaa1f78cb --- /dev/null +++ b/test/language/statements/for-of/int16array.js @@ -0,0 +1,29 @@ +// 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); diff --git a/test/language/statements/for-of/int32array-mutate.js b/test/language/statements/for-of/int32array-mutate.js new file mode 100644 index 0000000000..e74481f3c0 --- /dev/null +++ b/test/language/statements/for-of/int32array-mutate.js @@ -0,0 +1,34 @@ +// 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); diff --git a/test/language/statements/for-of/int32array.js b/test/language/statements/for-of/int32array.js new file mode 100644 index 0000000000..d112a9a575 --- /dev/null +++ b/test/language/statements/for-of/int32array.js @@ -0,0 +1,29 @@ +// 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); diff --git a/test/language/statements/for-of/int8array-mutate.js b/test/language/statements/for-of/int8array-mutate.js new file mode 100644 index 0000000000..2482bbf2cf --- /dev/null +++ b/test/language/statements/for-of/int8array-mutate.js @@ -0,0 +1,34 @@ +// 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); diff --git a/test/language/statements/for-of/int8array.js b/test/language/statements/for-of/int8array.js new file mode 100644 index 0000000000..a40566fd0f --- /dev/null +++ b/test/language/statements/for-of/int8array.js @@ -0,0 +1,29 @@ +// 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); diff --git a/test/language/statements/for-of/map-contract-expand.js b/test/language/statements/for-of/map-contract-expand.js new file mode 100644 index 0000000000..dc5fad13ef --- /dev/null +++ b/test/language/statements/for-of/map-contract-expand.js @@ -0,0 +1,37 @@ +// 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); diff --git a/test/language/statements/for-of/map-contract.js b/test/language/statements/for-of/map-contract.js new file mode 100644 index 0000000000..7a54894bc6 --- /dev/null +++ b/test/language/statements/for-of/map-contract.js @@ -0,0 +1,24 @@ +// 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); diff --git a/test/language/statements/for-of/map-expand-contract.js b/test/language/statements/for-of/map-expand-contract.js new file mode 100644 index 0000000000..078f638bed --- /dev/null +++ b/test/language/statements/for-of/map-expand-contract.js @@ -0,0 +1,28 @@ +// 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); diff --git a/test/language/statements/for-of/map-expand.js b/test/language/statements/for-of/map-expand.js new file mode 100644 index 0000000000..e408f2dbe4 --- /dev/null +++ b/test/language/statements/for-of/map-expand.js @@ -0,0 +1,33 @@ +// 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); diff --git a/test/language/statements/for-of/map.js b/test/language/statements/for-of/map.js new file mode 100644 index 0000000000..d1d3482328 --- /dev/null +++ b/test/language/statements/for-of/map.js @@ -0,0 +1,36 @@ +// 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); diff --git a/test/language/statements/for-of/set-contract-expand.js b/test/language/statements/for-of/set-contract-expand.js new file mode 100644 index 0000000000..8c99cfaf54 --- /dev/null +++ b/test/language/statements/for-of/set-contract-expand.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Set entry removal and re-insertion during traversal using for..of +info: > + Entries removed from a Set instance during traversal should be visited if + they are re-inserted prior to iterator exhaustion. +es6id: 13.6.4 +features: [Set] +---*/ + +var set = new Set(); +var iterationCount = 0; + +var first = 0; +var second = 1; + +set.add(0); +set.add(1); + +for (var x of set) { + assert.sameValue(x, first); + + first = second; + second = null; + + if (first !== null) { + set.delete(1); + set.add(1); + } + + iterationCount += 1; +} + +assert.sameValue(iterationCount, 2); diff --git a/test/language/statements/for-of/set-contract.js b/test/language/statements/for-of/set-contract.js new file mode 100644 index 0000000000..98770ddfee --- /dev/null +++ b/test/language/statements/for-of/set-contract.js @@ -0,0 +1,23 @@ +// 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 Set instance during traversal should not be visited. +es6id: 13.6.4 +features: [Set] +---*/ + +var set = new Set(); +var iterationCount = 0; + +set.add(0); +set.add(1); + +for (var x of set) { + assert.sameValue(x, 0); + set.delete(1); + iterationCount += 1; +} + +assert.sameValue(iterationCount, 1); diff --git a/test/language/statements/for-of/set-expand-contract.js b/test/language/statements/for-of/set-expand-contract.js new file mode 100644 index 0000000000..5fa11fd8a2 --- /dev/null +++ b/test/language/statements/for-of/set-expand-contract.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Set entry insertion and removal during traversal using for..of +info: > + New entries inserted into a Set instance during traversal should not be + visited if they are removed prior to visitation. +es6id: 13.6.4 +features: [Set] +---*/ + +var set = new Set(); +var iterationCount = 0; + +set.add(0); + +for (var x of set) { + assert.sameValue(x, 0); + + set.add(1); + set.delete(1); + + iterationCount += 1; +} + +assert.sameValue(iterationCount, 1); diff --git a/test/language/statements/for-of/set-expand.js b/test/language/statements/for-of/set-expand.js new file mode 100644 index 0000000000..32eb4b8575 --- /dev/null +++ b/test/language/statements/for-of/set-expand.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Set entry insertaion during traversal using for..of +info: > + New entries inserted into a Set instance during traversal should be + visited. +es6id: 13.6.4 +features: [Set] +---*/ + +var set = new Set(); +var iterationCount = 0; + +var first = 0; +var second = 1; + +set.add(0); + +for (var x of set) { + assert.sameValue(x, first); + + first = second; + second = null; + + set.add(1); + + iterationCount += 1; +} + +assert.sameValue(iterationCount, 2); diff --git a/test/language/statements/for-of/set.js b/test/language/statements/for-of/set.js new file mode 100644 index 0000000000..658298e7c0 --- /dev/null +++ b/test/language/statements/for-of/set.js @@ -0,0 +1,46 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Set instances should be able to be traversed using a `for...of` loop. +es6id: 13.6.4 +features: [Set] +---*/ + +var set = new Set(); +var obj = {}; +var iterationCount = 0; + +var first = 0; +var second = 'a'; +var third = true; +var fourth = false; +var fifth = null; +var sixth = undefined; +var seventh = NaN; +var eight = obj; + +set.add(0); +set.add('a'); +set.add(true); +set.add(false); +set.add(null); +set.add(undefined); +set.add(NaN); +set.add(obj); + +for (var x of set) { + assert.sameValue(x, first); + first = second; + second = third; + third = fourth; + fourth = fifth; + fifth = sixth; + sixth = seventh; + seventh = eight; + eight = null; + iterationCount += 1; +} + +assert.sameValue(iterationCount, 8); diff --git a/test/language/statements/for-of/string-astral-truncated.js b/test/language/statements/for-of/string-astral-truncated.js new file mode 100644 index 0000000000..15124eff3b --- /dev/null +++ b/test/language/statements/for-of/string-astral-truncated.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: String traversal using for..of (incomplete surrogate pairs) +info: > + String literals should be able to be traversed using a `for...of` loop. The + loop body should execute once for each incomplete surrogate pair. +es6id: 13.6.4 +---*/ + +var string = 'a\ud801b\ud801'; +var first = 'a'; +var second = '\ud801'; +var third = 'b'; +var fourth = '\ud801'; + +var iterationCount = 0; + +for (var value of string) { + assert.sameValue(value, first); + first = second; + second = third; + third = fourth; + fourth = null; + iterationCount += 1; +} + +assert.sameValue(iterationCount, 4); diff --git a/test/language/statements/for-of/string-astral.js b/test/language/statements/for-of/string-astral.js new file mode 100644 index 0000000000..f9b2dd99ec --- /dev/null +++ b/test/language/statements/for-of/string-astral.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: String traversal using for..of (astral symbols) +info: > + String literals should be able to be traversed using a `for...of` loop. The + loop body should execute once for each astral symbol. +es6id: 13.6.4 +---*/ + +var string = 'a\ud801\udc28b\ud801\udc28'; +var first = 'a'; +var second = '𐐨'; +var third = 'b'; +var fourth = '𐐨'; + +var iterationCount = 0; + +for (var value of string) { + assert.sameValue(value, first); + first = second; + second = third; + third = fourth; + fourth = null; + iterationCount += 1; +} + +assert.sameValue(iterationCount, 4); diff --git a/test/language/statements/for-of/string-bmp.js b/test/language/statements/for-of/string-bmp.js new file mode 100644 index 0000000000..a00fc39258 --- /dev/null +++ b/test/language/statements/for-of/string-bmp.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: String traversal using for..of +info: > + String literals should be able to be traversed using a `for...of` loop. The + loop body should execute once for every BMP character. +es6id: 13.6.4 +---*/ + +var string = 'abc'; +var first = 'a'; +var second = 'b'; +var third = 'c'; + +var iterationCount = 0; + +for (var value of string) { + assert.sameValue(value, first); + first = second; + second = third; + third = null; + iterationCount += 1; +} + +assert.sameValue(iterationCount, 3); diff --git a/test/language/statements/for-of/uint16array-mutate.js b/test/language/statements/for-of/uint16array-mutate.js new file mode 100644 index 0000000000..d98c744e74 --- /dev/null +++ b/test/language/statements/for-of/uint16array-mutate.js @@ -0,0 +1,34 @@ +// 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: Uint16Array mutation during traversal using for..of +info: > + Uint16Array 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 Uint16Array([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); diff --git a/test/language/statements/for-of/uint16array.js b/test/language/statements/for-of/uint16array.js new file mode 100644 index 0000000000..db761c10a7 --- /dev/null +++ b/test/language/statements/for-of/uint16array.js @@ -0,0 +1,31 @@ +// 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: Uint16Array traversal using for..of +info: > + Uint16Array instances should be able to be traversed using a `for..of` + loop. +features: [TypedArray] +---*/ + +var iterationCount = 0; +var array = new Uint16Array([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); diff --git a/test/language/statements/for-of/uint32array-mutate.js b/test/language/statements/for-of/uint32array-mutate.js new file mode 100644 index 0000000000..8d6061b6e4 --- /dev/null +++ b/test/language/statements/for-of/uint32array-mutate.js @@ -0,0 +1,34 @@ +// 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: Uint32Array mutation during traversal using for..of +info: > + Uint32Array 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 Uint32Array([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); diff --git a/test/language/statements/for-of/uint32array.js b/test/language/statements/for-of/uint32array.js new file mode 100644 index 0000000000..6f82242f88 --- /dev/null +++ b/test/language/statements/for-of/uint32array.js @@ -0,0 +1,31 @@ +// 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: Uint32Array traversal using for..of +info: > + Uint32Array instances should be able to be traversed using a `for..of` + loop. +features: [TypedArray] +---*/ + +var iterationCount = 0; +var array = new Uint32Array([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); diff --git a/test/language/statements/for-of/uint8array-mutate.js b/test/language/statements/for-of/uint8array-mutate.js new file mode 100644 index 0000000000..6c5afd6f0b --- /dev/null +++ b/test/language/statements/for-of/uint8array-mutate.js @@ -0,0 +1,34 @@ +// 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: Uint8Array mutation during traversal using for..of +info: > + Uint8Array 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 Uint8Array([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); diff --git a/test/language/statements/for-of/uint8array.js b/test/language/statements/for-of/uint8array.js new file mode 100644 index 0000000000..ada57cd733 --- /dev/null +++ b/test/language/statements/for-of/uint8array.js @@ -0,0 +1,29 @@ +// 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: > + Uint8Array instances should be able to be traversed using a `for..of` loop. +features: [TypedArray] +---*/ + +var iterationCount = 0; +var array = new Uint8Array([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); diff --git a/test/language/statements/for-of/uint8clampedarray-mutate.js b/test/language/statements/for-of/uint8clampedarray-mutate.js new file mode 100644 index 0000000000..04aac964aa --- /dev/null +++ b/test/language/statements/for-of/uint8clampedarray-mutate.js @@ -0,0 +1,34 @@ +// 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: Uint8ClampedArray mutation during traversal using for..of +info: > + Uint8ClampedArray 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 Uint8ClampedArray([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); diff --git a/test/language/statements/for-of/uint8clampedarray.js b/test/language/statements/for-of/uint8clampedarray.js new file mode 100644 index 0000000000..12e0d01ceb --- /dev/null +++ b/test/language/statements/for-of/uint8clampedarray.js @@ -0,0 +1,30 @@ +// 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: > + Uint8ClampedArray instances should be able to be traversed using a + `for..of` loop. +features: [TypedArray] +---*/ + +var iterationCount = 0; +var array = new Uint8ClampedArray([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);