A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/seleniumhq/selenium/commit/51095a4612bb32274aa81f6cd35e25c21c8395ca below:

chore/code style changes, add util (#10975) · SeleniumHQ/selenium@51095a4 · GitHub

File tree Expand file treeCollapse file tree 9 files changed

+78

-42

lines changed

Filter options

Expand file treeCollapse file tree 9 files changed

+78

-42

lines changed Original file line number Diff line number Diff line change

@@ -41,9 +41,8 @@

41 41

* {name: string}|

42 42

* {partialLinkText: string}|

43 43

* {tagName: string}|

44 -

* {xpath: string})}

44 +

* {xpath: string})} ByHash

45 45

*/

46 -

var ByHash // eslint-disable-line

47 46 48 47

/**

49 48

* Error thrown if an invalid character is encountered while escaping a CSS

Original file line number Diff line number Diff line change

@@ -204,7 +204,7 @@ class Executor {

204 204

// PUBLIC API

205 205 206 206

module.exports = {

207 -

Command: Command,

208 -

Name: Name,

209 -

Executor: Executor,

207 +

Command,

208 +

Name,

209 +

Executor,

210 210

}

Original file line number Diff line number Diff line change

@@ -17,6 +17,8 @@

17 17 18 18

'use strict'

19 19 20 +

const { isObject } = require('./util')

21 + 20 22

/**

21 23

* The base WebDriver error type. This error type is only used directly when a

22 24

* more appropriate category is not defined for the offending error.

@@ -505,7 +507,7 @@ function encodeError(err) {

505 507

* @see https://w3c.github.io/webdriver/webdriver-spec.html#protocol

506 508

*/

507 509

function isErrorResponse(data) {

508 -

return data && typeof data === 'object' && typeof data.error === 'string'

510 +

return isObject(data) && typeof data.error === 'string'

509 511

}

510 512 511 513

/**

@@ -540,15 +542,13 @@ function throwDecodedError(data) {

540 542

function checkLegacyResponse(responseObj) {

541 543

// Handle the legacy Selenium error response format.

542 544

if (

543 -

responseObj &&

544 -

typeof responseObj === 'object' &&

545 -

typeof responseObj['status'] === 'number' &&

546 -

responseObj['status'] !== 0

545 +

isObject(responseObj) &&

546 +

typeof responseObj.status === 'number' &&

547 +

responseObj.status !== 0

547 548

) {

548 -

let status = responseObj['status']

549 -

let ctor = LEGACY_ERROR_CODE_TO_TYPE.get(status) || WebDriverError

549 +

const { status, value } = responseObj

550 550 551 -

let value = responseObj['value']

551 +

let ctor = LEGACY_ERROR_CODE_TO_TYPE.get(status) || WebDriverError

552 552 553 553

if (!value || typeof value !== 'object') {

554 554

throw new ctor(value + '')

Original file line number Diff line number Diff line change

@@ -32,6 +32,7 @@ const logging = require('./logging')

32 32

const promise = require('./promise')

33 33

const { Session } = require('./session')

34 34

const webElement = require('./webelement')

35 +

const { isObject } = require('./util')

35 36 36 37

const getAttribute = requireAtom(

37 38

'get-attribute.js',

@@ -572,10 +573,7 @@ function parseHttpResponse(command, httpResponse) {

572 573 573 574

if (parsed && typeof parsed === 'object') {

574 575

let value = parsed.value

575 -

let isW3C =

576 -

value !== null &&

577 -

typeof value === 'object' &&

578 -

typeof parsed.status === 'undefined'

576 +

let isW3C = isObject(value) && typeof parsed.status === 'undefined'

579 577 580 578

if (!isW3C) {

581 579

error.checkLegacyResponse(parsed)

@@ -645,10 +643,10 @@ function buildPath(path, parameters) {

645 643

// PUBLIC API

646 644 647 645

module.exports = {

648 -

Executor: Executor,

649 -

Client: Client,

650 -

Request: Request,

651 -

Response: Response,

646 +

Executor,

647 +

Client,

648 +

Request,

649 +

Response,

652 650

// Exported for testing.

653 -

buildPath: buildPath,

651 +

buildPath,

654 652

}

Original file line number Diff line number Diff line change

@@ -22,16 +22,7 @@

22 22 23 23

'use strict'

24 24 25 -

/**

26 -

* Determines whether a {@code value} should be treated as a promise.

27 -

* Any object whose "then" property is a function will be considered a promise.

28 -

*

29 -

* @param {?} value The value to test.

30 -

* @return {boolean} Whether the value is a promise.

31 -

*/

32 -

function isPromise(value) {

33 -

return Object.prototype.toString.call(value) === '[object Promise]'

34 -

}

25 +

const { isObject, isPromise } = require('./util')

35 26 36 27

/**

37 28

* Creates a promise that will be resolved at a set time in the future.

@@ -218,7 +209,7 @@ async function fullyResolved(value) {

218 209

return fullyResolveKeys(/** @type {!Array} */ (value))

