"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/es5-ext/function/_define-length.js" (8 Mar 2017, 1201 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict';
    2 
    3 var toPosInt = require('../number/to-pos-integer')
    4 
    5   , test = function (a, b) {}, desc, defineProperty
    6   , generate, mixin;
    7 
    8 try {
    9     Object.defineProperty(test, 'length', { configurable: true, writable: false,
   10         enumerable: false, value: 1 });
   11 } catch (ignore) {}
   12 
   13 if (test.length === 1) {
   14     // ES6
   15     desc = { configurable: true, writable: false, enumerable: false };
   16     defineProperty = Object.defineProperty;
   17     module.exports = function (fn, length) {
   18         length = toPosInt(length);
   19         if (fn.length === length) return fn;
   20         desc.value = length;
   21         return defineProperty(fn, 'length', desc);
   22     };
   23 } else {
   24     mixin = require('../object/mixin');
   25     generate = (function () {
   26         var cache = [];
   27         return function (l) {
   28             var args, i = 0;
   29             if (cache[l]) return cache[l];
   30             args = [];
   31             while (l--) args.push('a' + (++i).toString(36));
   32             return new Function('fn', 'return function (' + args.join(', ') +
   33                 ') { return fn.apply(this, arguments); };');
   34         };
   35     }());
   36     module.exports = function (src, length) {
   37         var target;
   38         length = toPosInt(length);
   39         if (src.length === length) return src;
   40         target = generate(length)(src);
   41         try { mixin(target, src); } catch (ignore) {}
   42         return target;
   43     };
   44 }