From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- js/src/tests/test262/built-ins/WeakMap/browser.js | 0 .../tests/test262/built-ins/WeakMap/constructor.js | 15 +++++ .../test262/built-ins/WeakMap/empty-iterable.js | 33 ++++++++++ .../built-ins/WeakMap/get-set-method-failure.js | 32 +++++++++ .../test262/built-ins/WeakMap/is-a-constructor.js | 26 ++++++++ .../test262/built-ins/WeakMap/iterable-failure.js | 21 ++++++ .../built-ins/WeakMap/iterable-with-object-keys.js | 48 ++++++++++++++ .../built-ins/WeakMap/iterable-with-symbol-keys.js | 48 ++++++++++++++ .../WeakMap/iterator-close-after-set-failure.js | 45 +++++++++++++ .../iterator-item-first-entry-returns-abrupt.js | 49 ++++++++++++++ .../iterator-item-second-entry-returns-abrupt.js | 49 ++++++++++++++ ...iterator-items-are-not-object-close-iterator.js | 77 ++++++++++++++++++++++ .../iterator-items-keys-cannot-be-held-weakly.js | 52 +++++++++++++++ .../built-ins/WeakMap/iterator-next-failure.js | 31 +++++++++ .../built-ins/WeakMap/iterator-value-failure.js | 37 +++++++++++ js/src/tests/test262/built-ins/WeakMap/length.js | 16 +++++ js/src/tests/test262/built-ins/WeakMap/name.js | 22 +++++++ .../tests/test262/built-ins/WeakMap/no-iterable.js | 26 ++++++++ .../WeakMap/properties-of-map-instances.js | 16 +++++ .../properties-of-the-weakmap-prototype-object.js | 22 +++++++ .../built-ins/WeakMap/proto-from-ctor-realm.js | 31 +++++++++ .../built-ins/WeakMap/prototype-of-weakmap.js | 16 +++++ .../WeakMap/prototype/Symbol.toStringTag.js | 23 +++++++ .../test262/built-ins/WeakMap/prototype/browser.js | 0 .../built-ins/WeakMap/prototype/constructor.js | 23 +++++++ .../built-ins/WeakMap/prototype/delete/browser.js | 0 ...elete-entry-with-object-key-initial-iterable.js | 30 +++++++++ .../delete/delete-entry-with-object-key.js | 30 +++++++++ ...elete-entry-with-symbol-key-initial-iterable.js | 38 +++++++++++ .../delete/delete-entry-with-symbol-key.js | 41 ++++++++++++ .../built-ins/WeakMap/prototype/delete/delete.js | 25 +++++++ ...oes-not-have-weakmapdata-internal-slot-array.js | 25 +++++++ .../does-not-have-weakmapdata-internal-slot-map.js | 26 ++++++++ ...es-not-have-weakmapdata-internal-slot-object.js | 25 +++++++ .../does-not-have-weakmapdata-internal-slot-set.js | 26 ++++++++ ...-weakmapdata-internal-slot-weakmap-prototype.js | 25 +++++++ .../built-ins/WeakMap/prototype/delete/length.js | 24 +++++++ .../built-ins/WeakMap/prototype/delete/name.js | 24 +++++++ .../WeakMap/prototype/delete/not-a-constructor.js | 35 ++++++++++ .../returns-false-if-key-cannot-be-held-weakly.js | 23 +++++++ .../returns-false-when-object-key-not-present.js | 21 ++++++ .../returns-false-when-symbol-key-not-present.js | 25 +++++++ .../built-ins/WeakMap/prototype/delete/shell.js | 0 .../delete/this-not-object-throw-boolean.js | 22 +++++++ .../prototype/delete/this-not-object-throw-null.js | 22 +++++++ .../delete/this-not-object-throw-number.js | 22 +++++++ .../delete/this-not-object-throw-string.js | 22 +++++++ .../delete/this-not-object-throw-symbol.js | 23 +++++++ .../delete/this-not-object-throw-undefined.js | 22 +++++++ .../built-ins/WeakMap/prototype/get/browser.js | 0 .../does-not-have-weakmapdata-internal-slot-map.js | 26 ++++++++ .../does-not-have-weakmapdata-internal-slot-set.js | 26 ++++++++ .../get/does-not-have-weakmapdata-internal-slot.js | 33 ++++++++++ .../test262/built-ins/WeakMap/prototype/get/get.js | 24 +++++++ .../built-ins/WeakMap/prototype/get/length.js | 24 +++++++ .../built-ins/WeakMap/prototype/get/name.js | 24 +++++++ .../WeakMap/prototype/get/not-a-constructor.js | 35 ++++++++++ ...turns-undefined-if-key-cannot-be-held-weakly.js | 39 +++++++++++ .../get/returns-undefined-with-object-key.js | 36 ++++++++++ .../get/returns-undefined-with-symbol-key.js | 37 +++++++++++ .../prototype/get/returns-value-with-object-key.js | 32 +++++++++ .../prototype/get/returns-value-with-symbol-key.js | 35 ++++++++++ .../built-ins/WeakMap/prototype/get/shell.js | 0 .../WeakMap/prototype/get/this-not-object-throw.js | 45 +++++++++++++ .../built-ins/WeakMap/prototype/has/browser.js | 0 ...oes-not-have-weakmapdata-internal-slot-array.js | 25 +++++++ .../does-not-have-weakmapdata-internal-slot-map.js | 26 ++++++++ ...es-not-have-weakmapdata-internal-slot-object.js | 25 +++++++ .../does-not-have-weakmapdata-internal-slot-set.js | 26 ++++++++ ...-weakmapdata-internal-slot-weakmap-prototype.js | 25 +++++++ .../test262/built-ins/WeakMap/prototype/has/has.js | 25 +++++++ .../built-ins/WeakMap/prototype/has/length.js | 24 +++++++ .../built-ins/WeakMap/prototype/has/name.js | 24 +++++++ .../WeakMap/prototype/has/not-a-constructor.js | 35 ++++++++++ ...returns-false-when-key-cannot-be-held-weakly.js | 22 +++++++ .../returns-false-when-object-key-not-present.js | 25 +++++++ .../returns-false-when-symbol-key-not-present.js | 31 +++++++++ .../has/returns-true-when-object-key-present.js | 21 ++++++ .../has/returns-true-when-symbol-key-present.js | 30 +++++++++ .../built-ins/WeakMap/prototype/has/shell.js | 0 .../prototype/has/this-not-object-throw-boolean.js | 23 +++++++ .../prototype/has/this-not-object-throw-null.js | 22 +++++++ .../prototype/has/this-not-object-throw-number.js | 22 +++++++ .../prototype/has/this-not-object-throw-string.js | 22 +++++++ .../prototype/has/this-not-object-throw-symbol.js | 23 +++++++ .../has/this-not-object-throw-undefined.js | 22 +++++++ .../WeakMap/prototype/prototype-attributes.js | 14 ++++ .../WeakMap/prototype/set/adds-object-element.js | 27 ++++++++ .../WeakMap/prototype/set/adds-symbol-element.js | 26 ++++++++ .../built-ins/WeakMap/prototype/set/browser.js | 0 ...oes-not-have-weakmapdata-internal-slot-array.js | 26 ++++++++ .../does-not-have-weakmapdata-internal-slot-map.js | 26 ++++++++ ...es-not-have-weakmapdata-internal-slot-object.js | 25 +++++++ .../does-not-have-weakmapdata-internal-slot-set.js | 26 ++++++++ ...-weakmapdata-internal-slot-weakmap-prototype.js | 25 +++++++ .../built-ins/WeakMap/prototype/set/length.js | 23 +++++++ .../built-ins/WeakMap/prototype/set/name.js | 23 +++++++ .../WeakMap/prototype/set/not-a-constructor.js | 35 ++++++++++ .../set/returns-this-when-ignoring-duplicate.js | 26 ++++++++ .../WeakMap/prototype/set/returns-this.js | 19 ++++++ .../test262/built-ins/WeakMap/prototype/set/set.js | 24 +++++++ .../built-ins/WeakMap/prototype/set/shell.js | 0 .../prototype/set/this-not-object-throw-boolean.js | 22 +++++++ .../prototype/set/this-not-object-throw-null.js | 22 +++++++ .../prototype/set/this-not-object-throw-number.js | 22 +++++++ .../prototype/set/this-not-object-throw-string.js | 22 +++++++ .../prototype/set/this-not-object-throw-symbol.js | 23 +++++++ .../set/this-not-object-throw-undefined.js | 22 +++++++ .../set/throw-if-key-cannot-be-held-weakly.js | 38 +++++++++++ .../test262/built-ins/WeakMap/prototype/shell.js | 0 .../built-ins/WeakMap/set-not-callable-throws.js | 27 ++++++++ js/src/tests/test262/built-ins/WeakMap/shell.js | 24 +++++++ .../built-ins/WeakMap/undefined-newtarget.js | 21 ++++++ js/src/tests/test262/built-ins/WeakMap/weakmap.js | 16 +++++ 114 files changed, 2852 insertions(+) create mode 100644 js/src/tests/test262/built-ins/WeakMap/browser.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/constructor.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/empty-iterable.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/get-set-method-failure.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/is-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterable-failure.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterable-with-object-keys.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterable-with-symbol-keys.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterator-close-after-set-failure.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterator-item-first-entry-returns-abrupt.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterator-item-second-entry-returns-abrupt.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterator-items-are-not-object-close-iterator.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterator-items-keys-cannot-be-held-weakly.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterator-next-failure.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/iterator-value-failure.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/length.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/name.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/no-iterable.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/properties-of-map-instances.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/properties-of-the-weakmap-prototype-object.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/proto-from-ctor-realm.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype-of-weakmap.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/Symbol.toStringTag.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/browser.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/constructor.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/browser.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key-initial-iterable.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-object.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-set.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/length.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/name.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-if-key-cannot-be-held-weakly.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-object-key-not-present.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-symbol-key-not-present.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/shell.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/browser.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/get.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/length.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/name.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-if-key-cannot-be-held-weakly.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-object-key.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-object-key.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-symbol-key.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/shell.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/get/this-not-object-throw.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/browser.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-array.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-map.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-object.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-set.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/has.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/length.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/name.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-key-cannot-be-held-weakly.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-object-key-not-present.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-symbol-key-not-present.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-object-key-present.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-symbol-key-present.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/shell.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-boolean.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-null.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-number.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-string.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-symbol.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-undefined.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/prototype-attributes.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-object-element.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-symbol-element.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/browser.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/length.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/name.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/set.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/shell.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-boolean.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-null.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-number.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-string.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-symbol.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-undefined.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/set/throw-if-key-cannot-be-held-weakly.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/prototype/shell.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/set-not-callable-throws.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/shell.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/undefined-newtarget.js create mode 100644 js/src/tests/test262/built-ins/WeakMap/weakmap.js (limited to 'js/src/tests/test262/built-ins/WeakMap') diff --git a/js/src/tests/test262/built-ins/WeakMap/browser.js b/js/src/tests/test262/built-ins/WeakMap/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/constructor.js b/js/src/tests/test262/built-ins/WeakMap/constructor.js new file mode 100644 index 0000000000..e7381ed004 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/constructor.js @@ -0,0 +1,15 @@ +// 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-weakmap-constructor +description: > + The WeakMap constructor is the %WeakMap% intrinsic object and the initial + value of the WeakMap property of the global object. +---*/ + +assert.sameValue( + typeof WeakMap, 'function', + 'typeof WeakMap is "function"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/empty-iterable.js b/js/src/tests/test262/built-ins/WeakMap/empty-iterable.js new file mode 100644 index 0000000000..b3554b0aa5 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/empty-iterable.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-weakmap-iterable +description: > + If the iterable argument is empty, return new WeakMap object. +info: | + 23.3.1.1 WeakMap ( [ iterable ] ) + + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return map. + ... +---*/ + +var counter = 0; +var set = WeakMap.prototype.set; +WeakMap.prototype.set = function(value) { + counter++; + return set.call(this, value); +}; +var map = new WeakMap([]); + +assert.sameValue(Object.getPrototypeOf(map), WeakMap.prototype); +assert(map instanceof WeakMap); +assert.sameValue( + counter, 0, + 'empty iterable does not call WeakMap.prototype.set' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/get-set-method-failure.js b/js/src/tests/test262/built-ins/WeakMap/get-set-method-failure.js new file mode 100644 index 0000000000..06ced26fae --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/get-set-method-failure.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-weakmap-iterable +description: > + Return abrupt after getting `set` method. +info: | + 23.3.1.1 WeakMap ( [ iterable ] ) + + ... + 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). + ... +---*/ + +Object.defineProperty(WeakMap.prototype, 'set', { + get: function() { + throw new Test262Error(); + } +}); + +new WeakMap(); +new WeakMap(null); + +assert.throws(Test262Error, function() { + new WeakMap([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/is-a-constructor.js b/js/src/tests/test262/built-ins/WeakMap/is-a-constructor.js new file mode 100644 index 0000000000..8214f66f3f --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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 WeakMap 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, WeakMap] +---*/ + +assert.sameValue(isConstructor(WeakMap), true, 'isConstructor(WeakMap) must return true'); +new WeakMap(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterable-failure.js b/js/src/tests/test262/built-ins/WeakMap/iterable-failure.js new file mode 100644 index 0000000000..28bf7c73e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/iterable-failure.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap-iterable +description: > + If the iterable argument is undefined, return new WeakMap object. +info: | + 23.3.1.1 WeakMap ( [ iterable ] ) + + ... + 7. Else, + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + ... +---*/ + +assert.throws(TypeError, function() { + new WeakMap({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterable-with-object-keys.js b/js/src/tests/test262/built-ins/WeakMap/iterable-with-object-keys.js new file mode 100644 index 0000000000..77f691bdc8 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/iterable-with-object-keys.js @@ -0,0 +1,48 @@ +// 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-weakmap-iterable +description: > + Returns the new WeakMap adding entries from the iterable parameter, with + Object keys. +info: | + WeakMap ( [ _iterable_ ] ) + 5. Let _adder_ be ? Get(_map_, *"set"*). + 6. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_). + + AddEntriesFromIterable: + 3. Repeat, + i. Let _status_ be Completion(Call(_adder_, _target_, « _k_, _v_ »)). + + WeakMap.prototype.set( _key_, _value_ ): + 6. Let _p_ be the Record {[[Key]]: _key_, [[Value]]: _value_}. + 7. Append _p_ as the last element of _entries_. +features: [WeakMap] +---*/ + +var first = {}; +var second = {}; +var results = []; +var set = WeakMap.prototype.set; +WeakMap.prototype.set = function(key, value) { + results.push({ + _this: this, + key: key, + value: value + }); + return set.call(this, key, value); +}; +var map = new WeakMap([ + [first, 42], + [second, 43] +]); + +assert.sameValue(results.length, 2, 'Called WeakMap#set for each object'); +assert.sameValue(results[0].key, first, 'Adds object in order - first key'); +assert.sameValue(results[0].value, 42, 'Adds object in order - first value'); +assert.sameValue(results[0]._this, map, 'Adds object in order - this'); +assert.sameValue(results[1].key, second, 'Adds object in order - second key'); +assert.sameValue(results[1].value, 43, 'Adds object in order - second value'); +assert.sameValue(results[1]._this, map, 'Adds object in order - this'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterable-with-symbol-keys.js b/js/src/tests/test262/built-ins/WeakMap/iterable-with-symbol-keys.js new file mode 100644 index 0000000000..55071ed6bd --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/iterable-with-symbol-keys.js @@ -0,0 +1,48 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap-iterable +description: > + Returns the new WeakMap adding entries from the iterable parameter, with + Symbol keys. +info: | + WeakMap ( [ _iterable_ ] ) + 5. Let _adder_ be ? Get(_map_, *"set"*). + 6. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_). + + AddEntriesFromIterable: + 3. Repeat, + i. Let _status_ be Completion(Call(_adder_, _target_, « _k_, _v_ »)). + + WeakMap.prototype.set( _key_, _value_ ): + 6. Let _p_ be the Record {[[Key]]: _key_, [[Value]]: _value_}. + 7. Append _p_ as the last element of _entries_. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var sym = Symbol('a description'); +var results = []; +var set = WeakMap.prototype.set; +WeakMap.prototype.set = function(key, value) { + results.push({ + _this: this, + key: key, + value: value + }); + return set.call(this, key, value); +}; +var map = new WeakMap([ + [sym, 42], + [Symbol.hasInstance, 43], +]); + +assert.sameValue(results.length, 2, 'Called set() for each entry'); +assert.sameValue(results[0].key, sym, 'Adds object in order - first key, regular symbol'); +assert.sameValue(results[0].value, 42, 'Adds object in order - first value'); +assert.sameValue(results[0]._this, map, 'Adds object in order - this'); +assert.sameValue(results[1].key, Symbol.hasInstance, 'Adds object in order - second key, well-known symbol'); +assert.sameValue(results[1].value, 43, 'Adds object in order - second value'); +assert.sameValue(results[1]._this, map, 'Adds object in order - this'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterator-close-after-set-failure.js b/js/src/tests/test262/built-ins/WeakMap/iterator-close-after-set-failure.js new file mode 100644 index 0000000000..933794bc9a --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/iterator-close-after-set-failure.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-weakmap-iterable +description: > + Return IteratorClose(iter, status) if fail on adding value on constructing. +info: | + WeakMap ( [ 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; + } + }; +}; +WeakMap.prototype.set = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + new WeakMap(iterable); +}); + +assert.sameValue( + count, 1, + 'The iterator is closed when `WeakMap.prototype.set` throws an error.' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterator-item-first-entry-returns-abrupt.js b/js/src/tests/test262/built-ins/WeakMap/iterator-item-first-entry-returns-abrupt.js new file mode 100644 index 0000000000..8fd9ca47cc --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap-iterable +description: > + Closes iterator if item first entry completes abruptly. +info: | + WeakMap ( [ 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 WeakMap(iterable); +}); + +assert.sameValue(count, 1, 'The get error closed the iterator'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterator-item-second-entry-returns-abrupt.js b/js/src/tests/test262/built-ins/WeakMap/iterator-item-second-entry-returns-abrupt.js new file mode 100644 index 0000000000..dbbb034139 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap-iterable +description: > + Closes iterator if item second entry completes abruptly. +info: | + WeakMap ( [ 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 WeakMap(iterable); +}); + +assert.sameValue(count, 1, 'The get error closed the iterator'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterator-items-are-not-object-close-iterator.js b/js/src/tests/test262/built-ins/WeakMap/iterator-items-are-not-object-close-iterator.js new file mode 100644 index 0000000000..adb005a593 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap-iterable +description: > + Closes the iterator object after not object error on next item. +info: | + WeakMap ( [ 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 WeakMap(iterable); +}); +assert.sameValue(count, 1); + +nextItem = true; +assert.throws(TypeError, function() { + new WeakMap(iterable); +}); +assert.sameValue(count, 2); + +nextItem = ''; +assert.throws(TypeError, function() { + new WeakMap(iterable); +}); +assert.sameValue(count, 3); + +nextItem = null; +assert.throws(TypeError, function() { + new WeakMap(iterable); +}); +assert.sameValue(count, 4); + +nextItem = undefined; +assert.throws(TypeError, function() { + new WeakMap(iterable); +}); +assert.sameValue(count, 5); + +nextItem = Symbol.for('a'); +assert.throws(TypeError, function() { + new WeakMap(iterable); +}); +assert.sameValue(count, 6); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterator-items-keys-cannot-be-held-weakly.js b/js/src/tests/test262/built-ins/WeakMap/iterator-items-keys-cannot-be-held-weakly.js new file mode 100644 index 0000000000..437b48b251 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/iterator-items-keys-cannot-be-held-weakly.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-weakmap-iterable +description: > + Throws a TypeError if keys in iterable items cannot be held weakly. +info: | + WeakMap ( [ _iterable_ ] ) + 5. Let _adder_ be ? Get(_map_, *"set"*). + 6. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_). + + AddEntriesFromIterable: + 3. Repeat, + i. Let _status_ be Completion(Call(_adder_, _target_, « _k_, _v_ »)). + j. IfAbruptCloseIterator(_status_, _iteratorRecord_). + + WeakMap.prototype.set( _key_, _value_ ): + 4. If CanBeHeldWeakly(_key_) is *false*, throw a *TypeError* exception. +features: [Symbol, WeakMap] +---*/ + +assert.throws(TypeError, function() { + new WeakMap([1, 1]); +}); + +assert.throws(TypeError, function() { + new WeakMap(['', 1]); +}); + +assert.throws(TypeError, function() { + new WeakMap([true, 1]); +}); + +assert.throws(TypeError, function() { + new WeakMap([null, 1]); +}); + +assert.throws(TypeError, function() { + new WeakMap([Symbol.for('registered symbol'), 1]); +}, 'Registered symbol not allowed as a WeakMap key'); + +assert.throws(TypeError, function() { + new WeakMap([undefined, 1]); +}); + +assert.throws(TypeError, function() { + new WeakMap([ + ['a', 1], 2 + ]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterator-next-failure.js b/js/src/tests/test262/built-ins/WeakMap/iterator-next-failure.js new file mode 100644 index 0000000000..3cdac01c64 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/iterator-next-failure.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-weakmap-iterable +description: > + Return abrupt from next iterator step. +info: | + 23.3.1.1 WeakMap ( [ 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 WeakMap(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/iterator-value-failure.js b/js/src/tests/test262/built-ins/WeakMap/iterator-value-failure.js new file mode 100644 index 0000000000..4875063946 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/iterator-value-failure.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-weakmap-iterable +description: > + If the iterable argument is empty, return new WeakMap object. +info: | + 23.3.1.1 WeakMap ( [ 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 WeakMap(iterable); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/length.js b/js/src/tests/test262/built-ins/WeakMap/length.js new file mode 100644 index 0000000000..e5bf7043e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/length.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-properties-of-the-weakmap-constructor +description: > + The length property of the WeakMap constructor is 0. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(WeakMap.length, 0, 'The value of `WeakMap.length` is `0`'); + +verifyNotEnumerable(WeakMap, 'length'); +verifyNotWritable(WeakMap, 'length'); +verifyConfigurable(WeakMap, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/name.js b/js/src/tests/test262/built-ins/WeakMap/name.js new file mode 100644 index 0000000000..d7d4457efe --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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. +/*--- +esid: sec-weakmap-iterable +description: > + WeakMap ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.name, 'WeakMap', + 'The value of `WeakMap.name` is "WeakMap"' +); + +verifyNotEnumerable(WeakMap, 'name'); +verifyNotWritable(WeakMap, 'name'); +verifyConfigurable(WeakMap, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/no-iterable.js b/js/src/tests/test262/built-ins/WeakMap/no-iterable.js new file mode 100644 index 0000000000..8e891a99e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/no-iterable.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-weakmap-iterable +description: > + If the iterable argument is undefined, return new WeakMap object. +info: | + WeakMap ( [ iterable ] ) + + ... + 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 a = new WeakMap(); +var b = new WeakMap(undefined); +var c = new WeakMap(null); + +assert.sameValue(Object.getPrototypeOf(a), WeakMap.prototype); +assert.sameValue(Object.getPrototypeOf(b), WeakMap.prototype); +assert.sameValue(Object.getPrototypeOf(c), WeakMap.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/properties-of-map-instances.js b/js/src/tests/test262/built-ins/WeakMap/properties-of-map-instances.js new file mode 100644 index 0000000000..4eec328c6e --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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. +/*--- +esid: sec-properties-of-weakmap-instances +description: > + WeakMap instances are ordinary objects that inherit properties from the + WeakMap prototype. +---*/ + +assert.sameValue( + Object.getPrototypeOf(new WeakMap()), + WeakMap.prototype, + '`Object.getPrototypeOf(new WeakMap())` returns `WeakMap.prototype`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/properties-of-the-weakmap-prototype-object.js b/js/src/tests/test262/built-ins/WeakMap/properties-of-the-weakmap-prototype-object.js new file mode 100644 index 0000000000..2a3e1057b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/properties-of-the-weakmap-prototype-object.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-properties-of-the-weakmap-prototype-object +description: > + The WeakMap.prototype's prototype is Object.prototype. +info: | + 23.3.3 Properties of the WeakMap Prototype Object + + The WeakMap prototype object is the intrinsic object %WeakMapPrototype%. The + value of the [[Prototype]] internal slot of the WeakMap prototype object is + the intrinsic object %ObjectPrototype% (19.1.3). The WeakMap prototype object + is an ordinary object. It does not have a [[WeakMapData]] internal slot. +---*/ + +assert.sameValue( + Object.getPrototypeOf(WeakMap.prototype), + Object.prototype, + '`Object.getPrototypeOf(WeakMap.prototype)` returns `Object.prototype`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/WeakMap/proto-from-ctor-realm.js new file mode 100644 index 0000000000..cade937c93 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap-iterable +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 2. Let map be ? OrdinaryCreateFromConstructor(NewTarget, + "%WeakMapPrototype%", « [[WeakMapData]] »). + [...] + + 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(WeakMap, [], C); + +assert.sameValue(Object.getPrototypeOf(o), other.WeakMap.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype-of-weakmap.js b/js/src/tests/test262/built-ins/WeakMap/prototype-of-weakmap.js new file mode 100644 index 0000000000..41131ea439 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype-of-weakmap.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-properties-of-the-weakmap-constructor +description: > + The value of the [[Prototype]] internal slot of the WeakMap constructor is the + intrinsic object %FunctionPrototype% (19.2.3). +---*/ + +assert.sameValue( + Object.getPrototypeOf(WeakMap), + Function.prototype, + '`Object.getPrototypeOf(WeakMap)` returns `Function.prototype`' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/WeakMap/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..0e5a8a2617 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype-@@tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "WeakMap". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(WeakMap.prototype[Symbol.toStringTag], 'WeakMap'); + +verifyNotEnumerable(WeakMap.prototype, Symbol.toStringTag); +verifyNotWritable(WeakMap.prototype, Symbol.toStringTag); +verifyConfigurable(WeakMap.prototype, Symbol.toStringTag); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/browser.js b/js/src/tests/test262/built-ins/WeakMap/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/constructor.js b/js/src/tests/test262/built-ins/WeakMap/prototype/constructor.js new file mode 100644 index 0000000000..78bbfc0865 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/constructor.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-weakmap.prototype.constructor +description: > + WeakMap.prototype.constructor value and property descriptor +info: | + The initial value of WeakMap.prototype.constructor is the %WeakMap% + intrinsic object. + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(WeakMap.prototype.constructor, WeakMap); +assert.sameValue((new WeakMap()).constructor, WeakMap); + +verifyNotEnumerable(WeakMap.prototype, 'constructor'); +verifyWritable(WeakMap.prototype, 'constructor'); +verifyConfigurable(WeakMap.prototype, 'constructor'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/browser.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.js new file mode 100644 index 0000000000..dea167276f --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key-initial-iterable.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-weakmap.prototype.delete +description: > + Delete an entry with an Object key, added from initial iterable. +info: | + WeakMap.prototype.delete ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *false*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, then + i. Set _p_.[[Key]] to ~empty~. + ii. Set _p_.[[Value]] to ~empty~. + iii. Return *true*. +features: [WeakMap] +---*/ + +var foo = {}; +var map = new WeakMap([ + [foo, 42] +]); + +var result = map.delete(foo); + +assert.sameValue(map.has(foo), false); +assert.sameValue(result, true, 'WeakMap#delete returns true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.js new file mode 100644 index 0000000000..be3d05ba31 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-object-key.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-weakmap.prototype.delete +description: > + Delete an entry with an Object key. +info: | + WeakMap.prototype.delete ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *false*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, then + i. Set _p_.[[Key]] to ~empty~. + ii. Set _p_.[[Value]] to ~empty~. + iii. Return *true*. +features: [WeakMap] +---*/ + +var foo = {}; +var map = new WeakMap(); + +map.set(foo, 42); + +var result = map.delete(foo); + +assert.sameValue(map.has(foo), false); +assert.sameValue(result, true, 'WeakMap#delete returns true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key-initial-iterable.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key-initial-iterable.js new file mode 100644 index 0000000000..e84b4f0e05 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key-initial-iterable.js @@ -0,0 +1,38 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.delete +description: > + Delete an entry with a Symbol key, added from initial iterable. +info: | + WeakMap.prototype.delete ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *false*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, then + i. Set _p_.[[Key]] to ~empty~. + ii. Set _p_.[[Value]] to ~empty~. + iii. Return *true*. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var foo = Symbol('a description'); +var bar = Symbol('a description'); +var map = new WeakMap([ + [foo, 42], + [bar, 43], + [Symbol.hasInstance, 44], +]); + +var result = map.delete(foo); +assert(!map.has(foo), 'Regular symbol was deleted from map'); +assert(map.has(bar), "Symbols with the same description don't alias to each other"); +assert.sameValue(result, true, 'delete() returns true for regular symbol'); + +result = map.delete(Symbol.hasInstance); +assert(!map.has(Symbol.hasInstance), 'Well-known symbol was deleted from map'); +assert.sameValue(result, true, 'delete() returns true for well-known symbol'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key.js new file mode 100644 index 0000000000..9751b860c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete-entry-with-symbol-key.js @@ -0,0 +1,41 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.delete +description: > + Delete an entry with a Symbol key. +info: | + WeakMap.prototype.delete ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *false*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, then + i. Set _p_.[[Key]] to ~empty~. + ii. Set _p_.[[Value]] to ~empty~. + iii. Return *true*. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var foo = Symbol('a description'); +var bar = Symbol('a description'); +var map = new WeakMap(); + +map.set(foo, 42); +map.set(bar, 43); + +var result = map.delete(foo); + +assert(!map.has(foo), 'Regular symbol was deleted from map'); +assert(map.has(bar), "Symbols with the same description don't alias each other"); +assert.sameValue(result, true, 'delete() returns true for regular symbol'); + +map.set(Symbol.hasInstance, 44); + +result = map.delete(Symbol.hasInstance); + +assert(!map.has(Symbol.hasInstance), 'Well-known symbol was deleted from map'); +assert.sameValue(result, true, 'delete() returns true for well-known symbol'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete.js new file mode 100644 index 0000000000..15c82ed408 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/delete.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-weakmap.prototype.delete +description: > + WeakMap.prototype.delete property descriptor +info: | + WeakMap.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof WeakMap.prototype.delete, + 'function', + 'typeof WeakMap.prototype.delete is "function"' +); + +verifyNotEnumerable(WeakMap.prototype, 'delete'); +verifyWritable(WeakMap.prototype, 'delete'); +verifyConfigurable(WeakMap.prototype, 'delete'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.js new file mode 100644 index 0000000000..ee36e00388 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-array.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-weakmap.prototype.delete +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call([], {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call([], {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.js new file mode 100644 index 0000000000..c3c0403a19 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-map.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-weakmap.prototype.delete +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Map] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(new Map(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(new Map(), {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-object.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-object.js new file mode 100644 index 0000000000..d87efe53d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-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-weakmap.prototype.delete +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call({}, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call({}, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-set.js new file mode 100644 index 0000000000..6ded891930 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-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-weakmap.prototype.delete +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(new Set(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(new Set(), {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js new file mode 100644 index 0000000000..6d70c09325 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/does-not-have-weakmapdata-internal-slot-weakmap-prototype.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-weakmap.prototype.delete +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.delete ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(WeakMap.prototype, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(WeakMap.prototype, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/length.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/length.js new file mode 100644 index 0000000000..bfdcaff706 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.delete +description: > + WeakMap.prototype.delete.length value and writability. +info: | + WeakMap.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.delete.length, 1, + 'The value of WeakMap.prototype.delete.length is 1' +); + +verifyNotEnumerable(WeakMap.prototype.delete, 'length'); +verifyNotWritable(WeakMap.prototype.delete, 'length'); +verifyConfigurable(WeakMap.prototype.delete, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/name.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/name.js new file mode 100644 index 0000000000..67bc4d2ee4 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.delete +description: > + WeakMap.prototype.delete.name value and writability. +info: | + WeakMap.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.delete.name, 'delete', + 'The value of WeakMap.prototype.delete.name is "delete"' +); + +verifyNotEnumerable(WeakMap.prototype.delete, 'name'); +verifyNotWritable(WeakMap.prototype.delete, 'name'); +verifyConfigurable(WeakMap.prototype.delete, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/not-a-constructor.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/not-a-constructor.js new file mode 100644 index 0000000000..59136bd1ef --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/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: > + WeakMap.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, WeakMap, arrow-function] +---*/ + +assert.sameValue( + isConstructor(WeakMap.prototype.delete), + false, + 'isConstructor(WeakMap.prototype.delete) must return false' +); + +assert.throws(TypeError, () => { + let wm = new WeakMap(); new wm.delete(); +}, '`let wm = new WeakMap(); new wm.delete()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-if-key-cannot-be-held-weakly.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-if-key-cannot-be-held-weakly.js new file mode 100644 index 0000000000..aea214c53c --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-if-key-cannot-be-held-weakly.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-weakmap.prototype.delete +description: > + Return false if the key cannot be held weakly. +info: | + WeakMap.prototype.delete ( _key_ ) + 5. If CanBeHeldWeakly(_key_) is *false*, return *false*. +features: [Symbol, WeakMap] +---*/ + +var map = new WeakMap(); + +assert.sameValue(map.delete(1), false); +assert.sameValue(map.delete(''), false); +assert.sameValue(map.delete(NaN), false); +assert.sameValue(map.delete(null), false); +assert.sameValue(map.delete(undefined), false); +assert.sameValue(map.delete(true), false); +assert.sameValue(map.delete(Symbol.for('registered symbol')), false, 'registered symbol'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-object-key-not-present.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-object-key-not-present.js new file mode 100644 index 0000000000..3ec2d9bebd --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-object-key-not-present.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.delete +description: > + Return false if an Object key is not in the WeakMap. +info: | + WeakMap.prototype.delete ( _key_ ) + 6. Return *false*. +features: [WeakMap] +---*/ + +var map = new WeakMap(); +var foo = {}; +var bar = {}; + +map.set(foo, 42); + +assert.sameValue(map.delete(bar), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-symbol-key-not-present.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-symbol-key-not-present.js new file mode 100644 index 0000000000..873b481212 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/returns-false-when-symbol-key-not-present.js @@ -0,0 +1,25 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.delete +description: > + Return false if a Symbol key is not in the WeakMap. +info: | + WeakMap.prototype.delete ( _key_ ) + 6. Return *false*. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var map = new WeakMap(); +var foo = Symbol('a description'); +var bar = Symbol('a description'); +var baz = Symbol('another description'); + +map.set(foo, 42); + +assert.sameValue(map.delete(baz), false, 'Regular symbol key not present') +assert.sameValue(map.delete(bar), false, "Symbols with the same description don't alias to each other"); +assert.sameValue(map.delete(Symbol.hasInstance), false, 'Well-known symbol key not present'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/shell.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.js new file mode 100644 index 0000000000..1ccbfd4398 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-boolean.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-weakmap.prototype.delete +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(false, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(false, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.js new file mode 100644 index 0000000000..ade3d45c31 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-null.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-weakmap.prototype.delete +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(null, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(null, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.js new file mode 100644 index 0000000000..6437acd104 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-number.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-weakmap.prototype.delete +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(0, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(0, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.js new file mode 100644 index 0000000000..661c0fd4d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-string.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-weakmap.prototype.delete +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call('', {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call('', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.js new file mode 100644 index 0000000000..b3feca5fa5 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-symbol.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-weakmap.prototype.delete +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.delete ( 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() { + WeakMap.prototype.delete.call(Symbol(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(Symbol(), {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.js b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.js new file mode 100644 index 0000000000..3ef3760c22 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/delete/this-not-object-throw-undefined.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-weakmap.prototype.delete +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.delete ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.delete.call(undefined, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.delete.call(undefined, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/browser.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.js new file mode 100644 index 0000000000..387164ec86 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-map.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-weakmap.prototype.get +description: > + Throws a TypeError if `this` is a Map object. +info: | + WeakMap.prototype.get ( key ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Map] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(new Map(), 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.get.call(new Map(), 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot-set.js new file mode 100644 index 0000000000..115f53ec9b --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-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-weakmap.prototype.get +description: > + Throws a TypeError if `this` is a Set object. +info: | + WeakMap.prototype.get ( key ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(new Set(), 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.get.call(new Set(), 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.js new file mode 100644 index 0000000000..ac44156129 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/does-not-have-weakmapdata-internal-slot.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-weakmap.prototype.get +description: > + Throws a TypeError if `this` does not have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.get ( key ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ +var map = new WeakMap(); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call([], 1); +}); + +assert.throws(TypeError, function() { + map.get.call([], 1); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call({}, 1); +}); + +assert.throws(TypeError, function() { + map.get.call({}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/get.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/get.js new file mode 100644 index 0000000000..287b5c1f4b --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.get +description: > + Property type and descriptor. +info: | + WeakMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof WeakMap.prototype.get, + 'function', + '`typeof WeakMap.prototype.get` is `function`' +); + +verifyNotEnumerable(WeakMap.prototype, 'get'); +verifyWritable(WeakMap.prototype, 'get'); +verifyConfigurable(WeakMap.prototype, 'get'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/length.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/length.js new file mode 100644 index 0000000000..eb8f7d546e --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.get +description: > + WeakMap.prototype.get.length value and descriptor. +info: | + WeakMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.get.length, 1, + 'The value of `WeakMap.prototype.get.length` is `1`' +); + +verifyNotEnumerable(WeakMap.prototype.get, 'length'); +verifyNotWritable(WeakMap.prototype.get, 'length'); +verifyConfigurable(WeakMap.prototype.get, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/name.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/name.js new file mode 100644 index 0000000000..ce82cdb4e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.get +description: > + WeakMap.prototype.get.name value and descriptor. +info: | + WeakMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.get.name, 'get', + 'The value of `WeakMap.prototype.get.name` is `"get"`' +); + +verifyNotEnumerable(WeakMap.prototype.get, 'name'); +verifyNotWritable(WeakMap.prototype.get, 'name'); +verifyConfigurable(WeakMap.prototype.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/not-a-constructor.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/not-a-constructor.js new file mode 100644 index 0000000000..ec8be07522 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/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: > + WeakMap.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, WeakMap, arrow-function] +---*/ + +assert.sameValue( + isConstructor(WeakMap.prototype.get), + false, + 'isConstructor(WeakMap.prototype.get) must return false' +); + +assert.throws(TypeError, () => { + let wm = new WeakMap(); new wm.get(); +}, '`let wm = new WeakMap(); new wm.get()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-if-key-cannot-be-held-weakly.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-if-key-cannot-be-held-weakly.js new file mode 100644 index 0000000000..b05b51b67a --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-if-key-cannot-be-held-weakly.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-weakmap.prototype.get +description: > + Returns undefined when key cannot be held weakly. +info: | + WeakMap.prototype.get ( _key_ ) + 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*. +features: [Symbol, WeakMap] +---*/ + +var map = new WeakMap(); + +assert.sameValue(map.get(null), undefined, 'Returns undefined if key is null'); + +assert.sameValue(map.get(NaN), undefined, 'Returns undefined if key is NaN'); + +assert.sameValue( + map.get('foo'), undefined, + 'Returns undefined if key is a String' +); + +assert.sameValue( + map.get(1), undefined, + 'Returns undefined if key is a Number' +); + +assert.sameValue( + map.get(undefined), undefined, + 'Returns undefined if key is undefined' +); + +assert.sameValue( + map.get(Symbol.for('registered symbol')), undefined, + 'Returns undefined if key is a registered Symbol' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-object-key.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-object-key.js new file mode 100644 index 0000000000..3a49d62d7f --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-object-key.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-weakmap.prototype.get +description: > + Returns undefined when an Object key is not on the WeakMap object. +info: | + WeakMap.prototype.get ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not empty and SameValue(_p_.[[Key]], _key_) is *true*, + return _p_.[[Value]]. + 6. Return *undefined*. +features: [WeakMap] +---*/ + +var map = new WeakMap(); +var key = {}; + +assert.sameValue( + map.get(key), undefined, + 'returns undefined if key is not on the weakmap' +); + +map.set(key, 1); +map.set({}, 2); +map.delete(key); +map.set({}, 3); + +assert.sameValue( + map.get(key), undefined, + 'returns undefined if key was deleted' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js new file mode 100644 index 0000000000..a4844b9244 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-undefined-with-symbol-key.js @@ -0,0 +1,37 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.get +description: > + Returns undefined when a Symbol key is not on the WeakMap object. +info: | + WeakMap.prototype.get ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not empty and SameValue(_p_.[[Key]], _key_) is *true*, + return _p_.[[Value]]. + 6. Return *undefined*. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var map = new WeakMap(); +var key = Symbol('a description'); + +assert.sameValue(map.get(key), undefined, 'returns undefined for regular symbol on initially empty map'); +assert.sameValue( + map.get(Symbol.hasInstance), + undefined, + 'returns undefined for well-known symbol on initially empty map' +); + +map.set(key, 1); +map.set(Symbol.hasInstance, 2); +map.delete(key); +map.delete(Symbol.hasInstance); + +assert.sameValue(map.get(key), undefined, 'returns undefined for deleted regular symbol'); +assert.sameValue(map.get(Symbol.hasInstance), undefined, 'returns undefined for deleted well-known symbol'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-object-key.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-object-key.js new file mode 100644 index 0000000000..52875d308e --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-object-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-weakmap.prototype.get +description: > + Returns the value from the specified Object key +info: | + WeakMap.prototype.get ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, return _p_.[[Value]]. +features: [WeakMap] +---*/ + +var foo = {}; +var bar = {}; +var baz = []; +var map = new WeakMap([ + [foo, 0] +]); + +assert.sameValue(map.get(foo), 0); + +map.set(bar, 1); +assert.sameValue(map.get(bar), 1); + +map.set(baz, 2); +assert.sameValue(map.get(baz), 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-symbol-key.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-symbol-key.js new file mode 100644 index 0000000000..e5af39eeee --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/get/returns-value-with-symbol-key.js @@ -0,0 +1,35 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.get +description: > + Returns the value from the specified Symbol key +info: | + WeakMap.prototype.get ( _key_ ) + 3. Let _entries_ be the List that is _M_.[[WeakMapData]]. + 4. If CanBeHeldWeakly(_key_) is *false*, return *undefined*. + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, return _p_.[[Value]]. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var foo = Symbol('a description'); +var bar = Symbol('a description'); +var baz = Symbol('different description'); +var map = new WeakMap([ + [foo, 0], +]); + +assert.sameValue(map.get(foo), 0, 'Regular symbol as key, added in constructor'); + +map.set(bar, 1); +map.set(baz, 2); +assert.sameValue(map.get(baz), 2, 'Regular symbol as key, added with set()'); +assert.sameValue(map.get(bar), 1, "Symbols with the same description don't overwrite each other"); + +map.set(Symbol.hasInstance, 3); +assert.sameValue(map.get(Symbol.hasInstance), 3, 'Well-known symbol as key'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/shell.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/get/this-not-object-throw.js b/js/src/tests/test262/built-ins/WeakMap/prototype/get/this-not-object-throw.js new file mode 100644 index 0000000000..31963d4847 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.get +description: > + Throws a TypeError if `this` value is not an Object. +info: | + WeakMap.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() { + WeakMap.prototype.get.call(false, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(1, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call('', {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(undefined, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(null, {}); +}); + +assert.throws(TypeError, function() { + WeakMap.prototype.get.call(Symbol(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.get.call(false, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/browser.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-array.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-array.js new file mode 100644 index 0000000000..ad586369cc --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-array.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-weakmap.prototype.has +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.has ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call([], {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call([], {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-map.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-map.js new file mode 100644 index 0000000000..5ca9d67eb7 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-map.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-weakmap.prototype.has +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.has ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Map] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call(new Map(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(new Map(), {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-object.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-object.js new file mode 100644 index 0000000000..c83e6471a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-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-weakmap.prototype.has +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.has ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call({}, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call({}, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-set.js new file mode 100644 index 0000000000..f6a493227f --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-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-weakmap.prototype.has +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.has ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call(new Set(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(new Set(), {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js new file mode 100644 index 0000000000..43fa3b4d5e --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/does-not-have-weakmapdata-internal-slot-weakmap-prototype.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-weakmap.prototype.has +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.has ( value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call(WeakMap.prototype, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(WeakMap.prototype, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/has.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/has.js new file mode 100644 index 0000000000..7146168507 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/has.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-weakmap.prototype.has +description: > + WeakMap.prototype.has property descriptor +info: | + WeakMap.prototype.has ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof WeakMap.prototype.has, + 'function', + 'typeof WeakMap.prototype.has is "function"' +); + +verifyNotEnumerable(WeakMap.prototype, 'has'); +verifyWritable(WeakMap.prototype, 'has'); +verifyConfigurable(WeakMap.prototype, 'has'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/length.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/length.js new file mode 100644 index 0000000000..a68fa8ecec --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.has +description: > + WeakMap.prototype.has.length value and writability. +info: | + WeakMap.prototype.has ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.has.length, 1, + 'The value of WeakMap.prototype.has.length is 1' +); + +verifyNotEnumerable(WeakMap.prototype.has, 'length'); +verifyNotWritable(WeakMap.prototype.has, 'length'); +verifyConfigurable(WeakMap.prototype.has, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/name.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/name.js new file mode 100644 index 0000000000..558f24335d --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.has +description: > + WeakMap.prototype.has.name value and writability. +info: | + WeakMap.prototype.has ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.has.name, 'has', + 'The value of WeakMap.prototype.has.name is "has"' +); + +verifyNotEnumerable(WeakMap.prototype.has, 'name'); +verifyNotWritable(WeakMap.prototype.has, 'name'); +verifyConfigurable(WeakMap.prototype.has, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/not-a-constructor.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/not-a-constructor.js new file mode 100644 index 0000000000..83df17bbf5 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/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: > + WeakMap.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, WeakMap, arrow-function] +---*/ + +assert.sameValue( + isConstructor(WeakMap.prototype.has), + false, + 'isConstructor(WeakMap.prototype.has) must return false' +); + +assert.throws(TypeError, () => { + let wm = new WeakMap(); new wm.has(); +}, '`let wm = new WeakMap(); new wm.has()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-key-cannot-be-held-weakly.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-key-cannot-be-held-weakly.js new file mode 100644 index 0000000000..c570a66518 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-key-cannot-be-held-weakly.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-weakmap.prototype.has +description: > + Returns false if the key cannot be held weakly +info: | + WeakMap.prototype.has ( _key_ ) + 4. If CanBeHeldWeakly(_key_) is *false*, return *false*. +features: [Symbol, WeakMap] +---*/ + +var map = new WeakMap(); + +assert.sameValue(map.has(1), false); +assert.sameValue(map.has(''), false); +assert.sameValue(map.has(null), false); +assert.sameValue(map.has(undefined), false); +assert.sameValue(map.has(true), false); +assert.sameValue(map.has(Symbol.for('registered symbol')), false, 'Registered symbol not allowed as key'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-object-key-not-present.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-object-key-not-present.js new file mode 100644 index 0000000000..a1fab07546 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-object-key-not-present.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-weakmap.prototype.has +description: > + Return false when an Object key is not present in the WeakMap entries. +info: | + WeakMap.prototype.has ( _key_ ) + 6. Return *false*. +features: [WeakMap] +---*/ + +var foo = {}; +var bar = {}; +var map = new WeakMap(); + +assert.sameValue(map.has(foo), false); + +map.set(foo, 1); +assert.sameValue(map.has(bar), false); + +map.delete(foo); +assert.sameValue(map.has(foo), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-symbol-key-not-present.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-symbol-key-not-present.js new file mode 100644 index 0000000000..5f379d685a --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-false-when-symbol-key-not-present.js @@ -0,0 +1,31 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.has +description: > + Return false when a Symbol key is not present in the WeakMap entries. +info: | + WeakMap.prototype.has ( _key_ ) + 6. Return *false*. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var foo = Symbol('a description'); +var bar = Symbol('a description'); +var map = new WeakMap(); + +assert.sameValue(map.has(foo), false, 'Map is initially empty of regular symbol'); +assert.sameValue(map.has(Symbol.hasInstance), false, 'Map is initially empty of well-known symbol'); + +map.set(foo, 1); +assert.sameValue(map.has(bar), false, "Symbols with the same description don't alias each other"); + +map.delete(foo); +assert.sameValue(map.has(foo), false, 'Map is empty again of regular symbol after deleting'); + +map.set(Symbol.hasInstance, 2); +map.delete(Symbol.hasInstance); +assert.sameValue(map.has(Symbol.hasInstance), false, 'Map is empty again of well-known symbol after deleting'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-object-key-present.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-object-key-present.js new file mode 100644 index 0000000000..910a816609 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-object-key-present.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.has +description: > + Returns true when an Object key is present in the WeakMap entries list. +info: | + WeakMap.prototype.has ( _key_ ) + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, return *true*. +features: [WeakMap] +---*/ + +var foo = {}; +var map = new WeakMap(); + +map.set(foo, 1); +assert.sameValue(map.has(foo), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-symbol-key-present.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-symbol-key-present.js new file mode 100644 index 0000000000..827543f947 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/returns-true-when-symbol-key-present.js @@ -0,0 +1,30 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.has +description: > + Returns true when an Object key is present in the WeakMap entries list. +info: | + WeakMap.prototype.has ( _key_ ) + 5. For each Record {[[Key]], [[Value]]} _p_ of _entries_, do + a. If _p_.[[Key]] is not ~empty~ and SameValue(_p_.[[Key]], _key_) is + *true*, return *true*. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var foo = Symbol('a description'); +var bar = Symbol('a description'); +var map = new WeakMap(); + +map.set(foo, 1); +map.set(bar, 2); +assert.sameValue(map.has(foo), true, "Regular symbol as key"); + +map.delete(foo); +assert.sameValue(map.has(bar), true, "Symbols with the same description don't alias each other"); + +map.set(Symbol.hasInstance, 3); +assert.sameValue(map.has(Symbol.hasInstance), true, "Well-known symbol as key"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/shell.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-boolean.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-boolean.js new file mode 100644 index 0000000000..ccf9b1e6ec --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-boolean.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-weakmap.prototype.has +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.has ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call(false, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(false, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-null.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-null.js new file mode 100644 index 0000000000..b90fb80613 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-null.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-weakmap.prototype.has +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.has ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call(null, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(null, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-number.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-number.js new file mode 100644 index 0000000000..2beb7d5d0f --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-number.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-weakmap.prototype.has +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.has ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call(0, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(0, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-string.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-string.js new file mode 100644 index 0000000000..b4f82cf17a --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-string.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-weakmap.prototype.has +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.has ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call('', {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call('', {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-symbol.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-symbol.js new file mode 100644 index 0000000000..0c80ffd07e --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-symbol.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-weakmap.prototype.has +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.has ( 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() { + WeakMap.prototype.has.call(Symbol(), {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(Symbol(), {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-undefined.js b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-undefined.js new file mode 100644 index 0000000000..f8138cc349 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/has/this-not-object-throw-undefined.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-weakmap.prototype.has +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.has ( value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.has.call(undefined, {}); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.has.call(undefined, {}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/prototype-attributes.js b/js/src/tests/test262/built-ins/WeakMap/prototype/prototype-attributes.js new file mode 100644 index 0000000000..74158956fc --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/prototype-attributes.js @@ -0,0 +1,14 @@ +// 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-weakmap.prototype +description: > + WeakMap.prototype is not writable, not enumerable and not configurable. +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(WeakMap, 'prototype'); +verifyNotWritable(WeakMap, 'prototype'); +verifyNotConfigurable(WeakMap, 'prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-object-element.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-object-element.js new file mode 100644 index 0000000000..897b047e80 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-object-element.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-weakmap.prototype.set +description: > + Adds a value with an Object key. +info: | + WeakMap.prototype.set ( _key_, _value_ ) + 6. Let _p_ be the Record {[[Key]]: _key_, [[Value]]: _value_}. + 7. Append _p_ as the last element of _entries_. +features: [WeakMap] +---*/ + +var map = new WeakMap(); +var foo = {}; +var bar = {}; +var baz = {}; + +map.set(foo, 1); +map.set(bar, 2); +map.set(baz, 3); + +assert(map.has(foo)); +assert(map.has(bar)); +assert(map.has(baz)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-symbol-element.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-symbol-element.js new file mode 100644 index 0000000000..f23ea6b54f --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/adds-symbol-element.js @@ -0,0 +1,26 @@ +// |reftest| shell-option(--enable-symbols-as-weakmap-keys) skip-if(release_or_beta||!xulRuntime.shell) -- symbols-as-weakmap-keys is not released yet, requires shell-options +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.set +description: Adds a value with a Symbol key. +info: | + WeakMap.prototype.set ( _key_, _value_ ) + 6. Let _p_ be the Record {[[Key]]: _key_, [[Value]]: _value_}. + 7. Append _p_ as the last element of _entries_. +features: [Symbol, WeakMap, symbols-as-weakmap-keys] +---*/ + +var map = new WeakMap(); +var foo = Symbol('a description'); +var bar = Symbol('a description'); + +map.set(foo, 1); +map.set(bar, 2); +map.set(Symbol.hasInstance, 3); + +assert(map.has(bar), 'Regular symbol as key'); +assert.sameValue(map.get(foo), 1, "Symbols with the same description don't overwrite each other"); +assert(map.has(Symbol.hasInstance), 'Well-known symbol as key'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/browser.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.js new file mode 100644 index 0000000000..490cbd751a --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-array.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-weakmap.prototype.set +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... + +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call([], {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call([], {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.js new file mode 100644 index 0000000000..d07b8f16c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-map.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-weakmap.prototype.set +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Map] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(new Map(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(new Map(), {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-object.js new file mode 100644 index 0000000000..e31e8c6be1 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-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-weakmap.prototype.set +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call({}, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call({}, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-set.js new file mode 100644 index 0000000000..5efcf091cf --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-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-weakmap.prototype.set +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(new Set(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(new Set(), {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js new file mode 100644 index 0000000000..e60c46b13b --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/does-not-have-weakmapdata-internal-slot-weakmap-prototype.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-weakmap.prototype.set +description: > + Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. +info: | + WeakMap.prototype.set ( key, value ) + + ... + 3. If M does not have a [[WeakMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(WeakMap.prototype, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(WeakMap.prototype, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/length.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/length.js new file mode 100644 index 0000000000..052f181e53 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/length.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-weakmap.prototype.set +description: WeakMap.prototype.set.length descriptor +info: | + WeakMap.prototype.set ( key, value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.set.length, 2, + 'The value of `WeakMap.prototype.set.length` is `2`' +); + +verifyNotEnumerable(WeakMap.prototype.set, 'length'); +verifyNotWritable(WeakMap.prototype.set, 'length'); +verifyConfigurable(WeakMap.prototype.set, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/name.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/name.js new file mode 100644 index 0000000000..f1d62ffef5 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/name.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-weakmap.prototype.set +description: WeakMap.prototype.set.name descriptor +info: | + WeakMap.prototype.set ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + WeakMap.prototype.set.name, 'set', + 'The value of WeakMap.prototype.set.name is "set"' +); + +verifyNotEnumerable(WeakMap.prototype.set, 'name'); +verifyNotWritable(WeakMap.prototype.set, 'name'); +verifyConfigurable(WeakMap.prototype.set, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/not-a-constructor.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/not-a-constructor.js new file mode 100644 index 0000000000..c8d6272217 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/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: > + WeakMap.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, WeakMap, arrow-function] +---*/ + +assert.sameValue( + isConstructor(WeakMap.prototype.set), + false, + 'isConstructor(WeakMap.prototype.set) must return false' +); + +assert.throws(TypeError, () => { + let wm = new WeakMap(); new wm.set({}, 1); +}, '`let wm = new WeakMap(); new wm.set({}, 1)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.js new file mode 100644 index 0000000000..9f96f5e2f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this-when-ignoring-duplicate.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-weakmap.prototype.set +description: Returns `this` when new value is duplicate. +info: | + WeakMap.prototype.set ( key, value ) + + 1. Let M be the this value. + ... + 6. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValue(p.[[key]], key) is true, then + i. Set p.[[value]] to value. + ii. Return M. + ... +---*/ + +var foo = {}; +var map = new WeakMap([ + [foo, 1] +]); + +assert.sameValue(map.set(foo, 1), map, '`map.set(foo, 1)` returns `map`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this.js new file mode 100644 index 0000000000..dd30cc2e77 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/returns-this.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-weakmap.prototype.set +description: Returns `this` after setting a new value. +info: | + WeakMap.prototype.set ( key, value ) + + 1. Let M be this value. + ... + 9. Return M. + +---*/ + +var map = new WeakMap(); + +assert.sameValue(map.set({}, 1), map, '`map.set({}, 1)` returns `map`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/set.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/set.js new file mode 100644 index 0000000000..7ec5dd82c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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-weakmap.prototype.set +description: WeakMap.prototype.set property descriptor +info: | + WeakMap.prototype.set ( key, value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof WeakMap.prototype.set, + 'function', + 'typeof WeakMap.prototype.set is "function"' +); + +verifyNotEnumerable(WeakMap.prototype, 'set'); +verifyWritable(WeakMap.prototype, 'set'); +verifyConfigurable(WeakMap.prototype, 'set'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/shell.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-boolean.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-boolean.js new file mode 100644 index 0000000000..98b2fd02f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-boolean.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-weakmap.prototype.set +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.set ( key, value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(false, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(false, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-null.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-null.js new file mode 100644 index 0000000000..7a24860890 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-null.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-weakmap.prototype.set +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.set ( key, value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(null, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(null, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-number.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-number.js new file mode 100644 index 0000000000..1af785afca --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-number.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-weakmap.prototype.set +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.set ( key, value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(0, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(0, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-string.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-string.js new file mode 100644 index 0000000000..d689e80daa --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-string.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-weakmap.prototype.set +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.set ( key, value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call('', {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call('', {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-symbol.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-symbol.js new file mode 100644 index 0000000000..47522549f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-symbol.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-weakmap.prototype.set +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.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() { + WeakMap.prototype.set.call(Symbol(), {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(Symbol(), {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-undefined.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-undefined.js new file mode 100644 index 0000000000..188043687b --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/this-not-object-throw-undefined.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-weakmap.prototype.set +description: Throws TypeError if `this` is not Object. +info: | + WeakMap.prototype.set ( key, value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap.prototype.set.call(undefined, {}, 1); +}); + +assert.throws(TypeError, function() { + var map = new WeakMap(); + map.set.call(undefined, {}, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/set/throw-if-key-cannot-be-held-weakly.js b/js/src/tests/test262/built-ins/WeakMap/prototype/set/throw-if-key-cannot-be-held-weakly.js new file mode 100644 index 0000000000..ee115dae86 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/prototype/set/throw-if-key-cannot-be-held-weakly.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-weakmap.prototype.set +description: Throws TypeError if key cannot be held weakly. +info: | + WeakMap.prototype.set ( _key_, _value_ ) + 4. If CanBeHeldWeakly(_key_) is *false*, throw a *TypeError* exception. +features: [Symbol, WeakMap] +---*/ + +var s = new WeakMap(); + +assert.throws(TypeError, function() { + s.set(1, 1); +}); + +assert.throws(TypeError, function() { + s.set(false, 1); +}); + +assert.throws(TypeError, function() { + s.set(undefined, 1); +}); + +assert.throws(TypeError, function() { + s.set('string', 1); +}); + +assert.throws(TypeError, function() { + s.set(null, 1); +}); + +assert.throws(TypeError, function() { + s.set(Symbol.for('registered symbol'), 1); +}, 'Registered symbol not allowed as WeakMap key'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/prototype/shell.js b/js/src/tests/test262/built-ins/WeakMap/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/WeakMap/set-not-callable-throws.js b/js/src/tests/test262/built-ins/WeakMap/set-not-callable-throws.js new file mode 100644 index 0000000000..34a817c77e --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/set-not-callable-throws.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-weakmap-iterable +description: > + Throws TypeError if add is not callable on constructor call. +info: | + 23.3.1.1 WeakMap ( [ iterable ] ) + + ... + 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. + ... +---*/ + +WeakMap.prototype.set = null; +new WeakMap(); + +assert.throws(TypeError, function() { + new WeakMap([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/shell.js b/js/src/tests/test262/built-ins/WeakMap/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/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/WeakMap/undefined-newtarget.js b/js/src/tests/test262/built-ins/WeakMap/undefined-newtarget.js new file mode 100644 index 0000000000..f4e3dbe2f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/undefined-newtarget.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap-iterable +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 23.3.1.1 WeakMap ( [ iterable ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + WeakMap(); +}); + +assert.throws(TypeError, function() { + WeakMap([]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/WeakMap/weakmap.js b/js/src/tests/test262/built-ins/WeakMap/weakmap.js new file mode 100644 index 0000000000..0ba649d224 --- /dev/null +++ b/js/src/tests/test262/built-ins/WeakMap/weakmap.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-weakmap-iterable +description: > + WeakMap ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(this, 'WeakMap'); +verifyWritable(this, 'WeakMap'); +verifyConfigurable(this, 'WeakMap'); + +reportCompare(0, 0); -- cgit v1.2.3