diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Map')
185 files changed, 5457 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Map/Symbol.species/browser.js b/js/src/tests/test262/built-ins/Map/Symbol.species/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/Symbol.species/browser.js diff --git a/js/src/tests/test262/built-ins/Map/Symbol.species/length.js b/js/src/tests/test262/built-ins/Map/Symbol.species/length.js new file mode 100644 index 0000000000..d606baeca6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/Symbol.species/length.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 23.1.2.2 +description: > + get Map [ @@species ].length is 0. +info: | + get Map [ @@species ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(Map, Symbol.species); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/Symbol.species/return-value.js b/js/src/tests/test262/built-ins/Map/Symbol.species/return-value.js new file mode 100644 index 0000000000..2698c6b964 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/Symbol.species/return-value.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-map-@@species +description: Return value of @@species accessor method +info: | + 1. Return the this value. +features: [Symbol.species] +---*/ + +var thisVal = {}; +var accessor = Object.getOwnPropertyDescriptor(Map, Symbol.species).get; + +assert.sameValue(accessor.call(thisVal), thisVal); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/Symbol.species/shell.js b/js/src/tests/test262/built-ins/Map/Symbol.species/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/Symbol.species/shell.js diff --git a/js/src/tests/test262/built-ins/Map/Symbol.species/symbol-species-name.js b/js/src/tests/test262/built-ins/Map/Symbol.species/symbol-species-name.js new file mode 100644 index 0000000000..926d6fb31f --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/Symbol.species/symbol-species-name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.1.2.2 +description: > + Map[Symbol.species] accessor property get name +info: | + 23.1.2.2 get Map [ @@species ] + + ... + The value of the name property of this function is "get [Symbol.species]". +features: [Symbol.species] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(Map, Symbol.species); + +assert.sameValue( + descriptor.get.name, + 'get [Symbol.species]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/Symbol.species/symbol-species.js b/js/src/tests/test262/built-ins/Map/Symbol.species/symbol-species.js new file mode 100644 index 0000000000..b3c7fa8742 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/Symbol.species/symbol-species.js @@ -0,0 +1,23 @@ +// Copyright 2015 Cubane Canada, Inc. All rights reserved. +// See LICENSE for details. + +/*--- +info: | + Map has a property at `Symbol.species` +esid: sec-get-map-@@species +author: Sam Mikes +description: Map[Symbol.species] exists per spec +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(Map, Symbol.species); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyNotWritable(Map, Symbol.species, Symbol.species); +verifyNotEnumerable(Map, Symbol.species); +verifyConfigurable(Map, Symbol.species); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/bigint-number-same-value.js b/js/src/tests/test262/built-ins/Map/bigint-number-same-value.js new file mode 100644 index 0000000000..783afd421b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/bigint-number-same-value.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.set +description: > + Observing the expected behavior of keys when a BigInt and Number have + the same value. +info: | + Map.prototype.set ( key , value ) + + ... + Let p be the Record {[[key]]: key, [[value]]: value}. + Append p as the last element of entries. + ... + +features: [BigInt] +---*/ + +const number = 9007199254740991; +const bigint = 9007199254740991n; + +const m = new Map([ + [number, number], + [bigint, bigint], +]); + +assert.sameValue(m.size, 2); +assert.sameValue(m.has(number), true); +assert.sameValue(m.has(bigint), true); + +assert.sameValue(m.get(number), number); +assert.sameValue(m.get(bigint), bigint); + +m.delete(number); +assert.sameValue(m.size, 1); +assert.sameValue(m.has(number), false); +m.delete(bigint); +assert.sameValue(m.size, 0); +assert.sameValue(m.has(bigint), false); + +m.set(number, number); +assert.sameValue(m.size, 1); +m.set(bigint, bigint); +assert.sameValue(m.size, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/browser.js b/js/src/tests/test262/built-ins/Map/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/browser.js diff --git a/js/src/tests/test262/built-ins/Map/constructor.js b/js/src/tests/test262/built-ins/Map/constructor.js new file mode 100644 index 0000000000..f37c74de67 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/constructor.js @@ -0,0 +1,12 @@ +// 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: > + The Map constructor is the %Map% intrinsic object and the initial value of the + Map property of the global object. +---*/ + +assert.sameValue(typeof Map, 'function', 'typeof Map is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/does-not-throw-when-set-is-not-callable.js b/js/src/tests/test262/built-ins/Map/does-not-throw-when-set-is-not-callable.js new file mode 100644 index 0000000000..9d758b0016 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/does-not-throw-when-set-is-not-callable.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-iterable +description: > + Creating a new Map object without arguments doesn't throw if `set` is not + callable +info: | + Map ( [ iterable ] ) + + When the Set function is called with optional argument iterable the following steps are taken: + + ... + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + 7. Else, + a. Let adder be Get(map, "set"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + ... + 8. If iter is undefined, return map. + ... +---*/ + +Map.prototype.set = null; + +var m = new Map(); + +assert.sameValue(m.size, 0, 'The value of `m.size` is `0`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/get-set-method-failure.js b/js/src/tests/test262/built-ins/Map/get-set-method-failure.js new file mode 100644 index 0000000000..978a6a3a27 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/get-set-method-failure.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-iterable +description: > + new Map returns abrupt from getting Map.prototype.set. +info: | + Map ( [ iterable ] ) + + ... + 7. Else, + a. Let adder be Get(map, "add"). + b. ReturnIfAbrupt(adder). +---*/ + +Object.defineProperty(Map.prototype, 'set', { + get: function() { + throw new Test262Error(); + } +}); + +new Map(); + +assert.throws(Test262Error, function() { + new Map([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/is-a-constructor.js b/js/src/tests/test262/built-ins/Map/is-a-constructor.js new file mode 100644 index 0000000000..6d119375f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/is-a-constructor.js @@ -0,0 +1,26 @@ +// 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: > + The Map constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, Map] +---*/ + +assert.sameValue(isConstructor(Map), true, 'isConstructor(Map) must return true'); +new Map(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterable-calls-set.js b/js/src/tests/test262/built-ins/Map/iterable-calls-set.js new file mode 100644 index 0000000000..26c58a78d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterable-calls-set.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map-iterable +description: > + new Map calls `set` for each item on the iterable argument in order. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + ... + k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»). + ... +includes: [compareArray.js] +---*/ + +var mapSet = Map.prototype.set; +var counter = 0; + +var iterable = [ + ["foo", 1], + ["bar", 2] +]; +var results = []; +var _this = []; + +Map.prototype.set = function(k, v) { + counter++; + results.push([k, v]); + _this.push(this); + mapSet.call(this, k, v); +}; + +var map = new Map(iterable); + +assert.sameValue(counter, 2, "`Map.prototype.set` called twice."); + +assert.compareArray(results[0], iterable[0]); +assert.compareArray(results[1], iterable[1]); +assert.sameValue(_this[0], map); +assert.sameValue(_this[1], map); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-close-after-set-failure.js b/js/src/tests/test262/built-ins/Map/iterator-close-after-set-failure.js new file mode 100644 index 0000000000..17645d1ccb --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-close-after-set-failure.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-iterable +description: > + The iterator is closed when `Map.prototype.set` throws an error. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + ... + k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»). + l. If status is an abrupt completion, return IteratorClose(iter, status). +features: [Symbol.iterator] +---*/ + +var count = 0; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: [], + done: false + }; + }, + return: function() { + count += 1; + } + }; +}; +Map.prototype.set = function() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + new Map(iterable); +}); + +assert.sameValue(count, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-close-failure-after-set-failure.js b/js/src/tests/test262/built-ins/Map/iterator-close-failure-after-set-failure.js new file mode 100644 index 0000000000..5986ccab3c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-close-failure-after-set-failure.js @@ -0,0 +1,29 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map-iterable +description: > + The correct error is thrown `Map.prototype.set` throws an error and + the IteratorClose throws an error. +features: [Symbol.iterator] +---*/ + +var count = 0; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { value: [], done: false }; + }, + return: function() { + throw new TypeError('ignore'); + } + }; +}; +Map.prototype.set = function() { throw new Test262Error(); } + +assert.throws(Test262Error, function() { + new Map(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-is-undefined-throws.js b/js/src/tests/test262/built-ins/Map/iterator-is-undefined-throws.js new file mode 100644 index 0000000000..f6a3c01bea --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-is-undefined-throws.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 Amal Hussein. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map-objects +description: > + Throws a TypeError if the iterator of the iterable is undefined. +info: | + Map ( [ iterable ] ) + ... + 9. Let iteratorRecord be ? GetIterator(iterable). +features: [Symbol.iterator] +---*/ + +var iterable = { [Symbol.iterator]: undefined }; + +assert.throws(TypeError, + function () { + new Map(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-item-first-entry-returns-abrupt.js b/js/src/tests/test262/built-ins/Map/iterator-item-first-entry-returns-abrupt.js new file mode 100644 index 0000000000..0f31104338 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-item-first-entry-returns-abrupt.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-iterable +description: > + Closes iterator if item first entry completes abruptly. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + ... + g. Let k be Get(nextItem, "0"). + h. If k is an abrupt completion, return IteratorClose(iter, k). + ... +features: [Symbol.iterator] +---*/ + +var count = 0; +var item = ['foo', 'bar']; +Object.defineProperty(item, 0, { + get: function() { + throw new Test262Error(); + } +}); +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: item, + done: false + }; + }, + return: function() { + count++; + } + }; +}; + +assert.throws(Test262Error, function() { + new Map(iterable); +}); + +assert.sameValue(count, 1, 'The get error closed the iterator'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-item-second-entry-returns-abrupt.js b/js/src/tests/test262/built-ins/Map/iterator-item-second-entry-returns-abrupt.js new file mode 100644 index 0000000000..b7eefd9891 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-item-second-entry-returns-abrupt.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-iterable +description: > + Closes iterator if item second entry completes abruptly. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + ... + i. Let v be Get(nextItem, "1"). + j. If v is an abrupt completion, return IteratorClose(iter, v). + ... +features: [Symbol.iterator] +---*/ + +var count = 0; +var item = ['foo', 'bar']; +Object.defineProperty(item, 1, { + get: function() { + throw new Test262Error(); + } +}); +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: item, + done: false + }; + }, + return: function() { + count++; + } + }; +}; + +assert.throws(Test262Error, function() { + new Map(iterable); +}); + +assert.sameValue(count, 1, 'The get error closed the iterator'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-items-are-not-object-close-iterator.js b/js/src/tests/test262/built-ins/Map/iterator-items-are-not-object-close-iterator.js new file mode 100644 index 0000000000..62d40c0bbf --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-items-are-not-object-close-iterator.js @@ -0,0 +1,77 @@ +// 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-iterable +description: > + Closes the iterator after `not Object` error. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + e. ReturnIfAbrupt(nextItem). + f. If Type(nextItem) is not Object, + i. Let error be Completion{[[type]]: throw, [[value]]: a newly created + TypeError object, [[target]]:empty}. + ii. Return IteratorClose(iter, error). +features: + - Symbol + - Symbol.iterator +---*/ + +var count = 0; +var nextItem; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: nextItem, + done: false + }; + }, + return: function() { + count += 1; + } + }; +}; + +nextItem = 1; +assert.throws(TypeError, function() { + new Map(iterable); +}); +assert.sameValue(count, 1); + +nextItem = true; +assert.throws(TypeError, function() { + new Map(iterable); +}); +assert.sameValue(count, 2); + +nextItem = ''; +assert.throws(TypeError, function() { + new Map(iterable); +}); +assert.sameValue(count, 3); + +nextItem = null; +assert.throws(TypeError, function() { + new Map(iterable); +}); +assert.sameValue(count, 4); + +nextItem = undefined; +assert.throws(TypeError, function() { + new Map(iterable); +}); +assert.sameValue(count, 5); + +nextItem = Symbol('a'); +assert.throws(TypeError, function() { + new Map(iterable); +}); +assert.sameValue(count, 6); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-items-are-not-object.js b/js/src/tests/test262/built-ins/Map/iterator-items-are-not-object.js new file mode 100644 index 0000000000..3dc770ae8d --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-items-are-not-object.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-iterable +description: > + Throws a TypeError if iterable items are not Objects. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + e. ReturnIfAbrupt(nextItem). + f. If Type(nextItem) is not Object, + i. Let error be Completion{[[type]]: throw, [[value]]: a newly created + TypeError object, [[target]]:empty}. + ii. Return IteratorClose(iter, error). +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + new Map([1]); +}); + +assert.throws(TypeError, function() { + new Map(['']); +}); + +assert.throws(TypeError, function() { + new Map([true]); +}); + +assert.throws(TypeError, function() { + new Map([null]); +}); + +assert.throws(TypeError, function() { + new Map([Symbol('a')]); +}); + +assert.throws(TypeError, function() { + new Map([undefined]); +}); + +assert.throws(TypeError, function() { + new Map([ + ['a', 1], + 2 + ]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-next-failure.js b/js/src/tests/test262/built-ins/Map/iterator-next-failure.js new file mode 100644 index 0000000000..a60349a5e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-next-failure.js @@ -0,0 +1,30 @@ +// 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-iterable +description: > + The iterator is closed when iterable `next` throws an error. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). +features: [Symbol.iterator] +---*/ + +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + new Map(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/iterator-value-failure.js b/js/src/tests/test262/built-ins/Map/iterator-value-failure.js new file mode 100644 index 0000000000..d7d684df21 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/iterator-value-failure.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map-iterable +description: > + The iterator is closed when iterable `next` value throws an error. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + e. ReturnIfAbrupt(nextItem). +features: [Symbol.iterator] +---*/ + +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + get value() { + throw new Test262Error(); + }, + done: false + }; + } + }; +}; + +assert.throws(Test262Error, function() { + new Map(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/length.js b/js/src/tests/test262/built-ins/Map/length.js new file mode 100644 index 0000000000..c63939508b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/length.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.1.2 +description: Map.length is 0. +info: | + Properties of the Map Constructor + + Besides the length property (whose value is 0) +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Map.length, 0, 'The value of Map.length is 0'); + +verifyNotEnumerable(Map, 'length'); +verifyNotWritable(Map, 'length'); +verifyConfigurable(Map, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/map-iterable-empty-does-not-call-set.js b/js/src/tests/test262/built-ins/Map/map-iterable-empty-does-not-call-set.js new file mode 100644 index 0000000000..26461bb7f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/map-iterable-empty-does-not-call-set.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map-iterable +description: > + A Map constructed with an empty iterable argument does not call set. +info: | + Map ( [ iterable ] ) + + When the Map function is called with optional argument the following steps are + taken: + + ... + 8. If iter is undefined, return map. + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return map. +---*/ + +var set = Map.prototype.set; +var counter = 0; + +Map.prototype.set = function(value) { + counter++; + set.call(this, value); +}; + +new Map([]); + +assert.sameValue(counter, 0, '`Map.prototype.set` was not called.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/map-iterable-throws-when-set-is-not-callable.js b/js/src/tests/test262/built-ins/Map/map-iterable-throws-when-set-is-not-callable.js new file mode 100644 index 0000000000..bd69dd0636 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/map-iterable-throws-when-set-is-not-callable.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-iterable +description: > + Throws a TypeError if `set` is not callable on Map constructor with a + iterable argument. +info: | + Map ( [ iterable ] ) + + When the Map function is called with optional argument the following steps are + taken: + + ... + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + 7. Else, + a. Let adder be Get(map, "set"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. +---*/ + +Map.prototype.set = null; + +assert.throws(TypeError, function() { + new Map([ + [1, 1], + [2, 2] + ]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/map-iterable.js b/js/src/tests/test262/built-ins/Map/map-iterable.js new file mode 100644 index 0000000000..32918cea9b --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/map-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-map-iterable +description: > + Contructor returns a map object set with the elements from the iterable + argument. +info: | + Map ( [ iterable ] ) + + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return map. + ... +---*/ + +var m = new Map([ + ["attr", 1], + ["foo", 2] +]); + +assert.sameValue(m.size, 2, 'The value of `m.size` is `2`'); +assert.sameValue(m.get("attr"), 1); +assert.sameValue(m.get("foo"), 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/map-no-iterable-does-not-call-set.js b/js/src/tests/test262/built-ins/Map/map-no-iterable-does-not-call-set.js new file mode 100644 index 0000000000..0d293d61c7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/map-no-iterable-does-not-call-set.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-iterable +description: > + A Map constructed without a iterable argument does not call set. +info: | + Map ( [ iterable ] ) + + When the Map function is called with optional argument the following steps are + taken: + + ... + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + 7. Else, + a. Let adder be Get(map, "set"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + 8. If iter is undefined, return map. +---*/ + +var set = Map.prototype.set; +var counter = 0; + +Map.prototype.set = function(value) { + counter++; + set.call(this, value); +}; + +new Map(); + +assert.sameValue(counter, 0, '`Map.prototype.set` was not called.'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/map-no-iterable.js b/js/src/tests/test262/built-ins/Map/map-no-iterable.js new file mode 100644 index 0000000000..e1793ef578 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/map-no-iterable.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-iterable +description: > + Returns the new Map object with the new empty list if the iterable argument is + undefined. +info: | + Map ( [ iterable ] ) + + ... + 2. Let map be OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", + «[[MapData]]» ). + ... + 4. Map map’s [[MapData]] internal slot to a new empty List. + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + ... + 8. If iter is undefined, return map. +---*/ + +var m1 = new Map(); +var m2 = new Map(undefined); +var m3 = new Map(null); + +assert.sameValue(m1.size, 0, 'The value of `new Map().size` is `0`'); +assert.sameValue(m2.size, 0, 'The value of `new Map(undefined).size` is `0`'); +assert.sameValue(m3.size, 0, 'The value of `new Map(null).size` is `0`'); + +assert(m1 instanceof Map); +assert(m2 instanceof Map); +assert(m3 instanceof Map); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/map.js b/js/src/tests/test262/built-ins/Map/map.js new file mode 100644 index 0000000000..211626fc6e --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/map.js @@ -0,0 +1,19 @@ +// 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-iterable +description: > + Map descriptor as a standard built-in object. +info: | + Map ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(this, 'Map'); +verifyWritable(this, 'Map'); +verifyConfigurable(this, 'Map'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/name.js b/js/src/tests/test262/built-ins/Map/name.js new file mode 100644 index 0000000000..4ff6542786 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/name.js @@ -0,0 +1,20 @@ +// 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-iterable +description: Map.name value and descriptor. +info: | + Map ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Map.name, 'Map', 'The value of Map.name is "Map"'); + +verifyNotEnumerable(Map, 'name'); +verifyNotWritable(Map, 'name'); +verifyConfigurable(Map, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/newtarget.js b/js/src/tests/test262/built-ins/Map/newtarget.js new file mode 100644 index 0000000000..36f820fac7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/newtarget.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-iterable +description: > + The new Map object's prototype is Map.prototype +info: | + Map ( [ iterable ] ) + + When the Map function is called with optional argument the following steps + are taken: + + ... + 2. Let map be OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", + «[[MapData]]» ). + ... + +---*/ + +var m1 = new Map(); + +assert.sameValue( + Object.getPrototypeOf(m1), + Map.prototype, + "`Object.getPrototypeOf(m1)` returns `Map.prototype`" +); + +var m2 = new Map([ + [1, 1], + [2, 2] +]); + +assert.sameValue( + Object.getPrototypeOf(m2), + Map.prototype, + "`Object.getPrototypeOf(m2)` returns `Map.prototype`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/properties-of-map-instances.js b/js/src/tests/test262/built-ins/Map/properties-of-map-instances.js new file mode 100644 index 0000000000..b38608c055 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/properties-of-map-instances.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. +/*--- +es6id: 23.1.4 +description: > + Map instances are ordinary objects that inherit properties from the Map + prototype. +---*/ + +assert.sameValue( + Object.getPrototypeOf(new Map()), + Map.prototype, + '`Object.getPrototypeOf(new Map())` returns `Map.prototype`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/properties-of-the-map-prototype-object.js b/js/src/tests/test262/built-ins/Map/properties-of-the-map-prototype-object.js new file mode 100644 index 0000000000..a6c1ec8d7c --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/properties-of-the-map-prototype-object.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.1.3 +description: > + The prototype of Map.prototype is Object.prototype. +info: | + The Map prototype object is the intrinsic object %MapPrototype%. The value + of the [[Prototype]] internal slot of the Map prototype object is the + intrinsic object %ObjectPrototype% (19.1.3). The Map prototype object is an + ordinary object. It does not have a [[MapData]] internal slot. +---*/ + +assert.sameValue( + Object.getPrototypeOf(Map.prototype), + Object.prototype, + 'Object.getPrototypeOf(Map.prototype) returns Object.prototype' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/Map/proto-from-ctor-realm.js new file mode 100644 index 0000000000..f85cc28e78 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/proto-from-ctor-realm.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map-iterable +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 3. Let map be ? OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", + « [[MapData]] »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var o = Reflect.construct(Map, [], C); + +assert.sameValue(Object.getPrototypeOf(o), other.Map.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/prototype-of-map.js b/js/src/tests/test262/built-ins/Map/prototype-of-map.js new file mode 100644 index 0000000000..91f931c4eb --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/prototype-of-map.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. +/*--- +es6id: 23.1.2 +description: > + The prototype of Map is the intrinsic FunctionPrototype. +info: | + The value of the [[Prototype]] internal slot of the Map constructor is the + intrinsic object %FunctionPrototype% (19.2.3). +---*/ + +assert.sameValue( + Object.getPrototypeOf(Map), + Function.prototype, + '`Object.getPrototypeOf(Map)` returns `Function.prototype`' +); + +reportCompare(0, 0); 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); diff --git a/js/src/tests/test262/built-ins/Map/shell.js b/js/src/tests/test262/built-ins/Map/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/Map/undefined-newtarget.js b/js/src/tests/test262/built-ins/Map/undefined-newtarget.js new file mode 100644 index 0000000000..94e6bd397a --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/undefined-newtarget.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-iterable +description: > + Throws a TypeError if Map is called without a newTarget. +info: | + Map ( [ iterable ] ) + + When the Map function is called with optional argument the following steps + are taken: + + 1. If NewTarget is undefined, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + Map(); +}); + +assert.throws(TypeError, function() { + Map([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Map/valid-keys.js b/js/src/tests/test262/built-ins/Map/valid-keys.js new file mode 100644 index 0000000000..46ce265648 --- /dev/null +++ b/js/src/tests/test262/built-ins/Map/valid-keys.js @@ -0,0 +1,486 @@ +// |reftest| skip-if(!this.hasOwnProperty('WeakRef')) -- WeakRef is not enabled unconditionally +// Copyright (C) 2021 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.set +description: Observing the expected behavior of valid keys +info: | + Map.prototype.set ( key , value ) + + ... + Let p be the Record {[[key]]: key, [[value]]: value}. + Append p as the last element of entries. + ... + +features: [BigInt, Symbol, TypedArray, WeakRef, exponentiation] +---*/ + + +const negativeZero = -0; +const positiveZero = +0; +const zero = 0; +const one = 1; +const twoRaisedToFiftyThreeMinusOne = 2 ** 53 - 1; +const int32Array = new Int32Array([zero, one]); +const uint32Array = new Uint32Array([zero, one]); +const n = 100000000000000000000000000000000000000000000000000000000000000000000000000000000001n; +const bigInt = BigInt('100000000000000000000000000000000000000000000000000000000000000000000000000000000001'); +const n1 = 1n; +const n53 = 9007199254740991n; +const fiftyThree = BigInt('9007199254740991'); +const bigInt64Array = new BigInt64Array([n1, n53]); +const bigUint64Array = new BigUint64Array([n1, n53]); +const symbol = Symbol(''); +const object = {}; +const array = {}; +const string = ''; +const booleanTrue = true; +const booleanFalse = true; +const functionExprValue = function() {}; +const arrowFunctionValue = () => {}; +const classValue = class {}; +const map = new Map(); +const set = new Set(); +const weakMap = new WeakMap(); +const weakRef = new WeakRef({}); +const weakSet = new WeakSet(); +const nullValue = null; +const undefinedValue = undefined; +let unassigned; + +{ + const m = new Map([[negativeZero, negativeZero]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(negativeZero), true); + assert.sameValue(m.get(negativeZero), negativeZero); + m.delete(negativeZero); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(negativeZero), false); + m.set(negativeZero, negativeZero); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(negativeZero), true); + assert.sameValue(m.get(negativeZero), negativeZero); +}; + +{ + const m = new Map([[positiveZero, positiveZero]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(positiveZero), true); + assert.sameValue(m.get(positiveZero), positiveZero); + m.delete(positiveZero); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(positiveZero), false); + m.set(positiveZero, positiveZero); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(positiveZero), true); + assert.sameValue(m.get(positiveZero), positiveZero); +}; + +{ + const m = new Map([[zero, zero]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(zero), true); + assert.sameValue(m.get(zero), zero); + m.delete(zero); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(zero), false); + m.set(zero, zero); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(zero), true); + assert.sameValue(m.get(zero), zero); +}; + +{ + const m = new Map([[one, one]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(one), true); + assert.sameValue(m.get(one), one); + m.delete(one); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(one), false); + m.set(one, one); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(one), true); + assert.sameValue(m.get(one), one); +}; + +{ + const m = new Map([[twoRaisedToFiftyThreeMinusOne, twoRaisedToFiftyThreeMinusOne]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(twoRaisedToFiftyThreeMinusOne), true); + assert.sameValue(m.get(twoRaisedToFiftyThreeMinusOne), twoRaisedToFiftyThreeMinusOne); + m.delete(twoRaisedToFiftyThreeMinusOne); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(twoRaisedToFiftyThreeMinusOne), false); + m.set(twoRaisedToFiftyThreeMinusOne, twoRaisedToFiftyThreeMinusOne); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(twoRaisedToFiftyThreeMinusOne), true); + assert.sameValue(m.get(twoRaisedToFiftyThreeMinusOne), twoRaisedToFiftyThreeMinusOne); +}; + +{ + const m = new Map([[int32Array, int32Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(int32Array), true); + assert.sameValue(m.get(int32Array), int32Array); + m.delete(int32Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(int32Array), false); + m.set(int32Array, int32Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(int32Array), true); + assert.sameValue(m.get(int32Array), int32Array); +}; + +{ + const m = new Map([[uint32Array, uint32Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(uint32Array), true); + assert.sameValue(m.get(uint32Array), uint32Array); + m.delete(uint32Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(uint32Array), false); + m.set(uint32Array, uint32Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(uint32Array), true); + assert.sameValue(m.get(uint32Array), uint32Array); +}; + +{ + const m = new Map([[n, n]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n), true); + assert.sameValue(m.get(n), n); + m.delete(n); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(n), false); + m.set(n, n); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n), true); + assert.sameValue(m.get(n), n); +}; + +{ + const m = new Map([[bigInt, bigInt]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt), true); + assert.sameValue(m.get(bigInt), bigInt); + m.delete(bigInt); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(bigInt), false); + m.set(bigInt, bigInt); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt), true); + assert.sameValue(m.get(bigInt), bigInt); +}; + +{ + const m = new Map([[n1, n1]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n1), true); + assert.sameValue(m.get(n1), n1); + m.delete(n1); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(n1), false); + m.set(n1, n1); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n1), true); + assert.sameValue(m.get(n1), n1); +}; + +{ + const m = new Map([[n53, n53]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n53), true); + assert.sameValue(m.get(n53), n53); + m.delete(n53); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(n53), false); + m.set(n53, n53); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n53), true); + assert.sameValue(m.get(n53), n53); +}; + +{ + const m = new Map([[fiftyThree, fiftyThree]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(fiftyThree), true); + assert.sameValue(m.get(fiftyThree), fiftyThree); + m.delete(fiftyThree); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(fiftyThree), false); + m.set(fiftyThree, fiftyThree); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(fiftyThree), true); + assert.sameValue(m.get(fiftyThree), fiftyThree); +}; + +{ + const m = new Map([[bigInt64Array, bigInt64Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt64Array), true); + assert.sameValue(m.get(bigInt64Array), bigInt64Array); + m.delete(bigInt64Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(bigInt64Array), false); + m.set(bigInt64Array, bigInt64Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt64Array), true); + assert.sameValue(m.get(bigInt64Array), bigInt64Array); +}; + +{ + const m = new Map([[bigUint64Array, bigUint64Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigUint64Array), true); + assert.sameValue(m.get(bigUint64Array), bigUint64Array); + m.delete(bigUint64Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(bigUint64Array), false); + m.set(bigUint64Array, bigUint64Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigUint64Array), true); + assert.sameValue(m.get(bigUint64Array), bigUint64Array); +}; + +{ + const m = new Map([[symbol, symbol]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(symbol), true); + assert.sameValue(m.get(symbol), symbol); + m.delete(symbol); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(symbol), false); + m.set(symbol, symbol); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(symbol), true); + assert.sameValue(m.get(symbol), symbol); +}; + +{ + const m = new Map([[object, object]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(object), true); + assert.sameValue(m.get(object), object); + m.delete(object); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(object), false); + m.set(object, object); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(object), true); + assert.sameValue(m.get(object), object); +}; + +{ + const m = new Map([[array, array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(array), true); + assert.sameValue(m.get(array), array); + m.delete(array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(array), false); + m.set(array, array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(array), true); + assert.sameValue(m.get(array), array); +}; + +{ + const m = new Map([[string, string]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(string), true); + assert.sameValue(m.get(string), string); + m.delete(string); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(string), false); + m.set(string, string); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(string), true); + assert.sameValue(m.get(string), string); +}; + +{ + const m = new Map([[booleanTrue, booleanTrue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanTrue), true); + assert.sameValue(m.get(booleanTrue), booleanTrue); + m.delete(booleanTrue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(booleanTrue), false); + m.set(booleanTrue, booleanTrue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanTrue), true); + assert.sameValue(m.get(booleanTrue), booleanTrue); +}; + +{ + const m = new Map([[booleanFalse, booleanFalse]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanFalse), true); + assert.sameValue(m.get(booleanFalse), booleanFalse); + m.delete(booleanFalse); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(booleanFalse), false); + m.set(booleanFalse, booleanFalse); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanFalse), true); + assert.sameValue(m.get(booleanFalse), booleanFalse); +}; + +{ + const m = new Map([[functionExprValue, functionExprValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(functionExprValue), true); + assert.sameValue(m.get(functionExprValue), functionExprValue); + m.delete(functionExprValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(functionExprValue), false); + m.set(functionExprValue, functionExprValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(functionExprValue), true); + assert.sameValue(m.get(functionExprValue), functionExprValue); +}; + +{ + const m = new Map([[arrowFunctionValue, arrowFunctionValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(arrowFunctionValue), true); + assert.sameValue(m.get(arrowFunctionValue), arrowFunctionValue); + m.delete(arrowFunctionValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(arrowFunctionValue), false); + m.set(arrowFunctionValue, arrowFunctionValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(arrowFunctionValue), true); + assert.sameValue(m.get(arrowFunctionValue), arrowFunctionValue); +}; + +{ + const m = new Map([[classValue, classValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(classValue), true); + assert.sameValue(m.get(classValue), classValue); + m.delete(classValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(classValue), false); + m.set(classValue, classValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(classValue), true); + assert.sameValue(m.get(classValue), classValue); +}; + +{ + const m = new Map([[map, map]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(map), true); + assert.sameValue(m.get(map), map); + m.delete(map); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(map), false); + m.set(map, map); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(map), true); + assert.sameValue(m.get(map), map); +}; + +{ + const m = new Map([[set, set]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(set), true); + assert.sameValue(m.get(set), set); + m.delete(set); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(set), false); + m.set(set, set); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(set), true); + assert.sameValue(m.get(set), set); +}; + +{ + const m = new Map([[weakMap, weakMap]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakMap), true); + assert.sameValue(m.get(weakMap), weakMap); + m.delete(weakMap); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(weakMap), false); + m.set(weakMap, weakMap); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakMap), true); + assert.sameValue(m.get(weakMap), weakMap); +}; + +{ + const m = new Map([[weakRef, weakRef]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakRef), true); + assert.sameValue(m.get(weakRef), weakRef); + m.delete(weakRef); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(weakRef), false); + m.set(weakRef, weakRef); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakRef), true); + assert.sameValue(m.get(weakRef), weakRef); +}; + +{ + const m = new Map([[weakSet, weakSet]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakSet), true); + assert.sameValue(m.get(weakSet), weakSet); + m.delete(weakSet); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(weakSet), false); + m.set(weakSet, weakSet); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakSet), true); + assert.sameValue(m.get(weakSet), weakSet); +}; + +{ + const m = new Map([[nullValue, nullValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(nullValue), true); + assert.sameValue(m.get(nullValue), nullValue); + m.delete(nullValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(nullValue), false); + m.set(nullValue, nullValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(nullValue), true); + assert.sameValue(m.get(nullValue), nullValue); +}; + +{ + const m = new Map([[undefinedValue, undefinedValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(undefinedValue), true); + assert.sameValue(m.get(undefinedValue), undefinedValue); + m.delete(undefinedValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(undefinedValue), false); + m.set(undefinedValue, undefinedValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(undefinedValue), true); + assert.sameValue(m.get(undefinedValue), undefinedValue); +}; + +{ + const m = new Map([[unassigned, unassigned]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(unassigned), true); + assert.sameValue(m.get(unassigned), unassigned); + m.delete(unassigned); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(unassigned), false); + m.set(unassigned, unassigned); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(unassigned), true); + assert.sameValue(m.get(unassigned), unassigned); +}; + + +reportCompare(0, 0); |