diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Array/prototype/flatMap/this-value-ctor-object-species.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/flatMap/this-value-ctor-object-species.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Array/prototype/flatMap/this-value-ctor-object-species.js | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/flatMap/this-value-ctor-object-species.js b/js/src/tests/test262/built-ins/Array/prototype/flatMap/this-value-ctor-object-species.js new file mode 100644 index 0000000000..25106bdbe2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/flatMap/this-value-ctor-object-species.js @@ -0,0 +1,159 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.flatMap +description: > + Assert behavior if this value has a custom object constructor property +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let sourceLen be ? ToLength(? Get(O, "length")). + ... + 5. Let A be ? ArraySpeciesCreate(O, 0). + ... + + ArraySpeciesCreate ( originalArray, length ) + + 3. Let isArray be ? IsArray(originalArray). + 4. If isArray is false, return ? ArrayCreate(length). + 5. Let C be ? Get(originalArray, "constructor"). + 6. If IsConstructor(C) is true, then + a. Let thisRealm be the current Realm Record. + b. Let realmC be ? GetFunctionRealm(C). + c. If thisRealm and realmC are not the same Realm Record, then + i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined. + 7. If Type(C) is Object, then + a. Set C to ? Get(C, @@species). + b. If C is null, set C to undefined. + 8. If C is undefined, return ? ArrayCreate(length). + 9. If IsConstructor(C) is false, throw a TypeError exception. + 10. Return ? Construct(C, « length »). +features: [Array.prototype.flatMap, Symbol, Symbol.species] +includes: [compareArray.js] +---*/ + +assert.sameValue( + typeof Array.prototype.flatMap, + 'function', + 'The value of `typeof Array.prototype.flatMap` is expected to be "function"' +); + +var arr = [[42, 1], [42, 2]]; +var mapperFn = function(e) { return e; }; + +arr.constructor = {}; +var actual = arr.flatMap(mapperFn); +assert.compareArray(actual, [42, 1, 42, 2], 'The value of actual is expected to be [42, 1, 42, 2]'); +assert.sameValue( + Object.getPrototypeOf(actual), + Array.prototype, + 'Object.getPrototypeOf(arr.flatMap(mapperFn)) returns Array.prototype' +); + +var called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return null; + } +}; +actual = arr.flatMap(mapperFn); +assert.compareArray(actual, [42, 1, 42, 2], 'The value of actual is expected to be [42, 1, 42, 2]'); +assert.sameValue( + Object.getPrototypeOf(actual), + Array.prototype, + 'Object.getPrototypeOf(arr.flatMap(mapperFn)) returns Array.prototype' +); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return undefined; + } +}; +actual = arr.flatMap(mapperFn); +assert.compareArray(actual, [42, 1, 42, 2], 'The value of actual is expected to be [42, 1, 42, 2]'); +assert.sameValue( + Object.getPrototypeOf(actual), + Array.prototype, + 'Object.getPrototypeOf(arr.flatMap(mapperFn)) returns Array.prototype' +); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return 0; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return ''; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return false; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return {}; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return []; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return Symbol(); + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); + +reportCompare(0, 0); |