Skip to content

Commit 83c97eb

Browse files
authored
update map/filter clean up to common format (#10094)
1 parent 7530f33 commit 83c97eb

9 files changed

Lines changed: 142 additions & 133 deletions

File tree

javascript/node/selenium-webdriver/example/google_search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
const { Builder, By, Key, until } = require('..')
4141

42-
var driver = new Builder().forBrowser('firefox').build()
42+
const driver = new Builder().forBrowser('firefox').build()
4343

4444
driver
4545
.get('http://www.google.com/ncr')

javascript/node/selenium-webdriver/io/exec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class Result {
7676
}
7777
}
7878

79-
const COMMAND_RESULT = /** !WeakMap<!Command, !Promise<!Result>> */ new WeakMap()
79+
const COMMAND_RESULT =
80+
/** !WeakMap<!Command, !Promise<!Result>> */ new WeakMap()
8081
const KILL_HOOK = /** !WeakMap<!Command, function(string)> */ new WeakMap()
8182

8283
/**

javascript/node/selenium-webdriver/lib/http.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const error = require('./error')
3131
const logging = require('./logging')
3232
const promise = require('./promise')
3333
const { Session } = require('./session')
34-
const { WebElement, ShadowRoot } = require('./webdriver')
34+
const { WebElement } = require('./webdriver')
3535

3636
const getAttribute = requireAtom(
3737
'get-attribute.js',
@@ -63,8 +63,8 @@ function requireAtom(module, bazelTarget) {
6363
console.log(ex2)
6464
throw Error(
6565
`Failed to import atoms module ${module}. If running in dev mode, you` +
66-
` need to run \`bazel build ${bazelTarget}\` from the project` +
67-
`root: ${ex}`
66+
` need to run \`bazel build ${bazelTarget}\` from the project` +
67+
`root: ${ex}`
6868
)
6969
}
7070
}
@@ -173,7 +173,7 @@ var CommandSpec // eslint-disable-line
173173
/** @typedef {function(!cmd.Command): !cmd.Command} */
174174
var CommandTransformer // eslint-disable-line
175175

176-
class InternalTypeError extends TypeError { }
176+
class InternalTypeError extends TypeError {}
177177

178178
/**
179179
* @param {!cmd.Command} command The initial command.
@@ -423,8 +423,14 @@ const W3C_COMMAND_MAP = new Map([
423423
[cmd.Name.PRINT_PAGE, post('/session/:sessionId/print')],
424424
// Shadow Root
425425
[cmd.Name.GET_SHADOW_ROOT, get('/session/:sessionId/element/:id/shadow')],
426-
[cmd.Name.FIND_ELEMENT_FROM_SHADOWROOT, post('/session/:sessionId/shadow/:id/element')],
427-
[cmd.Name.FIND_ELEMENTS_FROM_SHADOWROOT, post('/session/:sessionId/shadow/:id/elements')],
426+
[
427+
cmd.Name.FIND_ELEMENT_FROM_SHADOWROOT,
428+
post('/session/:sessionId/shadow/:id/element'),
429+
],
430+
[
431+
cmd.Name.FIND_ELEMENTS_FROM_SHADOWROOT,
432+
post('/session/:sessionId/shadow/:id/elements'),
433+
],
428434
// Log extensions.
429435
[cmd.Name.GET_LOG, post('/session/:sessionId/se/log')],
430436
[cmd.Name.GET_AVAILABLE_LOG_TYPES, get('/session/:sessionId/se/log/types')],
@@ -445,7 +451,7 @@ class Client {
445451
* @return {!Promise<Response>} A promise that will be fulfilled with the
446452
* server's response.
447453
*/
448-
send(httpRequest) { } // eslint-disable-line
454+
send(httpRequest) { } // eslint-disable-line
449455
}
450456

451457
/**
@@ -588,7 +594,7 @@ class Executor {
588594
// No implementations use the `capabilities` key yet...
589595
let capabilities = value.capabilities || value.value
590596
return new Session(
591-
/** @type {{sessionId: string}} */(value).sessionId,
597+
/** @type {{sessionId: string}} */ (value).sessionId,
592598
capabilities
593599
)
594600
}

javascript/node/selenium-webdriver/lib/promise.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,12 @@ async function map(array, fn, self = undefined) {
142142
}
143143

144144
const arr = /** @type {!Array} */ (v)
145-
const n = arr.length
146-
const values = new Array(n)
145+
const values = []
147146

148-
for (let i = 0; i < n; i++) {
149-
if (i in arr) {
150-
values[i] = await Promise.resolve(fn.call(self, arr[i], i, arr))
151-
}
147+
for (const [index, item] of arr.entries()) {
148+
values.push(await Promise.resolve(fn.call(self, item, index, arr)))
152149
}
150+
153151
return values
154152
}
155153

