| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
(function (root, factory) { |
| 14 |
|
| 15 |
if (typeof define === 'function' && define.amd) { |
| 16 |
|
| 17 |
define(factory); |
| 18 |
} else if (typeof exports === 'object') { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
module.exports = factory(); |
| 23 |
} else { |
| 24 |
|
| 25 |
root.returnExports = factory(); |
| 26 |
} |
| 27 |
}(this, function () { |
| 28 |
'use strict'; |
| 29 |
|
| 30 |
|
| 31 |
var getGlobal = new Function('return this;'); |
| 32 |
|
| 33 |
|
| 34 |
var globals = getGlobal(); |
| 35 |
var Object = globals.Object; |
| 36 |
var _call = Function.call.bind(Function.call); |
| 37 |
var functionToString = Function.toString; |
| 38 |
var _strMatch = String.prototype.match; |
| 39 |
|
| 40 |
var throwsError = function (func) { |
| 41 |
try { |
| 42 |
func(); |
| 43 |
return false; |
| 44 |
} catch (e) { |
| 45 |
return true; |
| 46 |
} |
| 47 |
}; |
| 48 |
var arePropertyDescriptorsSupported = function () { |
| 49 |
|
| 50 |
return !throwsError(function () { |
| 51 |
Object.defineProperty({}, 'x', { get: function () {} }); |
| 52 |
}); |
| 53 |
}; |
| 54 |
var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported(); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
(function () { |
| 66 |
if (Object.setPrototypeOf) { return; } |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
var getOwnPropertyNames = Object.getOwnPropertyNames; |
| 71 |
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 72 |
var create = Object.create; |
| 73 |
var defineProperty = Object.defineProperty; |
| 74 |
var getPrototypeOf = Object.getPrototypeOf; |
| 75 |
var objProto = Object.prototype; |
| 76 |
|
| 77 |
var copyDescriptors = function (target, source) { |
| 78 |
|
| 79 |
getOwnPropertyNames(source).forEach(function (key) { |
| 80 |
defineProperty( |
| 81 |
target, |
| 82 |
key, |
| 83 |
getOwnPropertyDescriptor(source, key) |
| 84 |
); |
| 85 |
}); |
| 86 |
return target; |
| 87 |
}; |
| 88 |
|
| 89 |
var createAndCopy = function (origin, proto) { |
| 90 |
return copyDescriptors(create(proto), origin); |
| 91 |
}; |
| 92 |
var set, setPrototypeOf; |
| 93 |
try { |
| 94 |
|
| 95 |
|
| 96 |
set = getOwnPropertyDescriptor(objProto, '__proto__').set; |
| 97 |
set.call({}, null); |
| 98 |
|
| 99 |
|
| 100 |
setPrototypeOf = function (origin, proto) { |
| 101 |
set.call(origin, proto); |
| 102 |
return origin; |
| 103 |
}; |
| 104 |
} catch (e) { |
| 105 |
|
| 106 |
set = { __proto__: null }; |
| 107 |
|
| 108 |
|
| 109 |
if (set instanceof Object) { |
| 110 |
setPrototypeOf = createAndCopy; |
| 111 |
} else { |
| 112 |
|
| 113 |
|
| •114 |
Object.setPrototypeOf(set, objProto); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
if (set instanceof Object) { |
| 119 |
setPrototypeOf = function (origin, proto) { |
| 120 |
|
| 121 |
|
| •122 |
Object.setPrototypeOf(origin, proto); |
| 123 |
|
| 124 |
return origin; |
| 125 |
}; |
| 126 |
} else { |
| 127 |
|
| 128 |
|
| 129 |
setPrototypeOf = function (origin, proto) { |
| 130 |
|
| 131 |
if (getPrototypeOf(origin)) { |
| 132 |
|
| 133 |
|
| •134 |
Object.setPrototypeOf(origin, proto); |
| 135 |
|
| 136 |
return origin; |
| 137 |
} |
| 138 |
|
| 139 |
return createAndCopy(origin, proto); |
| 140 |
}; |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
Object.setPrototypeOf = setPrototypeOf; |
| 145 |
}()); |
| 146 |
|
| 147 |
if (supportsDescriptors && function foo() {}.name !== 'foo') { |
| 148 |
|
| 149 |
Object.defineProperty(Function.prototype, 'name', { |
| 150 |
configurable: true, |
| 151 |
enumerable: false, |
| 152 |
get: function () { |
| 153 |
if (this === Function.prototype) { |
| 154 |
return ''; |
| 155 |
} |
| 156 |
var str = _call(functionToString, this); |
| 157 |
var match = _call(_strMatch, str, /\s*function\s+([^(\s]*)\s*/); |
| 158 |
var name = match && match[1]; |
| 159 |
Object.defineProperty(this, 'name', { |
| 160 |
configurable: true, |
| 161 |
enumerable: false, |
| 162 |
writable: false, |
| 163 |
value: name |
| 164 |
}); |
| 165 |
return name; |
| 166 |
} |
| 167 |
}); |
| 168 |
} |
| 169 |
})); |