Repository navigation
fix(intl): built-in Intl functions have no own prototype (#5904) - #6707
Conversation
) The Intl method/getter/bound functions were created via `js_closure_alloc` without being flagged non-constructable, so `function_would_have_own_prototype` lazily synthesized a `.prototype` object for them and left them dynamically `new`-able — unlike ordinary built-ins (`Math.max`, `Array.prototype.map`), which correctly report `hasOwnProperty("prototype") === false` and `isConstructor === false`. ECMA-262 §17: a built-in function only gets the auto-created `.prototype` when it implements [[Construct]]. Mark the closures built by the three shared Intl installation helpers — `install_function` (prototype methods, the static `supportedLocalesOf`, and the this-based `formatRange`/`formatRangeToParts`), `install_bound_instance_function` (bound instance methods), and the accessor-getter path in `install_constructor` (the `get …format` accessor) — non-constructable, the same flag the native-module builtin methods carry. The constructor closures themselves are untouched. Fixes 20 test262 intl402 cases across every Intl service (6 NumberFormat, 6 DateTimeFormat, 3 Collator, 2 PluralRules, 2 DurationFormat, 1 Intl.supportedValuesOf) with zero regressions on the intl402 slice (3100 -> 3120 pass). Adds a gap test asserting the ECMA-262 §17 function surface, byte-identical to node. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughIntl builtin installation now marks non-constructor functions as non-constructable, preventing own ChangesIntl builtin constructability
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test-files/test_gap_intl_builtin_fn_no_prototype_5904.ts (1)
1-6: 🎯 Functional Correctness | 🔵 TrivialRun the gap suite with Node 26.5.0. The pinned runtime in
.node-versionis 26.5.0, and the current Node is v24.15.0.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test-files/test_gap_intl_builtin_fn_no_prototype_5904.ts` around lines 1 - 6, Run the gap suite for test-files/test_gap_intl_builtin_fn_no_prototype_5904.ts using Node 26.5.0, matching the version pinned in .node-version; do not use the current Node v24.15.0.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test-files/test_gap_intl_builtin_fn_no_prototype_5904.ts`:
- Around line 1-6: Run the gap suite for
test-files/test_gap_intl_builtin_fn_no_prototype_5904.ts using Node 26.5.0,
matching the version pinned in .node-version; do not use the current Node
v24.15.0.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5241fa30-5829-4da0-8e65-2cfcccc7139c
📒 Files selected for processing (3)
crates/perry-runtime/src/intl.rscrates/perry-runtime/src/intl/install.rstest-files/test_gap_intl_builtin_fn_no_prototype_5904.ts
|
Thanks @coderabbitai. On the Node-version nitpick: the gap test only exercises ECMA-262 §17 built-in-function invariants ( |
|
Tip For best results, initiate chat on the files or code changes.
🐇 ✓ ✏️ Learnings added
|
Summary
Part of the
intl402/NumberFormatworklist (#5904). Fixes the largest coherent single-root subcluster: built-in Intl functions must not have an ownprototypeproperty and must not be constructable.The
Intl.NumberFormatmethod/getter/bound functions — theformataccessor, the bound[[BoundFormat]]function,resolvedOptions,formatToParts,formatRange,formatRangeToParts, and the staticsupportedLocalesOf— were created viajs_closure_allocwithout being flagged non-constructable. That letfunction_would_have_own_prototypelazily synthesize a.prototypeobject for them and left them dynamicallynew-able, unlike ordinary built-ins (Math.max,Array.prototype.map) which correctly reporthasOwnProperty("prototype") === falseandisConstructor === false.Per ECMA-262 §17, a built-in function only gets the auto-created
.prototypewhen it implements[[Construct]]. The fix marks the closures created by the three shared Intl installation helpers as non-constructable — the same flag the native-module builtin methods already carry:install_function— prototype methods (formatToParts/resolvedOptions/…), the staticsupportedLocalesOf, and the this-based instance methods (formatRange/formatRangeToParts).install_bound_instance_function— the bound instance methods (format/formatToParts/resolvedOptions).install_constructor— theget …prototype.formataccessor.The constructor closures themselves are untouched, so
new Intl.NumberFormat()andReflect.construct(Intl.X, args, Custom)still work.Tests fixed (test262,
intl402/NumberFormat)Verification
Same-methodology A/B on the pinned test262 slice (
PERRY_NO_AUTO_OPTIMIZE=1, one perry binary, base commit differing only by this edit):intl402/NumberFormat: 217 → 223 pass, 31 → 25 runtime-fail. The 6 fixed cases are exactly thebuiltin.jscluster above.Full
intl402slice: 3100 → 3120 pass, 228 → 208 runtime-fail, 0 → 0 diff, 2 → 2 compile-fail — 20 cases fixed, zero regressions. Because the fix lives in the shared installation helpers, the same class of assertion now passes across every Intl service:Added a per-PR-visible gap test (
test-files/test_gap_intl_builtin_fn_no_prototype_5904.ts) that asserts the full ECMA-262 §17 surface ([object Function]tag, extensibility,[[Prototype]] === Function.prototype, no ownprototype, not a constructor) for the NumberFormat functions plusDateTimeFormat.prototype.resolvedOptionsandCollator.supportedLocalesOf; byte-identical tonode --experimental-strip-types.Code-only PR (no version bump / CHANGELOG / CLAUDE.md edit) per the worklist instructions.
Summary by CodeRabbit
Bug Fixes
prototypeproperty when they are not constructable.Tests