@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
43 lines (42 loc) • 1.4 kB
JavaScript
import { getClient } from "../currentScopes.js";
import { defineIntegration } from "../integration.js";
import { getOriginalFunction } from "../utils/object.js";
// src/integrations/functiontostring.ts
const INTEGRATION_NAME = "FunctionToString";
const SETUP_CLIENTS = /* @__PURE__ */ new WeakMap();
const _functionToStringIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
const originalFunctionToString = Function.prototype.toString;
const callOriginalFunctionToString = Function.prototype.call.bind(originalFunctionToString);
const hasOwnProperty = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
try {
Function.prototype.toString = function() {
let unwrappedFunction;
try {
if (SETUP_CLIENTS.has(getClient()) && hasOwnProperty(this, "__sentry_original__")) unwrappedFunction = getOriginalFunction(this);
} catch {}
return callOriginalFunctionToString(unwrappedFunction ?? this);
};
} catch {}
},
setup(client) {
SETUP_CLIENTS.set(client, true);
}
};
});
/**
* Patch toString calls to return proper name for wrapped functions.
*
* ```js
* Sentry.init({
* integrations: [
* functionToStringIntegration(),
* ],
* });
* ```
*/
const functionToStringIntegration = defineIntegration(_functionToStringIntegration);
export { functionToStringIntegration };
//# sourceMappingURL=functiontostring.js.map