mirror of https://github.com/tc39/test262.git
Map.property.forEach
This commit is contained in:
parent
ad60436658
commit
a31a62fcc8
|
@ -0,0 +1,44 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Verify the parameters order on the given callback.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
map.set('foo', 42);
|
||||||
|
map.set('bar', 'baz');
|
||||||
|
|
||||||
|
var results = [];
|
||||||
|
|
||||||
|
var callback = function(value, key, thisArg) {
|
||||||
|
results.push({
|
||||||
|
value: value,
|
||||||
|
key: key,
|
||||||
|
thisArg: thisArg
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
map.forEach(callback);
|
||||||
|
|
||||||
|
assert.sameValue(results[0].value, 42);
|
||||||
|
assert.sameValue(results[0].key, 'foo');
|
||||||
|
assert.sameValue(results[0].thisArg, map);
|
||||||
|
|
||||||
|
assert.sameValue(results[1].value, 'baz');
|
||||||
|
assert.sameValue(results[1].key, 'bar');
|
||||||
|
assert.sameValue(results[1].thisArg, map);
|
||||||
|
|
||||||
|
assert.sameValue(results.length, 2);
|
|
@ -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.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Returns error from callback result is abrupt.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
ii. ReturnIfAbrupt(funcResult).
|
||||||
|
...
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map([[0, 0]]);
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
map.forEach(function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
If a thisArg is not provided, undefined will be used as the this value for
|
||||||
|
each invocation of callbackfn.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
...
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var _this = [];
|
||||||
|
var map = new Map();
|
||||||
|
|
||||||
|
map.set(0, 0);
|
||||||
|
map.set(1, 1);
|
||||||
|
map.set(2, 2);
|
||||||
|
|
||||||
|
map.forEach(function() {
|
||||||
|
_this.push(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(_this[0], this);
|
||||||
|
assert.sameValue(_this[1], this);
|
||||||
|
assert.sameValue(_this[2], this);
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
If a thisArg is not provided, undefined will be used as the this value for
|
||||||
|
each invocation of callbackfn.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
...
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var _this = [];
|
||||||
|
var map = new Map();
|
||||||
|
|
||||||
|
map.set(0, 0);
|
||||||
|
map.set(1, 1);
|
||||||
|
map.set(2, 2);
|
||||||
|
|
||||||
|
map.forEach(function() {
|
||||||
|
_this.push(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(_this[0], undefined);
|
||||||
|
assert.sameValue(_this[1], undefined);
|
||||||
|
assert.sameValue(_this[2], undefined);
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Map state with deleted values during forEach.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
ii. ReturnIfAbrupt(funcResult).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
map.set('foo', 0);
|
||||||
|
map.set('bar', 1);
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
var results = [];
|
||||||
|
|
||||||
|
map.forEach(function(value, key) {
|
||||||
|
if (count === 0) {
|
||||||
|
map.delete('bar');
|
||||||
|
}
|
||||||
|
results.push({
|
||||||
|
value: value,
|
||||||
|
key: key
|
||||||
|
});
|
||||||
|
count++;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(results.length, 1);
|
||||||
|
assert.sameValue(results[0].key, 'foo');
|
||||||
|
assert.sameValue(results[0].value, 0);
|
24
test/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js
vendored
Normal file
24
test/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js
vendored
Normal file
|
@ -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.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` is a Set object.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If M does not have a [[MapData]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
features: [Set]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call(new Set(), function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var m = new Map();
|
||||||
|
m.forEach.call(new Set(), function() {});
|
||||||
|
});
|
24
test/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js
vendored
Normal file
24
test/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js
vendored
Normal file
|
@ -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.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` is a WeakMap object.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If M does not have a [[MapData]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
features: [WeakMap]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call(new WeakMap(), function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var m = new Map();
|
||||||
|
m.forEach.call(new WeakMap(), function() {});
|
||||||
|
});
|
|
@ -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.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` object does not have a [[MapData]] internal slot.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If M does not have a [[MapData]] internal slot, throw a TypeError
|
||||||
|
exception.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var m = new Map();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call([], function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
m.forEach.call([], function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call({}, function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
m.forEach.call({}, function() {});
|
||||||
|
});
|
|
@ -0,0 +1,43 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if first argument is not callable.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
4. If IsCallable(callbackfn) is false, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
map.forEach({});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
map.forEach([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
map.forEach(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
map.forEach('');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
map.forEach(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
map.forEach(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
map.forEach(Symbol());
|
||||||
|
});
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Property type and descriptor.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
typeof Map.prototype.forEach,
|
||||||
|
'function',
|
||||||
|
'`typeof Map.prototype.forEach` is `function`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Map.prototype, 'forEach');
|
||||||
|
verifyWritable(Map.prototype, 'forEach');
|
||||||
|
verifyConfigurable(Map.prototype, 'forEach');
|
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Repeats for each non-empty record, in original key insertion order.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map([
|
||||||
|
['foo', 'valid foo'],
|
||||||
|
['bar', false],
|
||||||
|
['baz', 'valid baz']
|
||||||
|
]);
|
||||||
|
map.set(0, false);
|
||||||
|
map.set(1, false);
|
||||||
|
map.set(2, 'valid 2');
|
||||||
|
map.delete(1);
|
||||||
|
map.delete('bar');
|
||||||
|
|
||||||
|
// Not setting a new key, just changing the value
|
||||||
|
map.set(0, 'valid 0');
|
||||||
|
|
||||||
|
var results = [];
|
||||||
|
var callback = function(value) {
|
||||||
|
results.push(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
map.forEach(callback);
|
||||||
|
|
||||||
|
assert.sameValue(results[0], 'valid foo');
|
||||||
|
assert.sameValue(results[1], 'valid baz');
|
||||||
|
assert.sameValue(results[2], 'valid 0');
|
||||||
|
assert.sameValue(results[3], 'valid 2');
|
||||||
|
assert.sameValue(results.length, 4);
|
||||||
|
|
||||||
|
map.clear();
|
||||||
|
results = [];
|
||||||
|
|
||||||
|
map.forEach(callback);
|
||||||
|
assert.sameValue(results.length, 0);
|
49
test/built-ins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js
vendored
Normal file
49
test/built-ins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js
vendored
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
New keys are visited if created during forEach execution.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
ii. ReturnIfAbrupt(funcResult).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
map.set('foo', 0);
|
||||||
|
map.set('bar', 1);
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
var results = [];
|
||||||
|
|
||||||
|
map.forEach(function(value, key) {
|
||||||
|
if (count === 0) {
|
||||||
|
map.set('baz', 2);
|
||||||
|
}
|
||||||
|
results.push({
|
||||||
|
value: value,
|
||||||
|
key: key
|
||||||
|
});
|
||||||
|
count++;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(count, 3);
|
||||||
|
assert.sameValue(map.size, 3);
|
||||||
|
|
||||||
|
assert.sameValue(results[0].key, 'foo');
|
||||||
|
assert.sameValue(results[0].value, 0);
|
||||||
|
|
||||||
|
assert.sameValue(results[1].key, 'bar');
|
||||||
|
assert.sameValue(results[1].value, 1);
|
||||||
|
|
||||||
|
assert.sameValue(results[2].key, 'baz');
|
||||||
|
assert.sameValue(results[2].value, 2);
|
50
test/built-ins/Map/prototype/forEach/iterates-values-deleted-then-readded.js
vendored
Normal file
50
test/built-ins/Map/prototype/forEach/iterates-values-deleted-then-readded.js
vendored
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
New keys are visited if created during forEach execution.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
ii. ReturnIfAbrupt(funcResult).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
map.set('foo', 0);
|
||||||
|
map.set('bar', 1);
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
var results = [];
|
||||||
|
|
||||||
|
map.forEach(function(value, key) {
|
||||||
|
if (count === 0) {
|
||||||
|
map.delete('foo');
|
||||||
|
map.set('foo', 'baz');
|
||||||
|
}
|
||||||
|
results.push({
|
||||||
|
value: value,
|
||||||
|
key: key
|
||||||
|
});
|
||||||
|
count++;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(count, 3);
|
||||||
|
assert.sameValue(map.size, 2);
|
||||||
|
|
||||||
|
assert.sameValue(results[0].key, 'foo');
|
||||||
|
assert.sameValue(results[0].value, 0);
|
||||||
|
|
||||||
|
assert.sameValue(results[1].key, 'bar');
|
||||||
|
assert.sameValue(results[1].value, 1);
|
||||||
|
|
||||||
|
assert.sameValue(results[2].key, 'foo');
|
||||||
|
assert.sameValue(results[2].value, 'baz');
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Map.prototype.forEach.length value and descriptor.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Map.prototype.forEach.length, 1,
|
||||||
|
'The value of `Map.prototype.forEach.length` is `1`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Map.prototype.forEach, 'length');
|
||||||
|
verifyNotWritable(Map.prototype.forEach, 'length');
|
||||||
|
verifyConfigurable(Map.prototype.forEach, 'length');
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Map.prototype.forEach.name value and descriptor.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Map.prototype.forEach.name, 'forEach',
|
||||||
|
'The value of `Map.prototype.forEach.name` is `"forEach"`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Map.prototype.forEach, 'name');
|
||||||
|
verifyNotWritable(Map.prototype.forEach, 'name');
|
||||||
|
verifyConfigurable(Map.prototype.forEach, 'name');
|
|
@ -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.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Returns undefined.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Return undefined.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
|
||||||
|
var result = map.forEach(function() {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, undefined, 'Empty map#forEach returns undefined');
|
||||||
|
|
||||||
|
map.set(1, 1);
|
||||||
|
result = map.forEach(function() {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, undefined, 'map#forEach returns undefined');
|
37
test/built-ins/Map/prototype/forEach/second-parameter-as-callback-context.js
vendored
Normal file
37
test/built-ins/Map/prototype/forEach/second-parameter-as-callback-context.js
vendored
Normal file
|
@ -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.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
If a thisArg parameter is provided, it will be used as the this value for each
|
||||||
|
invocation of callbackfn.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||||
|
6. Let entries be the List that is the value of M’s [[MapData]] internal slot.
|
||||||
|
7. Repeat for each Record {[[key]], [[value]]} e that is an element of
|
||||||
|
entries, in original key insertion order
|
||||||
|
a. If e.[[key]] is not empty, then
|
||||||
|
i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var expectedThis = {};
|
||||||
|
var _this = [];
|
||||||
|
|
||||||
|
var map = new Map();
|
||||||
|
map.set(0, 0);
|
||||||
|
map.set(1, 1);
|
||||||
|
map.set(2, 2);
|
||||||
|
|
||||||
|
var callback = function() {
|
||||||
|
_this.push(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
map.forEach(callback, expectedThis);
|
||||||
|
|
||||||
|
assert.sameValue(_this[0], expectedThis);
|
||||||
|
assert.sameValue(_this[1], expectedThis);
|
||||||
|
assert.sameValue(_this[2], expectedThis);
|
|
@ -0,0 +1,43 @@
|
||||||
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 23.1.3.5
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if `this` is not an Object.
|
||||||
|
info: >
|
||||||
|
Map.prototype.forEach ( callbackfn [ , thisArg ] )
|
||||||
|
|
||||||
|
1. Let M be the this value.
|
||||||
|
2. If Type(M) is not Object, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call(false, function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call(1, function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call('', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call(undefined, function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call(null, function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Map.prototype.forEach.call(Symbol(), function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var map = new Map();
|
||||||
|
map.forEach.call(false, function() {});
|
||||||
|
});
|
Loading…
Reference in New Issue