You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

4 years ago
  1. import getPrototypeOf from "./getPrototypeOf";
  2. import setPrototypeOf from "./setPrototypeOf";
  3. import isNativeFunction from "./isNativeFunction";
  4. import construct from "./construct";
  5. export default function _wrapNativeSuper(Class) {
  6. var _cache = typeof Map === "function" ? new Map() : undefined;
  7. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  8. if (Class === null || !isNativeFunction(Class)) return Class;
  9. if (typeof Class !== "function") {
  10. throw new TypeError("Super expression must either be null or a function");
  11. }
  12. if (typeof _cache !== "undefined") {
  13. if (_cache.has(Class)) return _cache.get(Class);
  14. _cache.set(Class, Wrapper);
  15. }
  16. function Wrapper() {
  17. return construct(Class, arguments, getPrototypeOf(this).constructor);
  18. }
  19. Wrapper.prototype = Object.create(Class.prototype, {
  20. constructor: {
  21. value: Wrapper,
  22. enumerable: false,
  23. writable: true,
  24. configurable: true
  25. }
  26. });
  27. return setPrototypeOf(Wrapper, Class);
  28. };
  29. return _wrapNativeSuper(Class);
  30. }