@@ -181,19 +179,17 @@ async function filter(array, fn, self = undefined) {
181179
}
182180

183181
const arr = /** @type {!Array} */ (v)
184-
const n = arr.length
185182
const values = []
186-
let valuesLength = 0
187183

188-
for (let i = 0; i < n; i++) {
189-
if (i in arr) {
190-
const value = arr[i]
191-
const include = await fn.call(self, value, i, arr)
192-
if (include) {
193-
values[valuesLength++] = value
194-
}
184+
for (const [index, item] of arr.entries()) {
185+
const isConditionTrue = await Promise.resolve(
186+
fn.call(self, item, index, arr)
187+
)
188+
if (isConditionTrue) {
189+
values.push(item)
195190
}
196191
}
192+
197193
return values
198194
}
199195

javascript/node/selenium-webdriver/lib/proxy.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ManualConfig.prototype.socksVersion
130130
* Configures WebDriver to bypass all browser proxies.
131131
* @return {!Config} A new proxy configuration object.
132132
*/
133-
exports.direct = function () {
133+
function direct() {
134134
return { proxyType: Type.DIRECT }
135135
}
136136

@@ -155,7 +155,7 @@ exports.direct = function () {
155155
* configuration options.
156156
* @return {!ManualConfig} A new proxy configuration object.
157157
*/
158-
exports.manual = function ({ ftp, http, https, bypass }) {
158+
function manual({ ftp, http, https, bypass }) {
159159
return {
160160
proxyType: Type.MANUAL,
161161
ftpProxy: ftp,
@@ -185,7 +185,7 @@ exports.manual = function ({ ftp, http, https, bypass }) {
185185
* @return {!ManualConfig} A new proxy configuration object.
186186
* @see https://en.wikipedia.org/wiki/SOCKS
187187
*/
188-
exports.socks = function (socksProxy, socksVersion = undefined) {
188+
function socks(socksProxy, socksVersion = undefined) {
189189
return /** @type {!Config} */ ({
190190
proxyType: Type.MANUAL,
191191
socksProxy,
@@ -199,14 +199,24 @@ exports.socks = function (socksProxy, socksVersion = undefined) {
199199
* @param {string} proxyAutoconfigUrl URL for the PAC proxy to use.
200200
* @return {!PacConfig} A new proxy configuration object.
201201
*/
202-
exports.pac = function (proxyAutoconfigUrl) {
202+
function pac(proxyAutoconfigUrl) {
203203
return { proxyType: Type.PAC, proxyAutoconfigUrl }
204204
}
205205

206206
/**
207207
* Configures WebDriver to use the current system's proxy.
208208
* @return {!Config} A new proxy configuration object.
209209
*/
210-
exports.system = function () {
210+
function system() {
211211
return { proxyType: Type.SYSTEM }
212212
}
213+
214+
// PUBLIC API
215+
216+
module.exports = {
217+
system,
218+
pac,
219+
socks,
220+
manual,
221+
direct,
222+
}

javascript/node/selenium-webdriver/lib/session.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ class Session {
7474

7575
// PUBLIC API
7676

77-
module.exports = { Session: Session }
77+
module.exports = { Session }

javascript/node/selenium-webdriver/lib/until.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,13 @@ exports.alertIsPresent = function alertIsPresent() {
137137
* @return {!Condition<boolean>} The new condition.
138138
*/
139139
exports.titleIs = function titleIs(title) {
140-
return new Condition(
141-
'for title to be ' + JSON.stringify(title),
142-
function (driver) {
143-
return driver.getTitle().then(function (t) {
144-
return t === title
145-
})
146-
}
147-
)
140+
return new Condition('for title to be ' + JSON.stringify(title), function (
141+
driver
142+
) {
143+
return driver.getTitle().then(function (t) {
144+
return t === title
145+
})
146+
})
148147
}
149148

150149
/**
@@ -189,14 +188,13 @@ exports.titleMatches = function titleMatches(regex) {
189188
* @return {!Condition<boolean>} The new condition.
190189
*/
191190
exports.urlIs = function urlIs(url) {
192-
return new Condition(
193-
'for URL to be ' + JSON.stringify(url),
194-
function (driver) {
195-
return driver.getCurrentUrl().then(function (u) {
196-
return u === url
197-
})
198-
}
199-
)
191+
return new Condition('for URL to be ' + JSON.stringify(url), function (
192+
driver
193+
) {
194+
return driver.getCurrentUrl().then(function (u) {
195+
return u === url
196+
})
197+
})
200198
}
201199

202200
/**

0 commit comments

Comments
 (0)