feat(intl): implement Intl.Locale (#5344)#5390
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds ChangesIntl.Locale implementation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Comment |
fa812b5 to
fe4e134
Compare
Adds `Intl.Locale` backed by `icu_locale_core`'s data-free BCP-47 / UTS #35 parser (the `intl-locale` feature, auto-enabled when a program references `Intl.Locale`). Previously the constructor was absent — `new Intl.Locale(...)` threw "undefined is not a constructor", which also blocked many other intl402 tests that build a Locale during setup. Implemented: - Constructor: tag (string or `Locale` instance) + options, with ApplyOptionsToTag / ApplyUnicodeExtensionToTag resolution in spec order (language, script, region, variants, then ca/co/hc/kf/kn/nu). Structural validation: invalid subtags / out-of-range enums / empty or <3-char keyword `type` values → RangeError; non-string/non-object tag → TypeError. - Accessor getters on the prototype (real `{ get, enumerable:false, configurable:true }` accessors): baseName, language, script, region, variants, calendar, caseFirst, collation, hourCycle, numberingSystem, numeric. - Methods: toString, maximize, minimize. maximize/minimize are best-effort (likely-subtags need CLDR data — out of scope for the data-free parser). The prototype is populated at globalThis init and stamped on the ctor's `prototype` dynamic prop; `ensure_function_prototype_object` now returns it via a Locale gate mirroring Temporal's, so `new Intl.Locale()` no longer shadows it with a fresh empty prototype. Makes the `intl-locale` feature self-sufficient by enabling `icu_locale_core/alloc` (it was previously only pulled in transitively by `temporal`), so the auto-optimize build of a Temporal-free program that touches `Intl.Locale` links cleanly. test262 intl402/Locale: 0 -> 86/151 (57%). Remaining failures need CLDR data (the Locale-Info `getCalendars`/`getWeekInfo`/... methods, alias and likely-subtags resolution) or are the known `newTarget`-detection and inherited-`Symbol.toStringTag` runtime gaps (the latter affects the existing Intl formatters too). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
fe4e134 to
422839a
Compare
|
Superseded by #5359, which already implemented |
Summary
Implements
Intl.Locale(issue #5344, the largest missing-constructor bucket in the intl402 tail), backed byicu_locale_core's data-free BCP-47 / UTS #35 parser. Previouslynew Intl.Locale(...)threw "undefined is not a constructor", which also blocked many other intl402 tests that construct a Locale during setup.What's implemented
tag(string orLocaleinstance) +options, with ApplyOptionsToTag / ApplyUnicodeExtensionToTag resolution in spec-mandated order (language, script, region, variants, thenca/co/hc/kf/kn/nu). Validation: invalid subtags / out-of-range enums / empty or<3-char keywordtypevalues →RangeError; non-string/non-object tag →TypeError.{ get, enumerable:false, configurable:true }):baseName,language,script,region,variants,calendar,caseFirst,collation,hourCycle,numberingSystem,numeric.toString,maximize,minimize(the latter two are best-effort — likely-subtags need CLDR data, out of scope for the data-free parser).Notable wiring
ensure_function_prototype_objectgains a Locale gate (mirroring the existing Temporal one) sonew Intl.Locale()returns the populated prototype instead of shadowing it with a fresh empty one.intl-localefeature now enablesicu_locale_core/allocexplicitly (it was previously only pulled in transitively bytemporal), so the auto-optimize build of a Temporal-free program that touchesIntl.Localelinks cleanly.intl-localeon anyIntl.Localereference.Results
scripts/test262_subset.py --dir intl402/Locale --all-features(node v26 oracle): 0 → 86/151 (57%).Remaining failures are out of scope or known gaps:
getCalendars/getWeekInfo/getTimeZones/…) and alias / likely-subtags resolution (mo→ro,SU→AM,islamicc→islamic-civil,maximize/minimize). These needicu_locale+ CLDR, not the data-freeicu_locale_core.Symbol.toStringTag— pre-existing Perry limitation (Object.prototype.toStringignores inheritedSymbol.toStringTag; affects the existing Intl formatters too).newTarget-detection / node-version artifacts, ~4firstDayOfWeek(deferred), a few validation edges.🤖 Generated with Claude Code
Summary by CodeRabbit
Intl.LocaleAPI support, includingnew Intl.Locale(...),toString, andmaximize/minimize.RangeErrorfor structurally invalid input.Intl.Localeconstructor prototypes to preserve any pre-populated prototype object.Intl.Localeusage to recognize moreIntl.*.Locale-related access patterns.