diff --git a/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.js b/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..93d71a75d8ea02ff3bae0a3a296dfb7410832ab7 --- /dev/null +++ b/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.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. +/*--- +es6id: 23.1.3.8 +description: > + Throws a TypeError if `this` is a Set object. +info: > + Map.prototype.keys () + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 2. If map does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.keys.call(new Set()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.keys.call(new Set()); +}); diff --git a/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.js b/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..7ed7992d9016f1436d7591a2cd9ccae22ee47a95 --- /dev/null +++ b/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.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. +/*--- +es6id: 23.1.3.8 +description: > + Throws a TypeError if `this` is a WeakMap object. +info: > + Map.prototype.keys () + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 2. If map does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.keys.call(new WeakMap()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.keys.call(new WeakMap()); +}); diff --git a/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js b/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..9ee5cc471aab73e899bc0094759f08b2eee687bc --- /dev/null +++ b/test/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,38 @@ +// 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.8 +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: > + Map.prototype.keys () + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 2. If map does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... + +---*/ + +var m = new Map(); + +assert.throws(TypeError, function() { + Map.prototype.keys.call([]); +}); + +assert.throws(TypeError, function() { + m.keys.call([]); +}); + +assert.throws(TypeError, function() { + Map.prototype.keys.call({}); +}); + +assert.throws(TypeError, function() { + m.keys.call({}); +}); diff --git a/test/built-ins/Map/prototype/keys/keys.js b/test/built-ins/Map/prototype/keys/keys.js new file mode 100644 index 0000000000000000000000000000000000000000..3405754e9b0f768cde264f8818508ab5d9cf6364 --- /dev/null +++ b/test/built-ins/Map/prototype/keys/keys.js @@ -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.8 +description: > + Property type and descriptor. +info: > + Map.prototype.keys () + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.keys, + 'function', + '`typeof Map.prototype.keys` is `function`' +); + +verifyNotEnumerable(Map.prototype, 'keys'); +verifyWritable(Map.prototype, 'keys'); +verifyConfigurable(Map.prototype, 'keys'); diff --git a/test/built-ins/Map/prototype/keys/length.js b/test/built-ins/Map/prototype/keys/length.js new file mode 100644 index 0000000000000000000000000000000000000000..485c1322641d3dda4282b2105a2b3632d71b1e13 --- /dev/null +++ b/test/built-ins/Map/prototype/keys/length.js @@ -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.8 +description: > + Map.prototype.keys.length value and descriptor. +info: > + Map.prototype.keys () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.keys.length, 0, + 'The value of `Map.prototype.keys.length` is `0`' +); + +verifyNotEnumerable(Map.prototype.keys, 'length'); +verifyNotWritable(Map.prototype.keys, 'length'); +verifyConfigurable(Map.prototype.keys, 'length'); diff --git a/test/built-ins/Map/prototype/keys/name.js b/test/built-ins/Map/prototype/keys/name.js new file mode 100644 index 0000000000000000000000000000000000000000..c5464b0912cc41f6c0865f8db35bca3c3d93d22a --- /dev/null +++ b/test/built-ins/Map/prototype/keys/name.js @@ -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.8 +description: > + Map.prototype.keys.name value and descriptor. +info: > + Map.prototype.keys () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.keys.name, 'keys', + 'The value of `Map.prototype.keys.name` is `"keys"`' +); + +verifyNotEnumerable(Map.prototype.keys, 'name'); +verifyNotWritable(Map.prototype.keys, 'name'); +verifyConfigurable(Map.prototype.keys, 'name'); diff --git a/test/built-ins/Map/prototype/keys/returns-iterator-empty.js b/test/built-ins/Map/prototype/keys/returns-iterator-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..08618c34bdca149f8e8cf639b3d4bff656688ec4 --- /dev/null +++ b/test/built-ins/Map/prototype/keys/returns-iterator-empty.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. +/*--- +es6id: 23.1.3.8 +description: > + Returns an iterator on an empty Map object. +info: > + Map.prototype.keys () + + ... + 2. Return CreateMapIterator(M, "key"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new Map(); +var iterator = map.keys(); +var result = iterator.next(); + +assert.sameValue( + result.value, undefined, + 'The value of `result.value` is `undefined`' +); +assert.sameValue(result.done, true, 'The value of `result.done` is `true`'); diff --git a/test/built-ins/Map/prototype/keys/returns-iterator.js b/test/built-ins/Map/prototype/keys/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..786284b32076041758dbea1360b9690e7e7c3fa0 --- /dev/null +++ b/test/built-ins/Map/prototype/keys/returns-iterator.js @@ -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.8 +description: > + Returns an iterator. +info: > + Map.prototype.keys ( ) + + ... + 2. Return CreateMapIterator(M, "key"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var obj = {}; +var map = new Map(); +map.set('foo', 1); +map.set(obj, 2); +map.set(map, 3); + +var iterator = map.keys(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 'foo', 'First result `value` ("key")'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, obj, 'Second result `value` ("key")'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, map, 'Third result `value` ("key")'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/built-ins/Map/prototype/keys/this-not-object-throw.js b/test/built-ins/Map/prototype/keys/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..1b81e80ebaeb0e868852f56728a7426d5291ddb9 --- /dev/null +++ b/test/built-ins/Map/prototype/keys/this-not-object-throw.js @@ -0,0 +1,47 @@ +// 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.8 +description: > + Throws a TypeError if `this` is not an Object. +info: > + Map.prototype.keys () + + ... + 2. Return CreateMapIterator(M, "key"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + 1. If Type(map) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.keys.call(false); +}); + +assert.throws(TypeError, function() { + Map.prototype.keys.call(1); +}); + +assert.throws(TypeError, function() { + Map.prototype.keys.call(''); +}); + +assert.throws(TypeError, function() { + Map.prototype.keys.call(undefined); +}); + +assert.throws(TypeError, function() { + Map.prototype.keys.call(null); +}); + +assert.throws(TypeError, function() { + Map.prototype.keys.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var map = new Map(); + map.keys.call(false); +});