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

オープン 初心者向け
#634 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
86/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, javascript
領域
backend, compilers

調査の方向性

quickjs.c で js_array_at、js_array_with、js_array_toReversed、js_array_toSpliced、js_array_toSorted の低速パスを調べ、JS_TryGetPropertyInt64 と JS_GetPropertyInt64 を比較します。まず、提供された Proxy の例を ./qjs で実行します。メソッドが has トラップを発生させずに [[Get]] を使用し、期待される値を生成すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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/

主要言語
C
スター
11.1k
フォーク
1.2k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bellard/quickjs のほかの issue

bellard/quickjs の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。