archives

« Bugzilla Issues Index

#4008 — ToDateTimeOptions must not apply defaults if at least one required option is present


ToDateTimeOptions must not apply defaults if at least one required option is present.

For example:
ToDateTimeOptions({weekday: "long"}, "date", "date") currently returns `{weekday: "long", year: "numeric", month: "numeric", day: "numeric"}`, but expected is `{weekday: "long"}`.


I see where the mistake that was made and the fix is simple, but I have question: why is "weekday" not present in 7.a?

http://www.ecma-international.org/ecma-402/1.0/index.html#ToDateTimeOptions


Because we don't want to include the weekday in the default date format string. `new Intl.DateTimeFormat("en-US").format(new Date)` and `new Date().toLocaleDateString("en-US")` should both return "2/19/2015" instead of "Thu, 2/19/2015".


Ah, that makes sense. I think a non-normative note is in order.


(In reply to André Bargull from comment #2)
> Because we don't want to include the weekday in the default date format
> string. `new Intl.DateTimeFormat("en-US").format(new Date)` and `new
> Date().toLocaleDateString("en-US")` should both return "2/19/2015" instead
> of "Thu, 2/19/2015".


Please confirm:


1. If options is undefined, then let options be null, else let options be ToObject(options).
2. ReturnIfAbrupt(options).
3. Let opts be ObjectCreate(options).
4. Let needDefaults be true.
5. If required is "date" or "any", then
a. For each of the property names "weekday", "year", "month", "day":
i. Let prop be the property name.
ii. If the result of Get(options, prop) is undefined, then let needDefaults be false.
6. If required is "time" or "any", then
a. For each of the property names "hour", "minute", "second":
i. Let prop be the property name.
ii. If the result of Get(options, prop) is not undefined, then let needDefaults be false.
7. If needDefaults is true and defaults is either "date" or "all", then
a. For each of the property names "year", "month", "day":
i. Let prop be the property name.
ii. Let desc be PropertyDescriptor { [[Value]]: "numeric", [[Configurable]]: true, [[Enumerable]]: true, [[Writable]]: true }.
iii. Let status be DefinePropertyOrThrow(options, prop, desc).
8. If needDefaults is true and defaults is either "time" or "all", then
a. For each of the property names "hour", "minute", "second":
i. Let prop be the property name.
ii. Let desc be PropertyDescriptor { [[Value]]: "numeric", [[Configurable]]: true, [[Enumerable]]: true, [[Writable]]: true }.
iii. Let status be DefinePropertyOrThrow(options, prop, desc).
9. Return options.


This is essentially reverting to the 1st edition, but with updates to ES6 language and mechanisms.


(In reply to Rick Waldron from comment #4)
> Please confirm:
>

LGTM except for a typo in step 5.a.ii: "is undefined" -> "is not undefined".


Furthermore these steps:
---
ii. Let desc be PropertyDescriptor { [[Value]]: "numeric", [[Configurable]]: true, [[Enumerable]]: true, [[Writable]]: true }.
iii. Let status be DefinePropertyOrThrow(options, prop, desc).
---

can be reduced to:
---
ii. Let status be CreateDataPropertyOrThrow(options, prop, "numeric").
iii. ReturnIfAbrupt(status).
---


And calling Get() actually needs an ReturnIfAbrupt check:
---
ii. If the result of Get(options, prop) is undefined, then let needDefaults be false.
---

Like:
---
ii. Let value be Get(options, prop).
iii. ReturnIfAbrupt(value).
iv. If value is not undefined, then let needDefaults be false.
---

Do you plan to fix all places in the intl spec where ReturnIfAbrupt calls are necessary? Or do you want to leave this as-is for the time being?


(In reply to André Bargull from comment #5)
> (In reply to Rick Waldron from comment #4)
> > Please confirm:
> >
>
> LGTM except for a typo in step 5.a.ii: "is undefined" -> "is not undefined".

Fixed

>
>
> Furthermore these steps:
> ---
> ii. Let desc be PropertyDescriptor { [[Value]]: "numeric",
> [[Configurable]]: true, [[Enumerable]]: true, [[Writable]]: true }.
> iii. Let status be DefinePropertyOrThrow(options, prop, desc).
> ---
>
> can be reduced to:
> ---
> ii. Let status be CreateDataPropertyOrThrow(options, prop, "numeric").
> iii. ReturnIfAbrupt(status).
> ---

Fixed.


>
>
> And calling Get() actually needs an ReturnIfAbrupt check:
> ---
> ii. If the result of Get(options, prop) is undefined, then let needDefaults
> be false.
> ---
>
> Like:
> ---
> ii. Let value be Get(options, prop).
> iii. ReturnIfAbrupt(value).
> iv. If value is not undefined, then let needDefaults be false.
> ---

Fixed.

>
> Do you plan to fix all places in the intl spec where ReturnIfAbrupt calls
> are necessary? Or do you want to leave this as-is for the time being?

I would like to make sure that these are all fixed. Any that might appear as "missed" were probably considered and determined unnecessary, however I realize now that I overlooked the possibility that user code may pass in objects with accessors that may throw, so another pass is necessary and if you have the time and resources to help me with that, I would greatly appreciate it.


Fixed in ECMA-402, 2nd ed.