"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/object-assign/index.js" (7 Feb 2017, 1994 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 /* eslint-disable no-unused-vars */
    3 var hasOwnProperty = Object.prototype.hasOwnProperty;
    4 var propIsEnumerable = Object.prototype.propertyIsEnumerable;
    5 
    6 function toObject(val) {
    7     if (val === null || val === undefined) {
    8         throw new TypeError('Object.assign cannot be called with null or undefined');
    9     }
   10 
   11     return Object(val);
   12 }
   13 
   14 function shouldUseNative() {
   15     try {
   16         if (!Object.assign) {
   17             return false;
   18         }
   19 
   20         // Detect buggy property enumeration order in older V8 versions.
   21 
   22         // https://bugs.chromium.org/p/v8/issues/detail?id=4118
   23         var test1 = new String('abc');  // eslint-disable-line
   24         test1[5] = 'de';
   25         if (Object.getOwnPropertyNames(test1)[0] === '5') {
   26             return false;
   27         }
   28 
   29         // https://bugs.chromium.org/p/v8/issues/detail?id=3056
   30         var test2 = {};
   31         for (var i = 0; i < 10; i++) {
   32             test2['_' + String.fromCharCode(i)] = i;
   33         }
   34         var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
   35             return test2[n];
   36         });
   37         if (order2.join('') !== '0123456789') {
   38             return false;
   39         }
   40 
   41         // https://bugs.chromium.org/p/v8/issues/detail?id=3056
   42         var test3 = {};
   43         'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
   44             test3[letter] = letter;
   45         });
   46         if (Object.keys(Object.assign({}, test3)).join('') !==
   47                 'abcdefghijklmnopqrst') {
   48             return false;
   49         }
   50 
   51         return true;
   52     } catch (e) {
   53         // We don't expect any of the above to throw, but better to be safe.
   54         return false;
   55     }
   56 }
   57 
   58 module.exports = shouldUseNative() ? Object.assign : function (target, source) {
   59     var from;
   60     var to = toObject(target);
   61     var symbols;
   62 
   63     for (var s = 1; s < arguments.length; s++) {
   64         from = Object(arguments[s]);
   65 
   66         for (var key in from) {
   67             if (hasOwnProperty.call(from, key)) {
   68                 to[key] = from[key];
   69             }
   70         }
   71 
   72         if (Object.getOwnPropertySymbols) {
   73             symbols = Object.getOwnPropertySymbols(from);
   74             for (var i = 0; i < symbols.length; i++) {
   75                 if (propIsEnumerable.call(from, symbols[i])) {
   76                     to[symbols[i]] = from[symbols[i]];
   77                 }
   78             }
   79         }
   80     }
   81 
   82     return to;
   83 };