UNPKG

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