nodejs / nodejs/node-api-cts

Some tests assert V8's exact error message wording, so non-V8 runtimes fail on prose

オープン
#84 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

説明

To see how far a non-V8 runtime gets, I ran the suite under Bun 1.3.14 (JavaScriptCore)
on Linux, with the addons rebuilt with GCC and the tests spawned the same way the node
implementor does. 43 of the 48 test files pass. Of the five failures, two are genuine
Node-API gaps in Bun (zero length external strings and Float16Array in the typed array
APIs, both since fixed on Bun's main branch). The other three fail only because the test
compares the thrown error's message text against V8's exact wording, and JavaScriptCore
words the same conditions differently. The same three files fail identically on Windows
with MSVC-built addons, which is where the quoted output below comes from.

The affected assertions:

test expects JSC actually throws
test_constructor/test.js line 15 /^TypeError: Cannot assign to read only property 'readonlyValue' of object '#<MyObject>'$/ TypeError: Attempted to assign to readonly property.
test_constructor/test.js lines 38, 42 /^TypeError: Cannot set property .* of #<.*> which has only a getter$/ TypeError: Attempted to assign to readonly property.
test_properties/test.js line 16 /^TypeError: Cannot assign to read only property '.*' of object '#<Object>'$/ TypeError: Attempted to assign to readonly property.
test_properties/test.js lines 55, 59 /^TypeError: Cannot set property .* of #<Object> which has only a getter$/ TypeError: Attempted to assign to readonly property.
test_bigint/test.js line 46 { name: 'RangeError', message: 'Maximum BigInt size exceeded' } RangeError: Out of memory

Three files, seven assertion sites, and it comes down to two JSC strings. Each run stops
at its first failing assertion, so the later sites in each file were confirmed by
evaluating the same operations directly under Bun in strict mode; JSC uses the single
Attempted to assign to readonly property. message for both the read only data property
and the getter-only accessor cases.

A representative failure from the run:

AssertionError: The input did not match the regular expression /^TypeError: Cannot assign to read only property 'readonlyValue' of object '#<MyObject>'$/. Input:

'TypeError: Attempted to assign to readonly property.'

and for the BigInt case:

Comparison {
+   message: 'Out of memory',
-   message: 'Maximum BigInt size exceeded',
    name: 'RangeError'
  }

What these assertions actually verify is real Node-API behavior: that
napi_define_properties produced a property that rejects writes with a TypeError, and
that the engine's own RangeError from an oversized BigInt propagates out of
napi_create_bigint_words as the pending exception. That part holds in Bun. The message
text on top of it is engine identity rather than conformance, and every non-V8 engine
(JSC here, Hermes and SpiderMonkey elsewhere) words it its own way, so as written a
conformant runtime scores red on strings it cannot change. The regexes came along
naturally with the ports from nodejs/node, where a single-engine assumption was fine.

A few possible directions, and I would rather follow your preference than pick one:

  1. Assert the error type and the behavior (the write throws and does not take effect,
    the BigInt call throws a RangeError) and drop the message text entirely.
  2. Keep a message assertion but loosen it to a shape every engine can meet, for example
    just /TypeError/, or name plus a much weaker pattern.
  3. Keep exact messages but make the expected strings per implementor, in the same spirit
    as features.js already being per implementor.

Happy to send a PR for whichever direction you want, or none if you would rather handle
it differently.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

test_constructor/test.js、test_properties/test.js、test_bigint/test.js のアサーション箇所から始め、その後、Bun または別の非 V8 ランタイムでこれらのテストを実行します。エンジン固有のメッセージの扱いについて maintainer が推奨する方向性を確認します。完了の条件は、テストが V8 の正確な文言を要求せずに示された動作を検証し、関連するランタイムでパスすることです。

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

評価

技術スタック
bun, javascript, node.js
領域
testing-qa
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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