Projekt

Obecné

Profil

Stáhnout (1.05 KB) Statistiky
| Větev: | Revize:
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

    
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
}
(79-79/80)