219 210

}

220 211 221 -

if (value && typeof value === 'object') {

212 +

if (isObject(value)) {

222 213

return fullyResolveKeys(/** @type {!Object} */ (value))

223 214

}

224 215 Original file line number Diff line number Diff line change

@@ -0,0 +1,43 @@

1 +

// Licensed to the Software Freedom Conservancy (SFC) under one

2 +

// or more contributor license agreements. See the NOTICE file

3 +

// distributed with this work for additional information

4 +

// regarding copyright ownership. The SFC licenses this file

5 +

// to you under the Apache License, Version 2.0 (the

6 +

// "License"); you may not use this file except in compliance

7 +

// with the License. You may obtain a copy of the License at

8 +

//

9 +

// http://www.apache.org/licenses/LICENSE-2.0

10 +

//

11 +

// Unless required by applicable law or agreed to in writing,

12 +

// software distributed under the License is distributed on an

13 +

// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

14 +

// KIND, either express or implied. See the License for the

15 +

// specific language governing permissions and limitations

16 +

// under the License.

17 + 18 +

'use strict'

19 + 20 +

/**

21 +

* Determines whether a {@code value} should be treated as an object.

22 +

* @param {?} value The value to test.

23 +

* @returns {boolean} Whether the value is an object.

24 +

*/

25 +

function isObject(value) {

26 +

return Object.prototype.toString.call(value) === '[object Object]'

27 +

}

28 + 29 +

/**

30 +

* Determines whether a {@code value} should be treated as a promise.

31 +

* Any object whose "then" property is a function will be considered a promise.

32 +

*

33 +

* @param {?} value The value to test.

34 +

* @return {boolean} Whether the value is a promise.

35 +

*/

36 +

function isPromise(value) {

37 +

return Object.prototype.toString.call(value) === '[object Promise]'

38 +

}

39 + 40 +

module.exports = {

41 +

isObject,

42 +

isPromise,

43 +

}

Original file line number Diff line number Diff line change

@@ -234,7 +234,11 @@ class Credential {

234 234

}

235 235

}

236 236 237 -

module.exports.Credential = Credential

238 -

module.exports.VirtualAuthenticatorOptions = VirtualAuthenticatorOptions

239 -

module.exports.Transport = Transport

240 -

module.exports.Protocol = Protocol

237 +

// PUBLIC API

238 + 239 +

module.exports = {

240 +

Credential,

241 +

VirtualAuthenticatorOptions,

242 +

Transport,

243 +

Protocol,

244 +

}

Original file line number Diff line number Diff line change

@@ -37,8 +37,9 @@ const { Capabilities } = require('./capabilities')

37 37

const path = require('path')

38 38

const { NoSuchElementError } = require('./error')

39 39

const cdpTargets = ['page', 'browser']

40 -

const Credential = require('./virtual_authenticator').Credential

40 +

const { Credential } = require('./virtual_authenticator')

41 41

const webElement = require('./webelement')

42 +

const { isObject } = require('./util')

42 43 43 44

// Capability names that are defined in the W3C spec.

44 45

const W3C_CAPABILITY_NAMES = new Set([

@@ -214,7 +215,7 @@ function fromWireValue(driver, value) {

214 215

} else if (ShadowRoot.isId(value)) {

215 216

let id = ShadowRoot.extractId(value)

216 217

value = new ShadowRoot(driver, id)

217 -

} else if (value && typeof value === 'object') {

218 +

} else if (isObject(value)) {

218 219

let result = {}

219 220

for (let key in value) {

220 221

if (Object.prototype.hasOwnProperty.call(value, key)) {

Original file line number Diff line number Diff line change

@@ -16,6 +16,7 @@

16 16

// under the License.

17 17 18 18

'use strict'

19 +

const { isObject } = require('./util')

19 20 20 21

/**

21 22

* @fileoverview Defines some common methods used for WebElements.

@@ -33,8 +34,7 @@ const ELEMENT_ID_KEY = 'element-6066-11e4-a52e-4f735466cecf'

33 34

*/

34 35

function isId(obj) {

35 36

return (

36 -

obj &&

37 -

typeof obj === 'object' &&

37 +

isObject(obj) &&

38 38

(typeof obj[ELEMENT_ID_KEY] === 'string' ||

39 39

typeof obj[LEGACY_ELEMENT_ID_KEY] === 'string')

40 40

)

@@ -48,7 +48,7 @@ function isId(obj) {

48 48

* @throws {TypeError} if the object is not a valid encoded ID.

49 49

*/

50 50

function extractId(obj) {

51 -

if (obj && typeof obj === 'object') {

51 +

if (isObject(obj)) {

52 52

if (typeof obj[ELEMENT_ID_KEY] === 'string') {

53 53

return obj[ELEMENT_ID_KEY]

54 54

} else if (typeof obj[LEGACY_ELEMENT_ID_KEY] === 'string') {

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4