1
|
var getPrototypeOf = require("./getPrototypeOf");
|
2
|
|
3
|
var setPrototypeOf = require("./setPrototypeOf");
|
4
|
|
5
|
var isNativeFunction = require("./isNativeFunction");
|
6
|
|
7
|
var construct = require("./construct");
|
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
|
};
|
39
|
|
40
|
return _wrapNativeSuper(Class);
|
41
|
}
|
42
|
|
43
|
module.exports = _wrapNativeSuper;
|