Skip to content

Commit 24d78ad

Browse files
committed
Bug 2003992 - [webdriver-bidi] Throw an error when calling "emulation.setLocaleOverride" with "locale" argument equal "undefined". r=whimboo
Differential Revision: https://phabricator.services.mozilla.com/D275041
1 parent 0dcb946 commit 24d78ad

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

remote/webdriver-bidi/modules/root/emulation.sys.mjs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -362,28 +362,26 @@ class EmulationModule extends RootBiDiModule {
362362
} = options;
363363

364364
let locale;
365-
if (localeArg !== undefined) {
366-
if (localeArg === null) {
367-
// The API requires an empty string to reset the override.
368-
locale = "";
369-
} else {
370-
locale = lazy.assert.string(
371-
localeArg,
372-
lazy.pprint`Expected "locale" to be a string, got ${localeArg}`
373-
);
374-
375-
// Validate if locale is a structurally valid language tag.
376-
try {
377-
Intl.getCanonicalLocales(localeArg);
378-
} catch (err) {
379-
if (err instanceof RangeError) {
380-
throw new lazy.error.InvalidArgumentError(
381-
`Expected "locale" to be a structurally valid language tag (e.g., "en-GB"), got ${localeArg}`
382-
);
383-
}
365+
if (localeArg === null) {
366+
// The API requires an empty string to reset the override.
367+
locale = "";
368+
} else {
369+
locale = lazy.assert.string(
370+
localeArg,
371+
lazy.pprint`Expected "locale" to be a string, got ${localeArg}`
372+
);
384373

385-
throw err;
374+
// Validate if locale is a structurally valid language tag.
375+
try {
376+
Intl.getCanonicalLocales(localeArg);
377+
} catch (err) {
378+
if (err instanceof RangeError) {
379+
throw new lazy.error.InvalidArgumentError(
380+
`Expected "locale" to be a structurally valid language tag (e.g., "en-GB"), got ${localeArg}`
381+
);
386382
}
383+
384+
throw err;
387385
}
388386
}
389387

0 commit comments

Comments
 (0)