build: polyfills

This commit is contained in:
dongchengjie
2024-05-29 09:39:26 +08:00
parent ef7659691b
commit 073beb0135
7 changed files with 290 additions and 247 deletions

33
src/polyfills/WeakRef.js Normal file
View File

@@ -0,0 +1,33 @@
(function (global) {
if (typeof global === "object" && global) {
if (typeof global["WeakRef"] === "undefined") {
global.WeakRef = (function (wm) {
function WeakRef(target) {
wm.set(this, target);
}
WeakRef.prototype.deref = function () {
return wm.get(this);
};
return WeakRef;
})(new WeakMap());
}
}
})(
(function () {
switch (true) {
case typeof globalThis === "object" && !!globalThis:
return globalThis;
case typeof self === "object" && !!self:
return self;
case typeof window === "object" && !!window:
return window;
case typeof global === "object" && !!global:
return global;
case typeof Function === "function":
return Function("return this")();
}
return null;
})()
);