time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

polyfill.js (1697B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var hasOwnProp = require( './../../has-own-property' );
     24 var isEnumerableProperty = require( './../../is-enumerable-property' );
     25 var isArray = require( './../../is-array' );
     26 var isInteger = require( '@stdlib/math/base/assert/is-integer' );
     27 var MAX_LENGTH = require( '@stdlib/constants/uint32/max' );
     28 
     29 
     30 // MAIN //
     31 
     32 /**
     33 * Tests whether a value is an `arguments` object.
     34 *
     35 * @private
     36 * @param {*} value - value to test
     37 * @returns {boolean} boolean indicating whether a value is an `arguments` object
     38 *
     39 * @example
     40 * function foo() {
     41 *     return arguments;
     42 * }
     43 *
     44 * var bool = isArguments( foo() );
     45 * // returns true
     46 *
     47 * @example
     48 * var bool = isArguments( [] );
     49 * // returns false
     50 */
     51 function isArguments( value ) {
     52 	return (
     53 		value !== null &&
     54 		typeof value === 'object' &&
     55 		!isArray( value ) &&
     56 		typeof value.length === 'number' &&
     57 		isInteger( value.length ) &&
     58 		value.length >= 0 &&
     59 		value.length <= MAX_LENGTH &&
     60 		hasOwnProp( value, 'callee' ) &&
     61 		!isEnumerableProperty( value, 'callee' )
     62 	);
     63 }
     64 
     65 
     66 // EXPORTS //
     67 
     68 module.exports = isArguments;