Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/lib/util.js
2884 views
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
try {
38
// Use array notation so the Closure compiler does not obfuscate away our
39
// contract.
40
return (typeof value === 'object' || typeof value === 'function') && typeof value['then'] === 'function'
41
/*eslint no-unused-vars: "off"*/
42
} catch (ex) {
43
return false
44
}
45
}
46
47
module.exports = {
48
isObject,
49
isPromise,
50
}
51
52