Skip to content

Commit ad13472

Browse files
emulation.setLocaleOverride (#924)
Addressing #774. Emulate locales in [`Intl`](https://tc39.es/ecma402/#intl-object). Other i18n emulation is out of scope of this PR. Emulate locale for browsing contexts or for user contexts. The ecmascript specification of [Intl](https://tc39.es/ecma402/#intl-object) is tight to [DefaultLocale()](https://tc39.es/ecma402/#sec-defaultlocale), which is an [implementation-defined](https://tc39.es/ecma262/#implementation-defined) abstract operation. This PR defines additional steps in case of the locale override is set.
1 parent f8595a0 commit ad13472

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

index.bs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ spec: CONSOLE; urlPrefix: https://console.spec.whatwg.org
127127
text: formatter; url: formatter
128128
text: formatting specifier; url: formatting-specifiers
129129
text: printer; url: printer
130+
spec: ECMASCRIPT-I18N; urlPrefix: https://tc39.es/ecma402/
131+
type: dfn
132+
text: DefaultLocale; url: #sec-defaultlocale
133+
text: IsStructurallyValidLanguageTag; url: #sec-isstructurallyvalidlanguagetag
130134
spec: ECMASCRIPT; urlPrefix: https://tc39.es/ecma262/
131135
type: dfn
132136
text: Array; url: sec-array-objects
@@ -3116,6 +3120,9 @@ or null and an [=struct/item=] named <dfn attribute for="viewport-configuration"
31163120

31173121
A [=remote end=] has a <dfn>viewport overrides map</dfn> which is a weak map between [=user contexts=] and [=viewport configuration=].
31183122

3123+
A [=remote end=] has a <dfn>locale overrides map</dfn> which is a weak map between
3124+
[=navigables=] or [=user contexts=] and string or null.
3125+
31193126
### Types ### {#module-browsingcontext-types}
31203127

31213128
#### The browsingContext.BrowsingContext Type #### {#type-browsingContext-Browsingcontext}
@@ -5768,6 +5775,7 @@ relating to emulation of browser APIs.
57685775
<pre class="cddl" data-cddl-module="remote-cddl">
57695776
EmulationCommand = (
57705777
emulation.SetGeolocationOverride //
5778+
emulation.SetLocaleOverride //
57715779
emulation.SetScreenOrientationOverride
57725780
)
57735781
</pre>
@@ -5898,6 +5906,125 @@ The [=remote end steps=] with |command parameters| are:
58985906

58995907
</div>
59005908

5909+
#### The emulation.setLocaleOverride Command #### {#command-emulation-setLocaleOverride}
5910+
5911+
The <dfn export for=commands>emulation.setLocaleOverride</dfn> command modifies
5912+
locale on the given top-level traversables or user contexts.
5913+
5914+
<dl>
5915+
<dt>Command Type</dt>
5916+
<dd>
5917+
<pre class="cddl" data-cddl-module="remote-cddl">
5918+
emulation.SetLocaleOverride = (
5919+
method: "emulation.setLocaleOverride",
5920+
params: emulation.SetLocaleOverrideParameters
5921+
)
5922+
5923+
emulation.SetLocaleOverrideParameters = {
5924+
locale: text / null,
5925+
? contexts: [+browsingContext.BrowsingContext],
5926+
? userContexts: [+browser.UserContext],
5927+
}
5928+
</pre>
5929+
</dd>
5930+
<dt>Result Type</dt>
5931+
<dd>
5932+
<code>
5933+
EmptyResult
5934+
</code>
5935+
</dd>
5936+
</dl>
5937+
5938+
<div algorithm="updated DefaultLocale steps">
5939+
The [=DefaultLocale=] algorithm is implementation defined. A WebDriver-BiDi
5940+
[=remote end=] must have an implementation that runs the following steps:
5941+
5942+
1. Let |emulated locale| be null.
5943+
5944+
1. Let |realm| be [=current Realm Record=].
5945+
5946+
1. Let |global object| be |realm|'s [=realm/global object=].
5947+
5948+
1. If |global object| implements {{WindowProxy}}:
5949+
5950+
1. Let |window| be the value of |global object|'s \[[WindowProxy]]
5951+
[=internal slot=].
5952+
5953+
1. Let |navigable| be |window|'s [=window/navigable=].
5954+
5955+
1. Let |top-level traversable| be |navigable|’s
5956+
[=navigable/top-level traversable=].
5957+
5958+
1. Let |user context| be |top-level traversable|'s [=associated user context=].
5959+
5960+
1. If [=locale overrides map=] [=map/contains=] |top-level traversable|, set
5961+
|emulated locale| to [=locale overrides map=][|top-level traversable|].
5962+
5963+
1. Otherwise, if [=locale overrides map=] [=map/contains=]
5964+
|user context|, set |emulated locale| to
5965+
[=locale overrides map=][|user context|].
5966+
5967+
1. If |emulated locale| is not null, return |emulated locale|.
5968+
5969+
1. Return the result of implementation-defined steps in accordance with the
5970+
requirements of the [=DefaultLocale=] specification.
5971+
5972+
</div>
5973+
5974+
<div algorithm="remote end steps for emulation.setLocaleOverride">
5975+
5976+
The [=remote end steps=] with |command parameters| are:
5977+
5978+
1. If |command parameters| [=map/contains=] "<code>userContexts</code>"
5979+
and |command parameters| [=map/contains=] "<code>context</code>",
5980+
return [=error=] with [=error code=] [=invalid argument=].
5981+
5982+
1. If |command parameters| doesn't [=map/contain=] "<code>userContexts</code>"
5983+
and |command parameters| doesn't [=map/contain=] "<code>context</code>",
5984+
return [=error=] with [=error code=] [=invalid argument=].
5985+
5986+
1. Let |emulated locale| be null.
5987+
5988+
1. If |command parameters| [=map/contains=] "<code>locale</code>":
5989+
5990+
1. Set |emulated locale| to |command parameters|["<code>locale</code>"].
5991+
5992+
1. If [=IsStructurallyValidLanguageTag=](|emulated locale|) returns false,
5993+
return [=error=] with [=error code=] [=invalid argument=].
5994+
5995+
1. Let |navigables| be a [=/set=].
5996+
5997+
1. If the <code>contexts</code> field of |command parameters| is present:
5998+
5999+
1. Let |navigables| be the result of [=trying=] to
6000+
[=get valid top-level traversables by ids=] with
6001+
|command parameters|["<code>contexts</code>"].
6002+
6003+
1. Otherwise:
6004+
6005+
1. Assert the <code>userContexts</code> field of |command parameters| is present.
6006+
6007+
1. Let |user contexts| be the result of [=trying=] to [=get valid user contexts=]
6008+
with |command parameters|["<code>userContexts</code>"].
6009+
6010+
1. For each |user context| of |user contexts|:
6011+
6012+
1. [=map/Set=] [=locale overrides map=][|user context|] to |emulated locale|.
6013+
6014+
1. [=list/For each=] |top-level traversable| of the list of all
6015+
[=/top-level traversables=] whose [=associated user context=] is
6016+
|user context|:
6017+
6018+
1. [=list/Append=] |top-level traversable| to |navigables|.
6019+
6020+
1. For each |navigable| of |navigables|:
6021+
6022+
1. [=map/Set=] [=locale overrides map=][|navigable|] to |emulated locale|.
6023+
6024+
1. Return [=success=] with data null.
6025+
6026+
</div>
6027+
59016028
#### The emulation.setScreenOrientationOverride Command #### {#command-emulation-setScreenOrientationOverride}
59026029

59036030
The <dfn export for=commands>emulation.setScreenOrientationOverride</dfn> command

0 commit comments

Comments
 (0)