Path: blob/trunk/javascript/selenium-webdriver/lib/util.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819/**20* Determines whether a {@code value} should be treated as an object.21* @param {?} value The value to test.22* @returns {boolean} Whether the value is an object.23*/24function isObject(value) {25return Object.prototype.toString.call(value) === '[object Object]'26}2728/**29* Determines whether a {@code value} should be treated as a promise.30* Any object whose "then" property is a function will be considered a promise.31*32* @param {?} value The value to test.33* @return {boolean} Whether the value is a promise.34*/35function isPromise(value) {36try {37// Use array notation so the Closure compiler does not obfuscate away our38// contract.39return (typeof value === 'object' || typeof value === 'function') && typeof value['then'] === 'function'40/*eslint no-unused-vars: "off"*/41} catch (ex) {42return false43}44}4546module.exports = {47isObject,48isPromise,49}505152