wasm/web: o.isPrototypeOf(x) and o.hasOwnProperty(k) throw "Cannot convert undefined or null to object"
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, rust, typescript
調査の方向性
まず crates/perry-codegen-wasm/src/wasm_runtime.js の mem_call、mem_call_i32 と、それらのディスパッチテーブルを確認してください。ブリッジの検索がテーブル自身のプロパティのみを受け入れるかを調べ、その後、isPrototypeOf、hasOwnProperty、propertyIsEnumerable という名前の呼び出しを対象とする perry-codegen-wasm のユニットテストを追加してください。これらの呼び出しがレシーバーのメソッドに到達し、テストが通れば完了です。クラスのプロトタイプチェーンの動作は別途追跡します。
索引モデルが issue の本文から書いたものです。
説明
On --target web, calling a method whose name is also an Object.prototype member — isPrototypeOf, hasOwnProperty, propertyIsEnumerable — on an object throws Cannot convert undefined or null to object. The same method called through .call works.
class A {}
class B extends A {}
const base: any = { k: 1 };
const child: any = { own: 2 };
Object.setPrototypeOf(child, base);
const typed: { k: number } = { k: 1 };
const show = (label: string, f: () => any) => { try { console.log(label + ": " + f()); } catch (e: any) { console.log(label + ": threw " + e.message); } };
show("base.isPrototypeOf(child)", () => base.isPrototypeOf(child));
show("Object.prototype.isPrototypeOf({})", () => Object.prototype.isPrototypeOf({}));
show("child.hasOwnProperty('own')", () => child.hasOwnProperty("own"));
show("typed.hasOwnProperty('k')", () => typed.hasOwnProperty("k"));
show("child.propertyIsEnumerable('own')", () => child.propertyIsEnumerable("own"));
show("A.isPrototypeOf(B)", () => A.isPrototypeOf(B));
show("A.prototype.isPrototypeOf(new B())", () => A.prototype.isPrototypeOf(new B()));
show("Object.prototype.hasOwnProperty.call(child, 'own') (control)", () => Object.prototype.hasOwnProperty.call(child, "own"));
| case | Node 26.12.1 | --target web on main |
|---|---|---|
base.isPrototypeOf(child) |
true |
threw Cannot convert undefined or null to object |
Object.prototype.isPrototypeOf({}) |
true |
threw Cannot convert undefined or null to object |
child.hasOwnProperty('own') |
true |
threw Cannot convert undefined or null to object |
typed.hasOwnProperty('k') |
true |
threw Cannot convert undefined or null to object |
child.propertyIsEnumerable('own') |
true |
threw Cannot convert undefined or null to object |
A.isPrototypeOf(B) |
true |
threw Cannot convert undefined or null to object |
A.prototype.isPrototypeOf(new B()) |
true |
threw Cannot convert undefined or null to object |
Object.prototype.hasOwnProperty.call(child, 'own') (control) |
true |
true |
Run with perry compile fc.ts --target web -o fc.html, then node scripts/parity_web_host.cjs fc.html. Tested on macOS arm64 against main at 88b1e37142, with Node 26.12.1.
Cause. A method call the emitter does not special-case reaches mem_call under the method's own name, with the receiver as the first argument. mem_call looks that name up with a plain index, __memDispatch[name] (crates/perry-codegen-wasm/src/wasm_runtime.js:1419, and __perryUiDispatch[name] at :1424; mem_call_i32 at :1447). Both tables are object literals, so __memDispatch["isPrototypeOf"] is Object.prototype.isPrototypeOf itself. mem_call calls it as a bridge, coreFn(...args), with no receiver, and it throws. A name that is not an Object.prototype member misses both tables and falls through to __classDispatch(receiver, name, args), which calls the receiver's method. The control is Object.prototype.hasOwnProperty.call(child, "own"), which does not go through the method-name lookup.
Proposed fix. mem_call and mem_call_i32 take only a table's own bridges (Object.prototype.hasOwnProperty.call(table, name)), so these names fall through to __classDispatch like any other method. I'll send a PR with a perry-codegen-wasm unit test.
With that fix, the two class rows stop throwing but print false: A.isPrototypeOf(B) also needs #15053 (B's class value inherits from A's), and A.prototype.isPrototypeOf(new B()) needs instances and class prototypes to share one prototype chain (filed separately).
- 主要言語
- Rust
- スター
- 4.9k
- フォーク
- 166
- 平均マージ
- 6時間 5分
- マージ済み PR(30日)
- 949
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PerryTS/perry のほかの issue
-
area:stdlib effort:S impact:med platform:linux type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
area:compiler effort:S impact:low platform:wasm type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
area:compiler effort:S impact:low platform:wasm type:chore
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
area:compiler effort:S impact:med platform:wasm type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
area:compiler effort:S impact:low platform:wasm type:chore
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 76/100
416rehman/Guardrails#1716 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
dginev/latexml-oxide#943 ·
メンテナーはふだん 1 日以内に返信
-
bug ready
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
MartinPTielemans/ilo#3731 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
oetiker/shadcn-egui#50 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
vymalo/another-agentic-system#412 ·
メンテナーはふだん 1 日以内に返信