Debian Codegraph @

js/src/tests/test262/built-ins/Array/fromAsync/this-constructor-with-readonly-length.js

raw
1 // |reftest| async
2 // Copyright (C) 2023 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-array.fromasync
7 description: >
8 Promise is rejected if length property on an instance of a custom this-value
9 is non-writable
10 info: |
11 3.j.ii.4.a. Perform ? Set(_A_, *"length"*, 𝔽(_k_), *true*).
12 ...
13 3.k.viii. Perform ? Set(_A_, *"length"*, 𝔽(_len_), *true*).
14
15 Note that there is no difference between strict mode and sloppy mode, because
16 we are not following runtime evaluation semantics.
17 includes: [asyncHelpers.js]
18 flags: [async]
19 features: [Array.fromAsync]
20 ---*/
21
22 asyncTest(async function () {
23 function MyArray() {
24 Object.defineProperty(this, "length", {
25 enumerable: true,
26 writable: false,
27 configurable: true,
28 value: 99
29 });
30 }
31
32 await assert.throwsAsync(TypeError, () => Array.fromAsync.call(MyArray, [0, 1, 2]), "Setting read-only length fails");
33 await assert.throwsAsync(TypeError, () => Array.fromAsync.call(MyArray, {
34 length: 3,
35 0: 0,
36 1: 1,
37 2: 2
38 }), "Setting read-only length fails in array-like case");
39 });