es6-sham.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*!
  2. * https://github.com/paulmillr/es6-shim
  3. * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
  4. * and contributors, MIT License
  5. * es6-sham: v0.35.4
  6. * see https://github.com/paulmillr/es6-shim/blob/0.35.3/LICENSE
  7. * Details and documentation:
  8. * https://github.com/paulmillr/es6-shim/
  9. */
  10. // UMD (Universal Module Definition)
  11. // see https://github.com/umdjs/umd/blob/master/returnExports.js
  12. (function (root, factory) {
  13. /*global define */
  14. if (typeof define === 'function' && define.amd) {
  15. // AMD. Register as an anonymous module.
  16. define(factory);
  17. } else if (typeof exports === 'object') {
  18. // Node. Does not work with strict CommonJS, but
  19. // only CommonJS-like environments that support module.exports,
  20. // like Node.
  21. module.exports = factory();
  22. } else {
  23. // Browser globals (root is window)
  24. root.returnExports = factory();
  25. }
  26. }(this, function () {
  27. 'use strict';
  28. /* eslint-disable no-new-func */
  29. var getGlobal = new Function('return this;');
  30. /* eslint-enable no-new-func */
  31. var globals = getGlobal();
  32. var Object = globals.Object;
  33. var _call = Function.call.bind(Function.call);
  34. var functionToString = Function.toString;
  35. var _strMatch = String.prototype.match;
  36. var throwsError = function (func) {
  37. try {
  38. func();
  39. return false;
  40. } catch (e) {
  41. return true;
  42. }
  43. };
  44. var arePropertyDescriptorsSupported = function () {
  45. // if Object.defineProperty exists but throws, it's IE 8
  46. return !throwsError(function () {
  47. Object.defineProperty({}, 'x', { get: function () {} }); // eslint-disable-line getter-return
  48. });
  49. };
  50. var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
  51. // NOTE: This versions needs object ownership
  52. // because every promoted object needs to be reassigned
  53. // otherwise uncompatible browsers cannot work as expected
  54. //
  55. // NOTE: This might need es5-shim or polyfills upfront
  56. // because it's based on ES5 API.
  57. // (probably just an IE <= 8 problem)
  58. //
  59. // NOTE: nodejs is fine in version 0.8, 0.10, and future versions.
  60. (function () {
  61. if (Object.setPrototypeOf) { return; }
  62. // @author Andrea Giammarchi - @WebReflection
  63. var getOwnPropertyNames = Object.getOwnPropertyNames;
  64. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  65. var create = Object.create;
  66. var defineProperty = Object.defineProperty;
  67. var getPrototypeOf = Object.getPrototypeOf;
  68. var objProto = Object.prototype;
  69. var copyDescriptors = function (target, source) {
  70. // define into target descriptors from source
  71. getOwnPropertyNames(source).forEach(function (key) {
  72. defineProperty(
  73. target,
  74. key,
  75. getOwnPropertyDescriptor(source, key)
  76. );
  77. });
  78. return target;
  79. };
  80. // used as fallback when no promotion is possible
  81. var createAndCopy = function (origin, proto) {
  82. return copyDescriptors(create(proto), origin);
  83. };
  84. var set, setPrototypeOf;
  85. try {
  86. // this might fail for various reasons
  87. // ignore if Chrome cought it at runtime
  88. set = getOwnPropertyDescriptor(objProto, '__proto__').set;
  89. set.call({}, null);
  90. // setter not poisoned, it can promote
  91. // Firefox, Chrome
  92. setPrototypeOf = function (origin, proto) {
  93. set.call(origin, proto);
  94. return origin;
  95. };
  96. } catch (e) {
  97. // do one or more feature detections
  98. set = { __proto__: null };
  99. // if proto does not work, needs to fallback
  100. // some Opera, Rhino, ducktape
  101. if (set instanceof Object) {
  102. setPrototypeOf = createAndCopy;
  103. } else {
  104. // verify if null objects are buggy
  105. /* eslint-disable no-proto */
  106. set.__proto__ = objProto;
  107. /* eslint-enable no-proto */
  108. // if null objects are buggy
  109. // nodejs 0.8 to 0.10
  110. if (set instanceof Object) {
  111. setPrototypeOf = function (origin, proto) {
  112. // use such bug to promote
  113. /* eslint-disable no-proto */
  114. origin.__proto__ = proto;
  115. /* eslint-enable no-proto */
  116. return origin;
  117. };
  118. } else {
  119. // try to use proto or fallback
  120. // Safari, old Firefox, many others
  121. setPrototypeOf = function (origin, proto) {
  122. // if proto is not null
  123. if (getPrototypeOf(origin)) {
  124. // use __proto__ to promote
  125. /* eslint-disable no-proto */
  126. origin.__proto__ = proto;
  127. /* eslint-enable no-proto */
  128. return origin;
  129. }
  130. // otherwise unable to promote: fallback
  131. return createAndCopy(origin, proto);
  132. };
  133. }
  134. }
  135. }
  136. Object.setPrototypeOf = setPrototypeOf;
  137. }());
  138. if (supportsDescriptors && function foo() {}.name !== 'foo') {
  139. /* eslint no-extend-native: 1 */
  140. Object.defineProperty(Function.prototype, 'name', {
  141. configurable: true,
  142. enumerable: false,
  143. get: function () {
  144. if (this === Function.prototype) {
  145. return '';
  146. }
  147. var str = _call(functionToString, this);
  148. var match = _call(_strMatch, str, /\s*function\s+([^(\s]*)\s*/);
  149. var name = match && match[1];
  150. Object.defineProperty(this, 'name', {
  151. configurable: true,
  152. enumerable: false,
  153. writable: false,
  154. value: name
  155. });
  156. return name;
  157. }
  158. });
  159. }
  160. }));