ecma402
ecma402 copied to clipboard
ECMA-402 contents should be arranged more consistently
Suggested template for Foo functionality:
- Foo Objects
- The Intl.Foo Constructor
- Intl.Foo ( [ locales [ , options ] ] )
- Properties of the Intl.Foo Constructor
- Intl.Foo.prototype
- Intl.Foo.supportedLocalesOf ( locales [, options ] )
- Internal slots
- Properties of the Intl.Foo Prototype Object
- Intl.Foo.prototype.constructor
- Intl.Foo.prototype.resolvedOptions ()
- Intl.Foo.prototype [ @@toStringTag ] (or maybe this could be absent from new extensions?)
- ...Foo-specific properties in alphabetic order...
- Properties of Intl.Foo Instances
- ...other Foo-specific surface area...
- Abstract Operations for Foo Objects
- The Intl.Foo Constructor
The biggest differences of this as compared to http://tc39.es/ecma402/ are in the ordering under "Properties of the Intl.Foo Prototype Object" (which currently all go like "constructor", "@@toStringTag", ..., "resolvedOptions") and in pushing abstract operations to be after the references to them (rather than before the Constructor definition as they are now).
It also looks like a great deal of the constructor code could be abstracted:
- (since PluralRules, cf. #384) If NewTarget is undefined, throw a TypeError exception.
- If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
- Let obj be ? OrdinaryCreateFromConstructor(newTarget, proto, internalSlotsList).
- Let requestedLocales be ? CanonicalizeLocaleList(locales).
- If options is undefined, then
- Let options be ObjectCreate(null).
- Else
- Let options be ? ToObject(options).
- Let opt be a new Record.
- Let matcher be ? GetOption(options,
"localeMatcher","string", «"lookup","best fit"»,"best fit"). - Set opt.[[localeMatcher]] to matcher.
- Let localeData be constructor.[[LocaleData]].
- Let r be ResolveLocale(constructor.[[AvailableLocales]], requestedLocales, opt, constructor.[[RelevantExtensionKeys]], localeData).
- Set obj.[[Locale]] to the value of r.[[locale]].
- Return obj.
This seems straightforward and it can help prevent errors when merging proposals, implementing the spec, etc. It should be done in a quiet time when there are not other big PRs open.
#923 rearranges the specifications for each Intl object to match the template given by @gibson042.
Is there still interest in abstracting away the duplicative constructor code? I'm a big fan of the idea, but given that different Intl Objects have different options reads interspersed through those sections, the most straightforward way to abstract it out would require normative changes to the order of those options reads.
Is there still interest in abstracting away the duplicative constructor code?
Yes, I'd still love to see that.
I'm a big fan of the idea, but given that different Intl Objects have different options reads interspersed through those sections, the most straightforward way to abstract it out would require normative changes to the order of those options reads.
I think we can get pretty far editorially... AFAICT, there's variation only on
- how to deal with undefined NewTarget (i.e., invocation as a function rather than as a constructor with
new), and - how to consume options, and
- (for Collator and DateTimeFormat and NumberFormat and RelativeTimeFormat) early reads of options properties that can potentially affect ResolveLocale [by overridding keywords in the requested locale identifiers, and in the case of Collator by selection of locale data]
...all of which can be parameterized in a common constructor operation.
We can also get even further if normative changes are on the table to e.g. snapshot options objects early in construction, which would be great but should wait for completion of the editorial part so we can better assess the impact of such changes.