1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.wrapNativeSuper = void 0;
|
4 |
|
5 | function wrapNativeSuper(Class) {
|
6 | var _cache = typeof Map === "function" ? new Map() : undefined;
|
7 |
|
8 | exports.wrapNativeSuper = wrapNativeSuper = function wrapNativeSuper(Class) {
|
9 | if (Class === null || !_isNativeFunction(Class))
|
10 | return Class;
|
11 | if (typeof Class !== "function") {
|
12 | throw new TypeError("Super expression must either be null or a function");
|
13 | }
|
14 | if (typeof _cache !== "undefined") {
|
15 | if (_cache.has(Class))
|
16 | return _cache.get(Class);
|
17 | _cache.set(Class, Wrapper);
|
18 | }
|
19 | function Wrapper() {
|
20 |
|
21 | return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
22 | }
|
23 | Wrapper.prototype = Object.create(Class.prototype, {
|
24 | constructor: {
|
25 | value: Wrapper,
|
26 | enumerable: false,
|
27 | writable: true,
|
28 | configurable: true
|
29 | }
|
30 | });
|
31 | return _setPrototypeOf(Wrapper, Class);
|
32 | };
|
33 | return wrapNativeSuper(Class);
|
34 | }
|
35 | exports.wrapNativeSuper = wrapNativeSuper;
|
36 | function isNativeReflectConstruct() {
|
37 | if (typeof Reflect === "undefined" || !Reflect.construct)
|
38 | return false;
|
39 |
|
40 | if (Reflect.construct.sham)
|
41 | return false;
|
42 | if (typeof Proxy === "function")
|
43 | return true;
|
44 | try {
|
45 | Date.prototype.toString.call(Reflect.construct(Date, [], function () { }));
|
46 | return true;
|
47 | }
|
48 | catch (e) {
|
49 | return false;
|
50 | }
|
51 | }
|
52 |
|
53 | function _construct(Parent, args, Class) {
|
54 | if (isNativeReflectConstruct()) {
|
55 |
|
56 | _construct = Reflect.construct;
|
57 | }
|
58 | else {
|
59 |
|
60 | _construct = function _construct(Parent, args, Class) {
|
61 | var a = [null];
|
62 | a.push.apply(a, args);
|
63 |
|
64 | var Constructor = Function.bind.apply(Parent, a);
|
65 |
|
66 | var instance = new Constructor();
|
67 | if (Class)
|
68 | _setPrototypeOf(instance, Class.prototype);
|
69 | return instance;
|
70 | };
|
71 | }
|
72 |
|
73 | return _construct.apply(null, arguments);
|
74 | }
|
75 | function _isNativeFunction(fn) {
|
76 | return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
77 | }
|
78 |
|
79 | function _setPrototypeOf(o, p) {
|
80 |
|
81 | _setPrototypeOf =
|
82 | Object.setPrototypeOf ||
|
83 |
|
84 | function _setPrototypeOf(o, p) {
|
85 | o.__proto__ = p;
|
86 | return o;
|
87 | };
|
88 | return _setPrototypeOf(o, p);
|
89 | }
|
90 |
|
91 | function _getPrototypeOf(o) {
|
92 |
|
93 | _getPrototypeOf = Object.setPrototypeOf
|
94 | ? Object.getPrototypeOf
|
95 | : function _getPrototypeOf(
|
96 | //@ts-ignore
|
97 | o) {
|
98 | return o.__proto__ || Object.getPrototypeOf(o);
|
99 | };
|
100 | return _getPrototypeOf(o);
|
101 | }
|
102 | module.exports = {
|
103 | wrapNativeSuper
|
104 | };
|