wrapNativeSuper.js (1296B)
1 var getPrototypeOf = require("./getPrototypeOf.js"); 2 3 var setPrototypeOf = require("./setPrototypeOf.js"); 4 5 var isNativeFunction = require("./isNativeFunction.js"); 6 7 var construct = require("./construct.js"); 8 9 function _wrapNativeSuper(Class) { 10 var _cache = typeof Map === "function" ? new Map() : undefined; 11 12 module.exports = _wrapNativeSuper = function _wrapNativeSuper(Class) { 13 if (Class === null || !isNativeFunction(Class)) return Class; 14 15 if (typeof Class !== "function") { 16 throw new TypeError("Super expression must either be null or a function"); 17 } 18 19 if (typeof _cache !== "undefined") { 20 if (_cache.has(Class)) return _cache.get(Class); 21 22 _cache.set(Class, Wrapper); 23 } 24 25 function Wrapper() { 26 return construct(Class, arguments, getPrototypeOf(this).constructor); 27 } 28 29 Wrapper.prototype = Object.create(Class.prototype, { 30 constructor: { 31 value: Wrapper, 32 enumerable: false, 33 writable: true, 34 configurable: true 35 } 36 }); 37 return setPrototypeOf(Wrapper, Class); 38 }, module.exports.__esModule = true, module.exports["default"] = module.exports; 39 return _wrapNativeSuper(Class); 40 } 41 42 module.exports = _wrapNativeSuper, module.exports.__esModule = true, module.exports["default"] = module.exports;