Files
discord-decomp/_bundle/isNativeFunction.js
T
2026-11-01 12:12:55 +02:00

99 lines
2.4 KiB
JavaScript

// Metro module 986 (f987).
import { GLOBAL_OBJ } from "./Module821";
import { DEBUG_BUILD } from "./Module823";
import { debug } from "./consoleSandbox";
let isNativeFunction;
const _isFetchSupported = function _isFetchSupported() {
if ("fetch" in GLOBAL_OBJ) {
try {
new Headers();
new Request("data:,");
new Response();
} catch ($e) {
return false;
}
return true;
}
return false;
};
isNativeFunction = function isNativeFunction(fetch) {
return fetch ? /^function\s+\w+\(\)\s+\{\s+\[native code\]\s+\}$/.test(fetch.toString()) : fetch;
};
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
export { isNativeFunction };
export function supportsDOMError() {
try {
new DOMError("");
} catch ($e) {
return false;
}
return true;
}
export function supportsDOMException() {
try {
new DOMException("");
} catch ($e) {
return false;
}
return true;
}
export function supportsErrorEvent() {
try {
new ErrorEvent("");
} catch ($e) {
return false;
}
return true;
}
export { _isFetchSupported as supportsFetch };
export function supportsHistory() {
return "history" in GLOBAL_OBJ && !!GLOBAL_OBJ.history;
}
export function supportsNativeFetch() {
if (typeof globalThis.EdgeRuntime === "string") {
return true;
}
if (_isFetchSupported()) {
if (isNativeFunction(GLOBAL_OBJ.fetch)) {
return true;
}
let r20 = false;
const document2 = GLOBAL_OBJ.document;
if (document2 && typeof document2.createElement === "function") {
try {
const element = document2.createElement("iframe");
element.hidden = true;
document2.head.appendChild(element);
if (element.contentWindow?.fetch) {
r20 = isNativeFunction(element.contentWindow.fetch);
}
document2.head.removeChild(element);
} catch (r41) {
if (DEBUG_BUILD) {
debug.warn("Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ", r41);
}
}
}
return r20;
}
return false;
}
export function supportsReferrerPolicy() {
if (_isFetchSupported()) {
try {
new Request("_", {
referrerPolicy: "origin"
});
} catch ($e) {
return false;
}
return true;
}
return false;
}
export function supportsReportingObserver() {
return "ReportingObserver" in GLOBAL_OBJ;
}