summaryrefslogtreecommitdiffstats
path: root/remote/webdriver-bidi/modules/root/session.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'remote/webdriver-bidi/modules/root/session.sys.mjs')
-rw-r--r--remote/webdriver-bidi/modules/root/session.sys.mjs37
1 files changed, 21 insertions, 16 deletions
diff --git a/remote/webdriver-bidi/modules/root/session.sys.mjs b/remote/webdriver-bidi/modules/root/session.sys.mjs
index a34ca514e3..8ecf7d7724 100644
--- a/remote/webdriver-bidi/modules/root/session.sys.mjs
+++ b/remote/webdriver-bidi/modules/root/session.sys.mjs
@@ -76,16 +76,10 @@ class SessionModule extends Module {
const { events, contexts: contextIds = null } = params;
// Check input types until we run schema validation.
- lazy.assert.array(events, "events: array value expected");
- events.forEach(name => {
- lazy.assert.string(name, `${name}: string value expected`);
- });
+ this.#assertNonEmptyArrayWithStrings(events, "events");
if (contextIds !== null) {
- lazy.assert.array(contextIds, "contexts: array value expected");
- contextIds.forEach(contextId => {
- lazy.assert.string(contextId, `${contextId}: string value expected`);
- });
+ this.#assertNonEmptyArrayWithStrings(contextIds, "contexts");
}
const listeners = this.#updateEventMap(events, contextIds, true);
@@ -113,15 +107,9 @@ class SessionModule extends Module {
const { events, contexts: contextIds = null } = params;
// Check input types until we run schema validation.
- lazy.assert.array(events, "events: array value expected");
- events.forEach(name => {
- lazy.assert.string(name, `${name}: string value expected`);
- });
+ this.#assertNonEmptyArrayWithStrings(events, "events");
if (contextIds !== null) {
- lazy.assert.array(contextIds, "contexts: array value expected");
- contextIds.forEach(contextId => {
- lazy.assert.string(contextId, `${contextId}: string value expected`);
- });
+ this.#assertNonEmptyArrayWithStrings(contextIds, "contexts");
}
const listeners = this.#updateEventMap(events, contextIds, false);
@@ -139,6 +127,23 @@ class SessionModule extends Module {
}
}
+ #assertNonEmptyArrayWithStrings(array, variableName) {
+ lazy.assert.array(
+ array,
+ `Expected "${variableName}" to be an array, got ${array}`
+ );
+ lazy.assert.that(
+ array => !!array.length,
+ `Expected "${variableName}" array to have at least one item`
+ )(array);
+ array.forEach(item => {
+ lazy.assert.string(
+ item,
+ `Expected elements of "${variableName}" to be a string, got ${item}`
+ );
+ });
+ }
+
#getBrowserIdForContextId(contextId) {
const context = lazy.TabManager.getBrowsingContextById(contextId);
if (!context) {