archives

« Bugzilla Issues Index

#4011 — 9.2.8 SupportedLocales: Use GetOption in step 1 ?


9.2.8 SupportedLocales (availableLocales, requestedLocales, options)

The initial steps of SupportedLocales can be simplified to:
---
1. If options is not undefined, then
a. Let matcher be GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
b. ReturnIfAbrupt(matcher).
2. Else, let matcher be "best fit".
3. If matcher is "best fit", then
[...]
---


(In reply to André Bargull from comment #0)
> 9.2.8 SupportedLocales (availableLocales, requestedLocales, options)
>
> The initial steps of SupportedLocales can be simplified to:
> ---
> 1. If options is not undefined, then
> a. Let matcher be GetOption(options, "localeMatcher", "string", «
> "lookup", "best fit" », "best fit").
> b. ReturnIfAbrupt(matcher).
> 2. Else, let matcher be "best fit".
> 3. If matcher is "best fit", then
> [...]
> ---



Please confirm:



1. If options is not undefined, then
a. Let matcher be GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
b. ReturnIfAbrupt(matcher).
2. Else, let matcher be "best fit".
3. If matcher is "best fit",
a. Let MatcherOperation be the abstract operation BestFitSupportedLocales.
4. Else
a. Let MatcherOperation be the abstract operation LookupSupportedLocales.
5. Let subset be MatcherOperation(availableLocales, requestedLocales).
6. For each named own property name P of subset,
a. Let desc be the result of the [[GetOwnProperty]] internal method of subset with the argument P.
b. Set desc.[[Writable]] to false.
c. Set desc.[[Configurable]] to false.
d. Let status be DefinePropertyOrThrow(subset, P, desc).
e. ReturnIfAbrupt(status).
7. Return subset.


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

How about:
---
1. If options is not undefined, then
a. Let matcher be GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
b. ReturnIfAbrupt(matcher).
2. Else, let matcher be "best fit".
3. If matcher is "best fit",
a. Let MatcherOperation be the abstract operation BestFitSupportedLocales.
4. Else
a. Let MatcherOperation be the abstract operation LookupSupportedLocales.
5. Let subset be MatcherOperation(availableLocales, requestedLocales).
6. Assert: Type(subset) is Object.
7. Let keys be subset.[[OwnPropertyKeys]] ().
8. ReturnIfAbrupt(keys).
9. Repeat for each element P of keys in List order,
a. Let currentDesc be subset.[[GetOwnProperty]](P).
b. ReturnIfAbrupt(currentDesc).
c. If currentDesc is not undefined, then
i. Let desc be PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
ii. Let status be DefinePropertyOrThrow(subset, P, desc).
iii. ReturnIfAbrupt(status).
10. Return subset.
---


Motivation for the additional changes:
- step 6: BestFitSupportedLocales is implementation defined, but we want to restrict the return value to objects.
- step 8: BestFitSupportedLocales is implementation defined, so calling subset.[[OwnPropertyKeys]]() could result in an abrupt completion.
- step 9.b: Same reason as for step 8.
- step 9.c: To mirror the structure of ES6 SetIntegrityLevel.
- step 9.c.i: This avoids mucking around with the returned descriptor which is normally not done in ES6.


Or alternatively for step 9:
---
9. Repeat for each element P of keys in List order,
a. Let desc be PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
b. Let status be DefinePropertyOrThrow(subset, P, desc).
c. ReturnIfAbrupt(status).
---

If you also want to handle accessor properties in step 9:
---
9. Repeat for each element P of keys in List order,
a. Let currentDesc be subset.[[GetOwnProperty]](P).
b. ReturnIfAbrupt(currentDesc).
c. If currentDesc is not undefined, then
i. If IsAccessorDescriptor(currentDesc) is true, then
1. Let desc be the PropertyDescriptor{ [[Configurable]]: false }.
ii. Else,
1. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
iii. Let status be DefinePropertyOrThrow(subset, P, desc).
iv. ReturnIfAbrupt(status).
---


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

If you don't want to apply the additional changes, your proposed updates also work for me.


Since LookupSupportedLocales and BestFitSupportedLocales, return an Array and List respectively, "subset" needs to become an object. I made some minor changes to your suggestion and rolled in Step 9, Alt 1:


1. If options is not undefined, then
a. Let matcher be GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
b. ReturnIfAbrupt(matcher).
2. Else, let matcher be "best fit".
3. If matcher is "best fit",
a. Let MatcherOperation be the abstract operation BestFitSupportedLocales.
4. Else
a. Let MatcherOperation be the abstract operation LookupSupportedLocales.
5. Let supportedLocales be MatcherOperation(availableLocales, requestedLocales).
6. Let subset be ToObject(supportedLocales).
7. ReturnIfAbrupt(subset).
8. Let keys be subset.[[OwnPropertyKeys]]().
9. ReturnIfAbrupt(keys).
10. Repeat for each element P of keys in List order,
a. Let desc be PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
b. Let status be DefinePropertyOrThrow(subset, P, desc).
c. ReturnIfAbrupt(status).
11. Return subset.


Fixed in ECMA-402, 2nd ed.