`Array.prototype.at` / `with` / `toReversed` / `toSorted` / `toSpliced` check `[[HasProperty]]` before reading elements

Open Beginner friendly
#634 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
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, javascript
Domain
backend, compilers

Research direction

In quickjs.c, inspect the slow paths in js_array_at, js_array_with, js_array_toReversed, js_array_toSpliced, and js_array_toSorted, and compare JS_TryGetPropertyInt64 with JS_GetPropertyInt64. Start by running the provided Proxy example with ./qjs; done means the methods use [[Get]] without triggering has traps and produce the expected values.

Written by the indexing model from the issue text.

Description

Array.prototype.at, with, toReversed, toSorted, and toSpliced read non-fast-array elements with [[HasProperty]] before [[Get]] instead of [[Get]] alone, so a Proxy receiver sees unexpected has trap calls and gets undefined whenever has returns false (for example, a virtual array Proxy with only a get trap).

// t.js
const v = new Proxy([], {
  get(t, k, r) {
    if (k === "length") return 3;
    if (k === "0" || k === "1" || k === "2") return (Number(k) + 1) * 10;
    return Reflect.get(t, k, r);
  }
});
console.log(v[1], v.at(1), v.toReversed().map(String).join(","));

function run(name, f) {
  const log = [];
  f(new Proxy([1, 2, 3], { has(t, k) { log.push("has:" + String(k)); return Reflect.has(t, k); } }));
  console.log(name + ": " + (log.length ? log.join(",") : "-"));
}
run("at", p => p.at(1));
run("with", p => p.with(0, 9));
run("toReversed", p => p.toReversed());
run("toSorted", p => p.toSorted());
run("toSpliced", p => p.toSpliced(0, 1));

Running ./qjs t.js prints:

20 undefined undefined,undefined,undefined
at: has:1
with: has:1,has:2
toReversed: has:2,has:1,has:0
toSorted: has:0,has:1,has:2
toSpliced: has:1,has:2

Expected (Node.js v26.13.0; Array.prototype.at):

20 20 30,20,10
at: -
with: -
toReversed: -
toSorted: -
toSpliced: -

In quickjs.c, the slow paths of js_array_at, js_array_with, js_array_toReversed, js_array_toSpliced, and js_array_toSorted call JS_TryGetPropertyInt64 (which checks JS_HasProperty before JS_GetPropertyValue) instead of JS_GetPropertyInt64.

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.