123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import '@sentry-internal/tracing';
- import { withScope, captureException } from '@sentry/core';
- import { GLOBAL_OBJ, getOriginalFunction, markFunctionWrapped, addNonEnumerableProperty, addExceptionTypeValue, addExceptionMechanism } from '@sentry/utils';
- const WINDOW = GLOBAL_OBJ ;
- let ignoreOnError = 0;
- function shouldIgnoreOnError() {
- return ignoreOnError > 0;
- }
- function ignoreNextOnError() {
-
- ignoreOnError++;
- setTimeout(() => {
- ignoreOnError--;
- });
- }
- function wrap(
- fn,
- options
- = {},
- before,
-
- ) {
-
-
-
-
-
-
- if (typeof fn !== 'function') {
- return fn;
- }
- try {
-
-
- const wrapper = fn.__sentry_wrapped__;
- if (wrapper) {
- return wrapper;
- }
-
- if (getOriginalFunction(fn)) {
- return fn;
- }
- } catch (e) {
-
-
-
- return fn;
- }
-
-
- const sentryWrapped = function () {
- const args = Array.prototype.slice.call(arguments);
- try {
- if (before && typeof before === 'function') {
- before.apply(this, arguments);
- }
-
- const wrappedArguments = args.map((arg) => wrap(arg, options));
-
-
-
-
- return fn.apply(this, wrappedArguments);
- } catch (ex) {
- ignoreNextOnError();
- withScope(scope => {
- scope.addEventProcessor(event => {
- if (options.mechanism) {
- addExceptionTypeValue(event, undefined, undefined);
- addExceptionMechanism(event, options.mechanism);
- }
- event.extra = {
- ...event.extra,
- arguments: args,
- };
- return event;
- });
- captureException(ex);
- });
- throw ex;
- }
- };
-
-
-
- try {
- for (const property in fn) {
- if (Object.prototype.hasOwnProperty.call(fn, property)) {
- sentryWrapped[property] = fn[property];
- }
- }
- } catch (_oO) {}
-
-
- markFunctionWrapped(sentryWrapped, fn);
- addNonEnumerableProperty(fn, '__sentry_wrapped__', sentryWrapped);
-
- try {
- const descriptor = Object.getOwnPropertyDescriptor(sentryWrapped, 'name') ;
- if (descriptor.configurable) {
- Object.defineProperty(sentryWrapped, 'name', {
- get() {
- return fn.name;
- },
- });
- }
-
- } catch (_oO) {}
- return sentryWrapped;
- }
- export { WINDOW, ignoreNextOnError, shouldIgnoreOnError, wrap };
|