[P2] Compiler: indirect toSorted calls ignore arguments.length

クローズ
#3,534 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

関連するプルリクエストがすでにマージされています。

  • #3552 @nickna による — マージ済み

評価

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

調査の方向性

Start by comparing the compiled indirect Array.prototype.toSorted.apply(args, []) path with the inline .call(args) path and the descriptor-aware generic helper mentioned in the issue. Run the unchecked classic JavaScript reproducer with --no-tsconfig --noLib and compare its output with Node v22.23.2. Done means the compiled indirect call reads the JavaScript length property once and produces 2 1.

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

説明

Compiled dynamic Array.prototype.toSorted calls use the backing arguments storage count instead of the JavaScript length property.

function f(a, b) {
    const args = arguments;
    let reads = 0;
    Object.defineProperty(args, "length", { get() { reads++; return 1; } });
    const sortCopy = Array.prototype.toSorted;
    console.log(sortCopy.apply(args, []).join(","), reads);
}
f(2, 1);

Node v22.23.2 prints 2 1. The compiled standalone outputs on clean main at cabb41636 and #3510 at 66d78c4ff both print 1,2 0. Both assemblies passed full saved IL verification. Run the source as an unchecked classic .js file with --no-tsconfig --noLib.

The indirect apply path differs from the inline Array.prototype.toSorted.call(args) path, which uses the descriptor-aware generic helper in #3510. Found while auditing related length checks in #3533.

主要言語
C#
スター
156
フォーク
4
平均マージ
15時間 35分
マージ済み PR(30日)
43

環境構築

はじめの一歩

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

nickna/SharpTS のほかの issue

nickna/SharpTS の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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