`Array` constructor stores elements with `[[Set]]` instead of `CreateDataPropertyOrThrow`

Open Beginner friendly
#633 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
backend

Research direction

Start in quickjs.c at js_array_constructor around line 43086 and compare its element loop with js_array_of, which the issue says uses JS_CreateDataPropertyUint32. Reproduce the reported prototype getter and setter cases with the supplied JavaScript snippet using ./qjs t.js. Done means the constructor creates own indexed data properties and produces the expected output in all three cases.

Written by the indexing model from the issue text.

Description

When Array (or an Array subclass) is called with two or more arguments or a single non-Number argument, QuickJS stores the elements via [[Set]] instead of defining own data properties, so an indexed getter, setter, or non-writable property on the prototype chain causes TypeError or runs the prototype setter instead of creating the element.

// t.js
class Sub extends Array {
  get 0() { return "proto"; }
}
try {
  console.log(JSON.stringify(new Sub(10, 20)));
} catch (e) {
  console.log(e.name + ": " + e.message);
}

Object.defineProperty(Array.prototype, 1, { get() { return "proto"; }, configurable: true });
try {
  console.log(JSON.stringify(new Array(1, 2, 3)));
} catch (e) {
  console.log(e.name + ": " + e.message);
}
delete Array.prototype[1];

let seen;
Object.defineProperty(Array.prototype, 0, { set(v) { seen = v; }, configurable: true });
let a = new Array("x");
console.log(seen, Object.hasOwn(a, 0), a.length);

Running ./qjs t.js prints:

TypeError: no setter for property
TypeError: no setter for property
x false 0

Expected (Node.js v26.13.0; Array ( ...values )):

[10,20]
[1,2,3]
undefined true 1

In js_array_constructor (quickjs.c:43086), the element loop calls JS_SetPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i])) instead of JS_CreateDataPropertyUint32(ctx, obj, i, JS_DupValue(ctx, argv[i]), JS_PROP_THROW) (which js_array_of uses).

Versions: QuickJS master 2519774 (2026-11-23) and release 2026-06-04 (3d5e064), Linux x86_64.

Credit: https://ucsbplse.github.io/

Dominant language
C
Stars
11.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bellard/quickjs

All issues in bellard/quickjs

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.