diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Map/prototype')
147 files changed, 3906 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator.js b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator.js new file mode 100644 index 0000000000..cd54db305b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator.js @@ -0,0 +1,21 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype-@@iterator +description: Initial state of the Symbol.iterator property +info: | + The initial value of the @@iterator property is the same function object as + the initial value of the entries property. + + Per ES6 section 17, the method should exist on the Array prototype, and it + should be writable and configurable, but not enumerable. +includes: [propertyHelper.js] +features: [Symbol.iterator] +---*/ + +assert.sameValue(Map.prototype[Symbol.iterator], Map.prototype.entries); +verifyNotEnumerable(Map.prototype, Symbol.iterator); +verifyWritable(Map.prototype, Symbol.iterator); +verifyConfigurable(Map.prototype, Symbol.iterator); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/browser.js b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/not-a-constructor.js new file mode 100644 index 0000000000..9a8bb37858 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype[Symbol.iterator] does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Symbol, Symbol.iterator, Map, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Map.prototype[Symbol.iterator]), + false, + 'isConstructor(Map.prototype[Symbol.iterator]) must return false' +); + +assert.throws(TypeError, () => { + let m = new Map(); new m[Symbol.iterator](); +}, '`let m = new Map(); new m[Symbol.iterator]()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/shell.js b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/Symbol.iterator/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/Map/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..a266290372 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/Symbol.toStringTag.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. +/*--- +esid: sec-map.prototype-@@tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "Map". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(Map.prototype[Symbol.toStringTag], 'Map'); + +verifyNotEnumerable(Map.prototype, Symbol.toStringTag); +verifyNotWritable(Map.prototype, Symbol.toStringTag); +verifyConfigurable(Map.prototype, Symbol.toStringTag); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/browser.js b/js/src/tests/test262/built-ins/Map/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/browser.js b/js/src/tests/test262/built-ins/Map/prototype/clear/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/clear-map.js b/js/src/tests/test262/built-ins/Map/prototype/clear/clear-map.js new file mode 100644 index 0000000000..5cd54d8873 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/clear-map.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. +/*--- +esid: sec-map.prototype.clear +description: > + Clears a Map. +info: | + Map.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. Set p.[[key]] to empty. + b. Set p.[[value]] to empty. + 6. Return undefined. +features: [Symbol] +---*/ + +var m1 = new Map([ + ['foo', 'bar'], + [1, 1] +]); +var m2 = new Map(); +var m3 = new Map(); +m2.set('foo', 'bar'); +m2.set(1, 1); +m2.set(Symbol('a'), Symbol('a')); + +m1.clear(); +m2.clear(); +m3.clear(); + +assert.sameValue(m1.size, 0); +assert.sameValue(m2.size, 0); +assert.sameValue(m3.size, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/clear.js b/js/src/tests/test262/built-ins/Map/prototype/clear/clear.js new file mode 100644 index 0000000000..3cc3a7f8bf --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/clear.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. +/*--- +esid: sec-map.prototype.clear +description: > + Map.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.clear, + 'function', + 'typeof Map.prototype.clear is "function"' +); + +verifyNotEnumerable(Map.prototype, 'clear'); +verifyWritable(Map.prototype, 'clear'); +verifyConfigurable(Map.prototype, 'clear'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-not-map-object.js b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-not-map-object.js new file mode 100644 index 0000000000..56a74bf165 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-not-map-object.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. +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` does not have a [[MapData]] internal slot. +info: | + Map.prototype.clear ( ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + Map.prototype.clear.call({}); +}); + +assert.throws(TypeError, function() { + Map.prototype.clear.call([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-not-object.js b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-not-object.js new file mode 100644 index 0000000000..c0403d2159 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-not-object.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` is not an Object. +info: | + Map.prototype.clear ( ) + + 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.clear.call(1); +}); + +assert.throws(TypeError, function() { + Map.prototype.clear.call(true); +}); + +assert.throws(TypeError, function() { + Map.prototype.clear.call(''); +}); + +assert.throws(TypeError, function() { + Map.prototype.clear.call(null); +}); + +assert.throws(TypeError, function() { + Map.prototype.clear.call(undefined); +}); + +assert.throws(TypeError, function() { + Map.prototype.clear.call(Symbol()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-set-object-throws.js b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-set-object-throws.js new file mode 100644 index 0000000000..e09a49314e --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-set-object-throws.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. +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` is a Set object. +info: | + Map.prototype.clear ( ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.clear.call(new Set()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.js new file mode 100644 index 0000000000..ab2097b38b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/context-is-weakmap-object-throws.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. +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + Map.prototype.clear ( ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.clear.call(new WeakMap()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/length.js b/js/src/tests/test262/built-ins/Map/prototype/clear/length.js new file mode 100644 index 0000000000..7cc8f3126f --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/length.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. +/*--- +esid: sec-map.prototype.clear +description: > + Map.prototype.clear.length value and descriptor. +info: | + Map.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.clear.length, 0, + 'The value of `Map.prototype.clear.length` is `0`' +); + +verifyNotEnumerable(Map.prototype.clear, 'length'); +verifyNotWritable(Map.prototype.clear, 'length'); +verifyConfigurable(Map.prototype.clear, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/map-data-list-is-preserved.js b/js/src/tests/test262/built-ins/Map/prototype/clear/map-data-list-is-preserved.js new file mode 100644 index 0000000000..269cecf346 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/map-data-list-is-preserved.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. +/*--- +esid: sec-map.prototype.clear +description: > + The existing [[MapData]] List is preserved. +info: | + The existing [[MapData]] List is preserved because there may be existing + MapIterator objects that are suspended midway through iterating over that + List. + + Map.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. Set p.[[key]] to empty. + b. Set p.[[value]] to empty. + 6. Return undefined. +---*/ + +var m = new Map([ + [1, 1], + [2, 2], + [3, 3] +]); +var e = m.entries(); + +e.next(); +m.clear(); + +var n = e.next(); +assert.sameValue(n.value, undefined); +assert.sameValue(n.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/name.js b/js/src/tests/test262/built-ins/Map/prototype/clear/name.js new file mode 100644 index 0000000000..0bef8b8fe7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/name.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. +/*--- +esid: sec-map.prototype.clear +description: > + Map.prototype.entries.name value and descriptor. +info: | + Map.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.clear.name, 'clear', + 'The value of `Map.prototype.clear.name` is `"clear"`' +); + +verifyNotEnumerable(Map.prototype.clear, 'name'); +verifyNotWritable(Map.prototype.clear, 'name'); +verifyConfigurable(Map.prototype.clear, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/clear/not-a-constructor.js new file mode 100644 index 0000000000..9567b58b7b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.clear does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue(isConstructor(Map.prototype.clear), false, 'isConstructor(Map.prototype.clear) must return false'); + +assert.throws(TypeError, () => { + let m = new Map(); new m.clear(); +}, '`let m = new Map(); new m.clear()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/returns-undefined.js b/js/src/tests/test262/built-ins/Map/prototype/clear/returns-undefined.js new file mode 100644 index 0000000000..396511db2f --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/returns-undefined.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. +/*--- +esid: sec-map.prototype.clear +description: > + Returns undefined. +info: | + Map.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. Set p.[[key]] to empty. + b. Set p.[[value]] to empty. + 6. Return undefined. +---*/ + +var m1 = new Map([ + ['foo', 'bar'], + [1, 1] +]); + +assert.sameValue(m1.clear(), undefined, 'clears a map and returns undefined'); +assert.sameValue(m1.clear(), undefined, 'returns undefined on an empty map'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/clear/shell.js b/js/src/tests/test262/built-ins/Map/prototype/clear/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/clear/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/constructor.js b/js/src/tests/test262/built-ins/Map/prototype/constructor.js new file mode 100644 index 0000000000..6e09bd7231 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/constructor.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map-constructor +description: Map.prototype.constructor value and descriptor +info: | + The initial value of Map.prototype.constructor is the intrinsic object %Map%. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Map.prototype.constructor, Map); +assert.sameValue((new Map()).constructor, Map); + +verifyNotEnumerable(Map.prototype, 'constructor'); +verifyWritable(Map.prototype, 'constructor'); +verifyConfigurable(Map.prototype, 'constructor'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/browser.js b/js/src/tests/test262/built-ins/Map/prototype/delete/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-not-map-object.js b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-not-map-object.js new file mode 100644 index 0000000000..310e802730 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-not-map-object.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. +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` does not have a [[MapData]] internal slot. +info: | + Map.prototype.delete ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + Map.prototype.delete.call({}, 'attr'); +}); + +assert.throws(TypeError, function() { + Map.prototype.delete.call([], 'attr'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-not-object.js b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-not-object.js new file mode 100644 index 0000000000..c2eaabf156 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-not-object.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` is not an Object. +info: | + Map.prototype.delete ( key ) + + 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.delete.call(1, 'attr'); +}); + +assert.throws(TypeError, function() { + Map.prototype.delete.call(true, 'attr'); +}); + +assert.throws(TypeError, function() { + Map.prototype.delete.call('', 'attr'); +}); + +assert.throws(TypeError, function() { + Map.prototype.delete.call(null, 'attr'); +}); + +assert.throws(TypeError, function() { + Map.prototype.delete.call(undefined, 'attr'); +}); + +assert.throws(TypeError, function() { + Map.prototype.delete.call(Symbol(), 'attr'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-set-object-throws.js b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-set-object-throws.js new file mode 100644 index 0000000000..152c54616d --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-set-object-throws.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. +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` is a Set object. +info: | + Map.prototype.delete ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.delete.call(new Set(), 'attr'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-weakmap-object-throws.js b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-weakmap-object-throws.js new file mode 100644 index 0000000000..ed9b730ba3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/context-is-weakmap-object-throws.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. +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + Map.prototype.delete ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.delete.call(new WeakMap(), 'attr'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/delete.js b/js/src/tests/test262/built-ins/Map/prototype/delete/delete.js new file mode 100644 index 0000000000..7aca1a2ff7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/delete.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. +/*--- +esid: sec-map.prototype.delete +description: > + Map.prototype.delete ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.delete, + 'function', + 'typeof Map.prototype.delete is "function"' +); + +verifyNotEnumerable(Map.prototype, 'delete'); +verifyWritable(Map.prototype, 'delete'); +verifyConfigurable(Map.prototype, 'delete'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/does-not-break-iterators.js b/js/src/tests/test262/built-ins/Map/prototype/delete/does-not-break-iterators.js new file mode 100644 index 0000000000..28e4a36512 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/does-not-break-iterators.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. +/*--- +esid: sec-map.prototype.delete +description: > + Deleting an entry does not break a [[MapData]] List. +info: | + Map.prototype.delete ( key ) + + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[key]] to empty. + ii. Set p.[[value]] to empty. + iii. Return true. + ... +---*/ + +var m = new Map([ + ['a', 1], + ['b', 2], + ['c', 3] +]); +var e = m.entries(); + +e.next(); +m.delete('b'); + +var n = e.next(); + +assert.sameValue(n.value[0], 'c'); +assert.sameValue(n.value[1], 3); + +n = e.next(); +assert.sameValue(n.value, undefined); +assert.sameValue(n.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/length.js b/js/src/tests/test262/built-ins/Map/prototype/delete/length.js new file mode 100644 index 0000000000..2be05ee2b1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/length.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. +/*--- +esid: sec-map.prototype.delete +description: > + Map.prototype.delete.length value and descriptor. +info: | + Map.prototype.delete ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.delete.length, 1, + 'The value of `Map.prototype.delete.length` is `1`' +); + +verifyNotEnumerable(Map.prototype.delete, 'length'); +verifyNotWritable(Map.prototype.delete, 'length'); +verifyConfigurable(Map.prototype.delete, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/name.js b/js/src/tests/test262/built-ins/Map/prototype/delete/name.js new file mode 100644 index 0000000000..dcacf4f3ee --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/name.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. +/*--- +esid: sec-map.prototype.delete +description: > + Map.prototype.delete.name value and descriptor. +info: | + Map.prototype.delete ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.delete.name, 'delete', + 'The value of `Map.prototype.delete.name` is `"delete"`' +); + +verifyNotEnumerable(Map.prototype.delete, 'name'); +verifyNotWritable(Map.prototype.delete, 'name'); +verifyConfigurable(Map.prototype.delete, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/delete/not-a-constructor.js new file mode 100644 index 0000000000..fb43d0a430 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.delete does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue(isConstructor(Map.prototype.delete), false, 'isConstructor(Map.prototype.delete) must return false'); + +assert.throws(TypeError, () => { + let m = new Map(); new m.delete(); +}, '`let m = new Map(); new m.delete()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/returns-false.js b/js/src/tests/test262/built-ins/Map/prototype/delete/returns-false.js new file mode 100644 index 0000000000..975d6e6ceb --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/returns-false.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. +/*--- +esid: sec-map.prototype.delete +description: > + Returns false when it does not delete an entry. +info: | + Map.prototype.delete ( key ) + + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + ... + iii. Return true. + 6. Return false. +---*/ + +var m = new Map([ + ['a', 1], + ['b', 2] +]); + +assert.sameValue(m.delete('not-in-the-map'), false); + +m.delete('a'); +assert.sameValue(m.delete('a'), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/returns-true-for-deleted-entry.js b/js/src/tests/test262/built-ins/Map/prototype/delete/returns-true-for-deleted-entry.js new file mode 100644 index 0000000000..11b6502121 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/returns-true-for-deleted-entry.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. +/*--- +esid: sec-map.prototype.delete +description: > + Returns true when deletes an entry. +info: | + Map.prototype.delete ( key ) + + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[key]] to empty. + ii. Set p.[[value]] to empty. + iii. Return true. + ... +---*/ + +var m = new Map([ + ['a', 1], + ['b', 2] +]); + +var result = m.delete('a'); + +assert(result); +assert.sameValue(m.size, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/delete/shell.js b/js/src/tests/test262/built-ins/Map/prototype/delete/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/delete/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/descriptor.js b/js/src/tests/test262/built-ins/Map/prototype/descriptor.js new file mode 100644 index 0000000000..6e4de86aff --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/descriptor.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype +description: Map.prototype property attributes. +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Map, 'prototype'); +verifyNotWritable(Map, 'prototype'); +verifyNotConfigurable(Map, 'prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/browser.js b/js/src/tests/test262/built-ins/Map/prototype/entries/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..d3b6325a6c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.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. +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` is a Set object. +info: | + Map.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key+value"). + + 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.entries.call(new Set()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.entries.call(new Set()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..87eb91ab40 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.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. +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + Map.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key+value"). + + 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.entries.call(new WeakMap()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.entries.call(new WeakMap()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..ce76b2353e --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: | + Map.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "key+value"). + + 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.entries.call([]); +}); + +assert.throws(TypeError, function() { + m.entries.call([]); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call({}); +}); + +assert.throws(TypeError, function() { + m.entries.call({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/entries.js b/js/src/tests/test262/built-ins/Map/prototype/entries/entries.js new file mode 100644 index 0000000000..c4a37be588 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/entries.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. +/*--- +esid: sec-map.prototype.entries +description: > + Property type and descriptor. +info: | + Map.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.entries, + 'function', + '`typeof Map.prototype.entries` is `function`' +); + +verifyNotEnumerable(Map.prototype, 'entries'); +verifyWritable(Map.prototype, 'entries'); +verifyConfigurable(Map.prototype, 'entries'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/length.js b/js/src/tests/test262/built-ins/Map/prototype/entries/length.js new file mode 100644 index 0000000000..593e918133 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/length.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. +/*--- +esid: sec-map.prototype.entries +description: > + Map.prototype.entries.length value and descriptor. +info: | + Map.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.entries.length, 0, + 'The value of `Map.prototype.entries.length` is `0`' +); + +verifyNotEnumerable(Map.prototype.entries, 'length'); +verifyNotWritable(Map.prototype.entries, 'length'); +verifyConfigurable(Map.prototype.entries, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/name.js b/js/src/tests/test262/built-ins/Map/prototype/entries/name.js new file mode 100644 index 0000000000..533b2fa97e --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/name.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. +/*--- +esid: sec-map.prototype.entries +description: > + Map.prototype.entries.name value and descriptor. +info: | + Map.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.entries.name, 'entries', + 'The value of `Map.prototype.entries.name` is `"entries"`' +); + +verifyNotEnumerable(Map.prototype.entries, 'name'); +verifyNotWritable(Map.prototype.entries, 'name'); +verifyConfigurable(Map.prototype.entries, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/entries/not-a-constructor.js new file mode 100644 index 0000000000..087ce39b98 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.entries does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Map.prototype.entries), + false, + 'isConstructor(Map.prototype.entries) must return false' +); + +assert.throws(TypeError, () => { + let m = new Map(); new m.entries(); +}, '`let m = new Map(); new m.entries()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/returns-iterator-empty.js b/js/src/tests/test262/built-ins/Map/prototype/entries/returns-iterator-empty.js new file mode 100644 index 0000000000..adda70f483 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/returns-iterator-empty.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. +/*--- +esid: sec-map.prototype.entries +description: > + Returns an iterator on an empty Map object. +info: | + Map.prototype.entries ( ) + + ... + 2. Return CreateMapIterator(M, "key+value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new Map(); +var iterator = map.entries(); +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`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/returns-iterator.js b/js/src/tests/test262/built-ins/Map/prototype/entries/returns-iterator.js new file mode 100644 index 0000000000..aeae3eb81b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/returns-iterator.js @@ -0,0 +1,57 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.entries +description: > + Returns an iterator. +info: | + Map.prototype.entries ( ) + + ... + 2. Return CreateMapIterator(M, "key+value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new Map(); +map.set('a',1); +map.set('b',2); +map.set('c',3); + +var iterator = map.entries(); +var result; + +result = iterator.next(); +assert.sameValue(result.value[0], 'a', 'First result `value` ("key")'); +assert.sameValue(result.value[1], 1, 'First result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 'b', 'Second result `value` ("key")'); +assert.sameValue(result.value[1], 2, 'Second result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Second result `value` (length)'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 'c', 'Third result `value` ("key")'); +assert.sameValue(result.value[1], 3, 'Third result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Third result `value` (length)'); +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)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/shell.js b/js/src/tests/test262/built-ins/Map/prototype/entries/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/entries/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/entries/this-not-object-throw.js new file mode 100644 index 0000000000..3b8144ef05 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/entries/this-not-object-throw.js @@ -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. +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` is not an Object. +info: | + Map.prototype.entries ( ) + + ... + 2. Return CreateSetIterator(M, "key+value"). + + 23.1.5.1 CreateSetIterator Abstract Operation + + 1. If Type(map) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.entries.call(false); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(1); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(''); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(undefined); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(null); +}); + +assert.throws(TypeError, function() { + Map.prototype.entries.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var map = new Map(); + map.entries.call(false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/browser.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-parameters.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-parameters.js new file mode 100644 index 0000000000..80120ec0f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-parameters.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. +/*--- +esid: sec-map.prototype.forEach +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-result-is-abrupt.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-result-is-abrupt.js new file mode 100644 index 0000000000..db210e806a --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-result-is-abrupt.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. +/*--- +esid: sec-map.prototype.forEach +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). + ... +---*/ + +var map = new Map([[0, 0]]); + +assert.throws(Test262Error, function() { + map.forEach(function() { + throw new Test262Error(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-this-non-strict.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-this-non-strict.js new file mode 100644 index 0000000000..d28c2691d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-this-non-strict.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. +/*--- +esid: sec-map.prototype.forEach +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-this-strict-strict.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-this-strict-strict.js new file mode 100644 index 0000000000..97abaf89b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/callback-this-strict-strict.js @@ -0,0 +1,38 @@ +'use strict'; +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/deleted-values-during-foreach.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/deleted-values-during-foreach.js new file mode 100644 index 0000000000..76498de300 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/deleted-values-during-foreach.js @@ -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. +/*--- +esid: sec-map.prototype.forEach +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..45dff89fd3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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() {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..f53d2ca50a --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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() {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..1f7f9c860c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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() {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/first-argument-is-not-callable.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/first-argument-is-not-callable.js new file mode 100644 index 0000000000..c88ef521af --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/first-argument-is-not-callable.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/forEach.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/forEach.js new file mode 100644 index 0000000000..20f4b5b758 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/forEach.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. +/*--- +esid: sec-map.prototype.forEach +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-in-key-insertion-order.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-in-key-insertion-order.js new file mode 100644 index 0000000000..24012f435b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-in-key-insertion-order.js @@ -0,0 +1,53 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js new file mode 100644 index 0000000000..f728b86d9b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js @@ -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. +/*--- +esid: sec-map.prototype.forEach +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-values-deleted-then-readded.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-values-deleted-then-readded.js new file mode 100644 index 0000000000..a0cce8e525 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/iterates-values-deleted-then-readded.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/length.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/length.js new file mode 100644 index 0000000000..d0e0c95dc8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/length.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. +/*--- +esid: sec-map.prototype.forEach +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/name.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/name.js new file mode 100644 index 0000000000..ea6f8c57fd --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/name.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. +/*--- +esid: sec-map.prototype.forEach +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/not-a-constructor.js new file mode 100644 index 0000000000..0a113f9d68 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.forEach does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Map.prototype.forEach), + false, + 'isConstructor(Map.prototype.forEach) must return false' +); + +assert.throws(TypeError, () => { + let m = new Map(); new m.forEach(); +}, '`let m = new Map(); new m.forEach()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/return-undefined.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/return-undefined.js new file mode 100644 index 0000000000..f3f2d3b2fd --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/return-undefined.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. +/*--- +esid: sec-map.prototype.forEach +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/second-parameter-as-callback-context.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/second-parameter-as-callback-context.js new file mode 100644 index 0000000000..16c5def0d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/second-parameter-as-callback-context.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/shell.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/forEach/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/forEach/this-not-object-throw.js new file mode 100644 index 0000000000..0e281c6585 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/forEach/this-not-object-throw.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.forEach +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() {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/browser.js b/js/src/tests/test262/built-ins/Map/prototype/get/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..05dd6be15b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` is a Set object. +info: | + Map.prototype.get ( key ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.get.call(new Set(), 1); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.get.call(new Set(), 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..618f1201df --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + Map.prototype.get ( key ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.get.call(new WeakMap(), 1); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.get.call(new WeakMap(), 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..1cc52a9e22 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: | + Map.prototype.get ( key ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var m = new Map(); + +assert.throws(TypeError, function() { + Map.prototype.get.call([], 1); +}); + +assert.throws(TypeError, function() { + m.get.call([], 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.get.call({}, 1); +}); + +assert.throws(TypeError, function() { + m.get.call({}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/get.js b/js/src/tests/test262/built-ins/Map/prototype/get/get.js new file mode 100644 index 0000000000..98525e8646 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/get.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. +/*--- +esid: sec-map.prototype.get +description: > + Property type and descriptor. +info: | + Map.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.get, + 'function', + '`typeof Map.prototype.get` is `function`' +); + +verifyNotEnumerable(Map.prototype, 'get'); +verifyWritable(Map.prototype, 'get'); +verifyConfigurable(Map.prototype, 'get'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/length.js b/js/src/tests/test262/built-ins/Map/prototype/get/length.js new file mode 100644 index 0000000000..4d6e66ffcb --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/length.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. +/*--- +esid: sec-map.prototype.get +description: > + Map.prototype.get.length value and descriptor. +info: | + Map.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.get.length, 1, + 'The value of `Map.prototype.get.length` is `1`' +); + +verifyNotEnumerable(Map.prototype.get, 'length'); +verifyNotWritable(Map.prototype.get, 'length'); +verifyConfigurable(Map.prototype.get, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/name.js b/js/src/tests/test262/built-ins/Map/prototype/get/name.js new file mode 100644 index 0000000000..ef63a260ee --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/name.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. +/*--- +esid: sec-map.prototype.get +description: > + Map.prototype.get.name value and descriptor. +info: | + Map.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.get.name, 'get', + 'The value of `Map.prototype.get.name` is `"get"`' +); + +verifyNotEnumerable(Map.prototype.get, 'name'); +verifyNotWritable(Map.prototype.get, 'name'); +verifyConfigurable(Map.prototype.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/get/not-a-constructor.js new file mode 100644 index 0000000000..9bc9b965e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.get does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue(isConstructor(Map.prototype.get), false, 'isConstructor(Map.prototype.get) must return false'); + +assert.throws(TypeError, () => { + let m = new Map(); new m.get(); +}, '`let m = new Map(); new m.get()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/returns-undefined.js b/js/src/tests/test262/built-ins/Map/prototype/get/returns-undefined.js new file mode 100644 index 0000000000..9af7162993 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/returns-undefined.js @@ -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. +/*--- +esid: sec-map.prototype.get +description: > + Returns undefined when key is not on the map. +info: | + Map.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return p.[[value]]. + 6. Return undefined. + ... +---*/ + +var map = new Map(); + +assert.sameValue( + map.get('item'), undefined, + 'returns undefined if key is not on the map' +); + +map.set('item', 1); +map.set('another_item', 2); +map.delete('item'); + +assert.sameValue( + map.get('item'), undefined, + 'returns undefined if key was deleted' +); + +map.set('item', 1); +map.clear(); + +assert.sameValue( + map.get('item'), undefined, + 'returns undefined after map is cleared' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/returns-value-different-key-types.js b/js/src/tests/test262/built-ins/Map/prototype/get/returns-value-different-key-types.js new file mode 100644 index 0000000000..b773a87e48 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/returns-value-different-key-types.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. +/*--- +esid: sec-map.prototype.get +description: > + Returns the value from the specified key on different types. +info: | + Map.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return p.[[value]]. + ... +features: [Symbol] +---*/ + +var map = new Map(); + +map.set('bar', 0); +assert.sameValue(map.get('bar'), 0); + +map.set(1, 42); +assert.sameValue(map.get(1), 42); + +map.set(NaN, 1); +assert.sameValue(map.get(NaN), 1); + +var item = {}; +map.set(item, 2); +assert.sameValue(map.get(item), 2); + +item = []; +map.set(item, 3); +assert.sameValue(map.get(item), 3); + +item = Symbol('item'); +map.set(item, 4); +assert.sameValue(map.get(item), 4); + +item = null; +map.set(item, 5); +assert.sameValue(map.get(item), 5); + +item = undefined; +map.set(item, 6); +assert.sameValue(map.get(item), 6); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js b/js/src/tests/test262/built-ins/Map/prototype/get/returns-value-normalized-zero-key.js new file mode 100644 index 0000000000..194b186002 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/returns-value-normalized-zero-key.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. +/*--- +esid: sec-map.prototype.get +description: > + -0 and +0 are normalized to +0; +info: | + Map.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[MapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return p.[[value]]. + ... +---*/ + +var map = new Map(); + +map.set(+0, 42); +assert.sameValue(map.get(-0), 42); + +map = new Map(); +map.set(-0, 43); +assert.sameValue(map.get(+0), 43); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/shell.js b/js/src/tests/test262/built-ins/Map/prototype/get/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/get/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/get/this-not-object-throw.js new file mode 100644 index 0000000000..46d5ea11af --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/get/this-not-object-throw.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` is not an Object. +info: | + Map.prototype.get ( key ) + + 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.get.call(false, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.get.call(1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.get.call('', 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.get.call(undefined, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.get.call(null, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.get.call(Symbol(), 1); +}); + +assert.throws(TypeError, function() { + var map = new Map(); + map.get.call(false, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/browser.js b/js/src/tests/test262/built-ins/Map/prototype/has/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..be7b3296ea --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` is a Set object. +info: | + Map.prototype.has ( key ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.has.call(new Set(), 1); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.has.call(new Set(), 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..d470bbdb8c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + Map.prototype.has ( key ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.has.call(new WeakMap(), 1); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.has.call(new WeakMap(), 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..77cb5284b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: | + Map.prototype.has ( key ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var m = new Map(); + +assert.throws(TypeError, function() { + Map.prototype.has.call([], 1); +}); + +assert.throws(TypeError, function() { + m.has.call([], 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.has.call({}, 1); +}); + +assert.throws(TypeError, function() { + m.has.call({}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/has.js b/js/src/tests/test262/built-ins/Map/prototype/has/has.js new file mode 100644 index 0000000000..0ff8d0b6eb --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/has.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. +/*--- +esid: sec-map.prototype.has +description: > + Property type and descriptor. +info: | + Map.prototype.has ( key ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.has, + 'function', + '`typeof Map.prototype.has` is `function`' +); + +verifyNotEnumerable(Map.prototype, 'has'); +verifyWritable(Map.prototype, 'has'); +verifyConfigurable(Map.prototype, 'has'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/length.js b/js/src/tests/test262/built-ins/Map/prototype/has/length.js new file mode 100644 index 0000000000..d5e9b5b48e --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/length.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. +/*--- +esid: sec-map.prototype.has +description: > + Map.prototype.has.length value and descriptor. +info: | + Map.prototype.has ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.has.length, 1, + 'The value of `Map.prototype.has.length` is `1`' +); + +verifyNotEnumerable(Map.prototype.has, 'length'); +verifyNotWritable(Map.prototype.has, 'length'); +verifyConfigurable(Map.prototype.has, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/name.js b/js/src/tests/test262/built-ins/Map/prototype/has/name.js new file mode 100644 index 0000000000..82e1dc3f01 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/name.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. +/*--- +esid: sec-map.prototype.has +description: > + Map.prototype.has.name value and descriptor. +info: | + Map.prototype.has ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.has.name, 'has', + 'The value of `Map.prototype.has.name` is `"has"`' +); + +verifyNotEnumerable(Map.prototype.has, 'name'); +verifyNotWritable(Map.prototype.has, 'name'); +verifyConfigurable(Map.prototype.has, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/normalizes-zero-key.js b/js/src/tests/test262/built-ins/Map/prototype/has/normalizes-zero-key.js new file mode 100644 index 0000000000..8bdc66d59c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/normalizes-zero-key.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. +/*--- +esid: sec-map.prototype.has +description: > + -0 and +0 are normalized to +0; +info: | + Map.prototype.has ( key ) + + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return true. + ... +---*/ + +var map = new Map(); + +assert.sameValue(map.has(-0), false); +assert.sameValue(map.has(+0), false); + +map.set(-0, 42); +assert.sameValue(map.has(-0), true); +assert.sameValue(map.has(+0), true); + +map.clear(); + +map.set(+0, 42); +assert.sameValue(map.has(-0), true); +assert.sameValue(map.has(+0), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/has/not-a-constructor.js new file mode 100644 index 0000000000..6f1d7d9253 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.has does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue(isConstructor(Map.prototype.has), false, 'isConstructor(Map.prototype.has) must return false'); + +assert.throws(TypeError, () => { + let m = new Map(); new m.has(); +}, '`let m = new Map(); new m.has()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/return-false-different-key-types.js b/js/src/tests/test262/built-ins/Map/prototype/has/return-false-different-key-types.js new file mode 100644 index 0000000000..a790c9964c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/return-false-different-key-types.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. +/*--- +esid: sec-map.prototype.has +description: > + Returns true for existing keys, using different key types. +info: | + Map.prototype.has ( key ) + + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + i. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return true. + ... +features: [Symbol] +---*/ + +var map = new Map(); + +assert.sameValue(map.has('str'), false); +assert.sameValue(map.has(1), false); +assert.sameValue(map.has(NaN), false); +assert.sameValue(map.has(true), false); +assert.sameValue(map.has(false), false); +assert.sameValue(map.has({}), false); +assert.sameValue(map.has([]), false); +assert.sameValue(map.has(Symbol()), false); +assert.sameValue(map.has(null), false); +assert.sameValue(map.has(undefined), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/return-true-different-key-types.js b/js/src/tests/test262/built-ins/Map/prototype/has/return-true-different-key-types.js new file mode 100644 index 0000000000..1d56cae345 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/return-true-different-key-types.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. +/*--- +esid: sec-map.prototype.has +description: > + Returns true for existing keys, using different key types. +info: | + Map.prototype.has ( key ) + + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + i. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return true. + ... +features: [Symbol] +---*/ + +var map = new Map(); + +var obj = {}; +var arr = []; +var symb = Symbol(); + +map.set('str', undefined); +map.set(1, undefined); +map.set(NaN, undefined); +map.set(true, undefined); +map.set(false, undefined); +map.set(obj, undefined); +map.set(arr, undefined); +map.set(symb, undefined); +map.set(null, undefined); +map.set(undefined, undefined); + +assert.sameValue(map.has('str'), true); +assert.sameValue(map.has(1), true); +assert.sameValue(map.has(NaN), true); +assert.sameValue(map.has(true), true); +assert.sameValue(map.has(false), true); +assert.sameValue(map.has(obj), true); +assert.sameValue(map.has(arr), true); +assert.sameValue(map.has(symb), true); +assert.sameValue(map.has(null), true); +assert.sameValue(map.has(undefined), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/shell.js b/js/src/tests/test262/built-ins/Map/prototype/has/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/has/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/has/this-not-object-throw.js new file mode 100644 index 0000000000..219a48a2ae --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/has/this-not-object-throw.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` is not an Object. +info: | + Map.prototype.has ( key ) + + 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.has.call(false, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.has.call(1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.has.call('', 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.has.call(undefined, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.has.call(null, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.has.call(Symbol(), 1); +}); + +assert.throws(TypeError, function() { + var map = new Map(); + map.has.call(false, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/browser.js b/js/src/tests/test262/built-ins/Map/prototype/keys/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..b32534b4a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.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. +/*--- +esid: sec-map.prototype.keys +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()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..b12d4c2a96 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.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. +/*--- +esid: sec-map.prototype.keys +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()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..7869123ad1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.keys +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({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/keys.js b/js/src/tests/test262/built-ins/Map/prototype/keys/keys.js new file mode 100644 index 0000000000..3ba771c735 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/keys.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. +/*--- +esid: sec-map.prototype.keys +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/length.js b/js/src/tests/test262/built-ins/Map/prototype/keys/length.js new file mode 100644 index 0000000000..6a5c19fd96 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/length.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. +/*--- +esid: sec-map.prototype.keys +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/name.js b/js/src/tests/test262/built-ins/Map/prototype/keys/name.js new file mode 100644 index 0000000000..ce3aa46661 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/name.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. +/*--- +esid: sec-map.prototype.keys +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/keys/not-a-constructor.js new file mode 100644 index 0000000000..be9835b84e --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.keys does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue(isConstructor(Map.prototype.keys), false, 'isConstructor(Map.prototype.keys) must return false'); + +assert.throws(TypeError, () => { + let m = new Map(); new m.keys(); +}, '`let m = new Map(); new m.keys()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/returns-iterator-empty.js b/js/src/tests/test262/built-ins/Map/prototype/keys/returns-iterator-empty.js new file mode 100644 index 0000000000..d00763f142 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/returns-iterator-empty.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. +/*--- +esid: sec-map.prototype.keys +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`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/returns-iterator.js b/js/src/tests/test262/built-ins/Map/prototype/keys/returns-iterator.js new file mode 100644 index 0000000000..4fbcff7d21 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/returns-iterator.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.keys +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)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/shell.js b/js/src/tests/test262/built-ins/Map/prototype/keys/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/keys/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/keys/this-not-object-throw.js new file mode 100644 index 0000000000..14fc88245d --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/keys/this-not-object-throw.js @@ -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. +/*--- +esid: sec-map.prototype.keys +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values-normalizes-zero-key.js b/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values-normalizes-zero-key.js new file mode 100644 index 0000000000..55122ae9ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values-normalizes-zero-key.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. +/*--- +esid: sec-map.prototype.set +description: > + Appends new value in the map normalizing +0 and -0. +info: | + Map.prototype.set ( key , value ) + + ... + 6. If key is −0, let key be +0. + 7. Let p be the Record {[[key]]: key, [[value]]: value}. + 8. Append p as the last element of entries. + 9. Return M. + ... +---*/ + +var map = new Map(); +map.set(-0, 42); + +assert.sameValue(map.get(0), 42); + +map = new Map(); +map.set(+0, 43); +assert.sameValue(map.get(0), 43); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values-return-map.js b/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values-return-map.js new file mode 100644 index 0000000000..a7c2008bab --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values-return-map.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. +/*--- +esid: sec-map.prototype.set +description: > + Map.prototype.set returns the given `this` object. +info: | + Map.prototype.set ( key , value ) + + ... + 6. If key is −0, let key be +0. + 7. Let p be the Record {[[key]]: key, [[value]]: value}. + 8. Append p as the last element of entries. + 9. Return M. + ... +---*/ + +var map = new Map(); +var result = map.set(1, 1); + +assert.sameValue(result, map); + +result = map.set(1,1).set(2,2).set(3,3); + +assert.sameValue(result, map, 'Map.prototype.set is chainable'); + +var map2 = new Map(); +result = map2.set.call(map, 4, 4); + +assert.sameValue(result, map); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values.js b/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values.js new file mode 100644 index 0000000000..f567db5d72 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/append-new-values.js @@ -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. +/*--- +esid: sec-map.prototype.set +description: > + Append a new value as the last element of entries. +info: | + Map.prototype.set ( key , value ) + + ... + 6. If key is −0, let key be +0. + 7. Let p be the Record {[[key]]: key, [[value]]: value}. + 8. Append p as the last element of entries. + 9. Return M. + ... +features: [Symbol] +---*/ + +var s = Symbol(2); +var map = new Map([[4, 4], ['foo3', 3], [s, 2]]); + +map.set(null, 42); +map.set(1, 'valid'); + +assert.sameValue(map.size, 5); +assert.sameValue(map.get(1), 'valid'); + +var results = []; + +map.forEach(function(value, key) { + results.push({ + value: value, + key: key + }); +}); + +var result = results.pop(); +assert.sameValue(result.value, 'valid'); +assert.sameValue(result.key, 1); + +result = results.pop(); +assert.sameValue(result.value, 42); +assert.sameValue(result.key, null); + +result = results.pop(); +assert.sameValue(result.value, 2); +assert.sameValue(result.key, s); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/browser.js b/js/src/tests/test262/built-ins/Map/prototype/set/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..9a80c6f6cf --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` is a Set object. +info: | + Map.prototype.set ( key , value ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.set.call(new Set(), 1, 1); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.set.call(new Set(), 1, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..cbabc7bab1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + Map.prototype.set ( key , value ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + Map.prototype.set.call(new WeakMap(), 1, 1); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.set.call(new WeakMap(), 1, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..ff591840b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: | + Map.prototype.set ( key , value ) + + ... + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var m = new Map(); + +assert.throws(TypeError, function() { + Map.prototype.set.call([], 1, 1); +}); + +assert.throws(TypeError, function() { + m.set.call([], 1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.set.call({}, 1, 1); +}); + +assert.throws(TypeError, function() { + m.set.call({}, 1, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/length.js b/js/src/tests/test262/built-ins/Map/prototype/set/length.js new file mode 100644 index 0000000000..939b633c34 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/length.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. +/*--- +esid: sec-map.prototype.set +description: > + Map.prototype.set.length value and descriptor. +info: | + Map.prototype.set ( key , value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.set.length, 2, + 'The value of `Map.prototype.set.length` is `2`' +); + +verifyNotEnumerable(Map.prototype.set, 'length'); +verifyNotWritable(Map.prototype.set, 'length'); +verifyConfigurable(Map.prototype.set, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/name.js b/js/src/tests/test262/built-ins/Map/prototype/set/name.js new file mode 100644 index 0000000000..7c0b83f696 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/name.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. +/*--- +esid: sec-map.prototype.set +description: > + Map.prototype.set.name value and descriptor. +info: | + Map.prototype.set ( key , value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.set.name, 'set', + 'The value of `Map.prototype.set.name` is `"set"`' +); + +verifyNotEnumerable(Map.prototype.set, 'name'); +verifyNotWritable(Map.prototype.set, 'name'); +verifyConfigurable(Map.prototype.set, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/set/not-a-constructor.js new file mode 100644 index 0000000000..2880254c25 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.set does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue(isConstructor(Map.prototype.set), false, 'isConstructor(Map.prototype.set) must return false'); + +assert.throws(TypeError, () => { + let m = new Map(); new m.set(); +}, '`let m = new Map(); new m.set()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value-normalizes-zero-key.js b/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value-normalizes-zero-key.js new file mode 100644 index 0000000000..6c4b708a16 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value-normalizes-zero-key.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. +/*--- +esid: sec-map.prototype.set +description: > + Replaces a value in the map normalizing +0 and -0. +info: | + Map.prototype.set ( key , value ) + + ... + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[value]] to value. + ii. Return M. + ... +---*/ + +var map = new Map([[+0, 1]]); + +map.set(-0, 42); +assert.sameValue(map.get(+0), 42, 'zero key is normalized in SameValueZero'); + +map = new Map([[-0, 1]]); +map.set(+0, 42); +assert.sameValue(map.get(-0), 42, 'zero key is normalized in SameValueZero'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value-returns-map.js b/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value-returns-map.js new file mode 100644 index 0000000000..b7f0e18909 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value-returns-map.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. +/*--- +esid: sec-map.prototype.set +description: > + Map.prototype.set returns the given `this` map object. +info: | + Map.prototype.set ( key , value ) + + 1. Let M be the this value. + ... + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[value]] to value. + ii. Return M. + ... +---*/ + +var map = new Map([['item', 0]]); +var map2 = new Map(); + +var x = map.set('item', 42); +assert.sameValue(x, map); + +x = Map.prototype.set.call(map, 'item', 0); +assert.sameValue(x, map); + +x = map2.set.call(map, 'item', 0); +assert.sameValue(x, map, 'Map#set returns the map `this` value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value.js b/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value.js new file mode 100644 index 0000000000..9fe4e95c3f --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/replaces-a-value.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. +/*--- +esid: sec-map.prototype.set +description: > + Replaces a value in the map. +info: | + Map.prototype.set ( key , value ) + + ... + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[value]] to value. + ii. Return M. + ... +---*/ + +var m = new Map([['item', 1]]); + +m.set('item', 42); +assert.sameValue(m.get('item'), 42); +assert.sameValue(m.size, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/set.js b/js/src/tests/test262/built-ins/Map/prototype/set/set.js new file mode 100644 index 0000000000..f8a12db779 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/set.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. +/*--- +esid: sec-map.prototype.set +description: > + Property type and descriptor. +info: | + Map.prototype.set ( key , value ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.set, + 'function', + '`typeof Map.prototype.set` is `function`' +); + +verifyNotEnumerable(Map.prototype, 'set'); +verifyWritable(Map.prototype, 'set'); +verifyConfigurable(Map.prototype, 'set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/shell.js b/js/src/tests/test262/built-ins/Map/prototype/set/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/set/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/set/this-not-object-throw.js new file mode 100644 index 0000000000..7f42b3e5ef --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/set/this-not-object-throw.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` is not an Object. +info: | + Map.prototype.set ( key , value ) + + 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.set.call(false, 1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.set.call(1, 1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.set.call('', 1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.set.call(undefined, 1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.set.call(null, 1, 1); +}); + +assert.throws(TypeError, function() { + Map.prototype.set.call(Symbol(), 1, 1); +}); + +assert.throws(TypeError, function() { + var map = new Map(); + map.set.call(false, 1, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/shell.js b/js/src/tests/test262/built-ins/Map/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/browser.js b/js/src/tests/test262/built-ins/Map/prototype/size/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..228d8068ba --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` is a Set object. +info: | + ... + If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +var map = new Map(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call(new Set()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..a2385ada8c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/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. +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + get Map.prototype.size + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +var map = new Map(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call(new WeakMap()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..00ba29073d --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/does-not-have-mapdata-internal-slot.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: | + get Map.prototype.size + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +var map = new Map(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/length.js b/js/src/tests/test262/built-ins/Map/prototype/size/length.js new file mode 100644 index 0000000000..b3812e1ec6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/length.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Map.prototype.size.length value and descriptor. +info: | + get Map.prototype.size + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.sameValue( + descriptor.get.length, 0, + 'The value of `Map.prototype.size.length` is `0`' +); + +verifyNotEnumerable(descriptor.get, 'length'); +verifyNotWritable(descriptor.get, 'length'); +verifyConfigurable(descriptor.get, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/name.js b/js/src/tests/test262/built-ins/Map/prototype/size/name.js new file mode 100644 index 0000000000..596e1a23c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/name.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Map.prototype.size.name value and descriptor. +info: | + get Map.prototype.size + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.sameValue(descriptor.get.name, + 'get size', + 'The value of `descriptor.get.name` is `get size`' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js new file mode 100644 index 0000000000..94316f9055 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values before and after using `set` and `clear`. +info: | + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +---*/ + +var map = new Map(); + +assert.sameValue(map.size, 0, 'The value of `map.size` is `0`'); + +map.set(1, 1); +map.set(2, 2); +assert.sameValue( + map.size, 2, + 'The value of `map.size` is `2`' +); + +map.clear(); +assert.sameValue( + map.size, 0, + 'The value of `map.size` is `0`, after executing `map.clear()`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js new file mode 100644 index 0000000000..3903b44033 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values before and after using `set` and `delete`. +info: | + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +---*/ + +var map = new Map(); + +assert.sameValue(map.size, 0, 'The value of `map.size` is `0`'); + +map.set(1, 1); +assert.sameValue( + map.size, 1, + 'The value of `map.size` is `1`, after executing `map.set(1, 1)`' +); + +map.delete(1); +assert.sameValue( + map.size, 0, + 'The value of `map.size` is `0`, after executing `map.delete(1)`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-by-insertion.js b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-by-insertion.js new file mode 100644 index 0000000000..f8dcb3497b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-by-insertion.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values inserted with set. +info: | + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +features: [Symbol] +---*/ + +var map = new Map(); + +map.set(0, undefined); +map.set(undefined, undefined); +map.set(false, undefined); +map.set(NaN, undefined); +map.set(null, undefined); +map.set('', undefined); +map.set(Symbol(), undefined); + +assert.sameValue(map.size, 7, 'The value of `map.size` is `7`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.js b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.js new file mode 100644 index 0000000000..f8ca96cf0b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/returns-count-of-present-values-by-iterable.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values inserted via iterable argument. +info: | + get Map.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +features: [Symbol] +---*/ + +var map = new Map([ + [0, undefined], + [undefined, undefined], + [false, undefined], + [NaN, undefined], + [null, undefined], + ['', undefined], + [Symbol(), undefined], +]); + +assert.sameValue(map.size, 7, 'The value of `map.size` is `7`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/shell.js b/js/src/tests/test262/built-ins/Map/prototype/size/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/size.js b/js/src/tests/test262/built-ins/Map/prototype/size/size.js new file mode 100644 index 0000000000..c13c0c58ac --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/size.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. +/*--- +esid: sec-get-map.prototype.size +description: > + Property type and descriptor. +info: | + get Map.prototype.size + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.sameValue( + typeof descriptor.get, + 'function', + 'typeof descriptor.get is function' +); +assert.sameValue( + typeof descriptor.set, + 'undefined', + 'typeof descriptor.set is undefined' +); + +verifyNotEnumerable(Map.prototype, 'size'); +verifyConfigurable(Map.prototype, 'size'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/size/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/size/this-not-object-throw.js new file mode 100644 index 0000000000..aa1f911dbc --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/size/this-not-object-throw.js @@ -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. +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` is not an Object. +info: | + get Map.prototype.size + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[MapData]] internal slot, throw a TypeError + exception. + ... + +features: [Symbol] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map.prototype, 'size'); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(false); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(''); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(undefined); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(null); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(Symbol()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/browser.js b/js/src/tests/test262/built-ins/Map/prototype/values/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/browser.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000..489e6b7331 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.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. +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` is a Set object. +info: | + Map.prototype.values () + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "value"). + + 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.values.call(new Set()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.values.call(new Set()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js b/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000..82f02364b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.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. +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + Map.prototype.values () + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "value"). + + 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.values.call(new WeakMap()); +}); + +assert.throws(TypeError, function() { + var m = new Map(); + m.values.call(new WeakMap()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot.js b/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000..65ea9ca971 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` object does not have a [[MapData]] internal slot. +info: | + Map.prototype.values () + + 1. Let M be the this value. + 2. Return CreateMapIterator(M, "value"). + + 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.values.call([]); +}); + +assert.throws(TypeError, function() { + m.values.call([]); +}); + +assert.throws(TypeError, function() { + Map.prototype.values.call({}); +}); + +assert.throws(TypeError, function() { + m.values.call({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/length.js b/js/src/tests/test262/built-ins/Map/prototype/values/length.js new file mode 100644 index 0000000000..304cdd7983 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/length.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. +/*--- +esid: sec-map.prototype.values +description: > + Map.prototype.values.length value and descriptor. +info: | + Map.prototype.values () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.values.length, 0, + 'The value of `Map.prototype.values.length` is `0`' +); + +verifyNotEnumerable(Map.prototype.values, 'length'); +verifyNotWritable(Map.prototype.values, 'length'); +verifyConfigurable(Map.prototype.values, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/name.js b/js/src/tests/test262/built-ins/Map/prototype/values/name.js new file mode 100644 index 0000000000..03827d01f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/name.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. +/*--- +esid: sec-map.prototype.values +description: > + Map.prototype.values.name value and descriptor. +info: | + Map.prototype.values () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Map.prototype.values.name, 'values', + 'The value of `Map.prototype.values.name` is `"values"`' +); + +verifyNotEnumerable(Map.prototype.values, 'name'); +verifyNotWritable(Map.prototype.values, 'name'); +verifyConfigurable(Map.prototype.values, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/not-a-constructor.js b/js/src/tests/test262/built-ins/Map/prototype/values/not-a-constructor.js new file mode 100644 index 0000000000..0fd6e656d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Map.prototype.values does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Map, arrow-function] +---*/ + +assert.sameValue(isConstructor(Map.prototype.values), false, 'isConstructor(Map.prototype.values) must return false'); + +assert.throws(TypeError, () => { + let m = new Map(); new m.values(); +}, '`let m = new Map(); new m.values()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/returns-iterator-empty.js b/js/src/tests/test262/built-ins/Map/prototype/values/returns-iterator-empty.js new file mode 100644 index 0000000000..990723ff87 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/returns-iterator-empty.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. +/*--- +esid: sec-map.prototype.values +description: > + Returns an iterator on an empty Map object. +info: | + Map.prototype.values () + + ... + 2. Return CreateMapIterator(M, "value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new Map(); +var iterator = map.values(); +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`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/returns-iterator.js b/js/src/tests/test262/built-ins/Map/prototype/values/returns-iterator.js new file mode 100644 index 0000000000..006b4975fc --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/returns-iterator.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.values +description: > + Returns an iterator. +info: | + Map.prototype.values ( ) + + ... + 2. Return CreateMapIterator(M, "value"). + + 23.1.5.1 CreateMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var obj = {}; +var map = new Map(); +map.set(1, 'foo'); +map.set(2, obj); +map.set(3, map); + +var iterator = map.values(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 'foo', 'First result `value` ("value")'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, obj, 'Second result `value` ("value")'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, map, 'Third result `value` ("value")'); +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)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/shell.js b/js/src/tests/test262/built-ins/Map/prototype/values/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/shell.js diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/this-not-object-throw.js b/js/src/tests/test262/built-ins/Map/prototype/values/this-not-object-throw.js new file mode 100644 index 0000000000..372aec3a02 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/this-not-object-throw.js @@ -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. +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` is not an Object. +info: | + Map.prototype.values () + + ... + 2. Return CreateMapIterator(M, "values"). + + 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.values.call(false); +}); + +assert.throws(TypeError, function() { + Map.prototype.values.call(1); +}); + +assert.throws(TypeError, function() { + Map.prototype.values.call(''); +}); + +assert.throws(TypeError, function() { + Map.prototype.values.call(undefined); +}); + +assert.throws(TypeError, function() { + Map.prototype.values.call(null); +}); + +assert.throws(TypeError, function() { + Map.prototype.values.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var map = new Map(); + map.values.call(false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype/values/values.js b/js/src/tests/test262/built-ins/Map/prototype/values/values.js new file mode 100644 index 0000000000..3ec0c35c6f --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype/values/values.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. +/*--- +esid: sec-map.prototype.values +description: > + Property type and descriptor. +info: | + Map.prototype.values () + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Map.prototype.values, + 'function', + '`typeof Map.prototype.values` is `function`' +); + +verifyNotEnumerable(Map.prototype, 'values'); +verifyWritable(Map.prototype, 'values'); +verifyConfigurable(Map.prototype, 'values'); + +reportCompare(0, 0); |