Skip to content

Commit f061890

Browse files
committed
ref: Update wrap method to hide internal sentry flags
1 parent 411fa6e commit f061890

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
## 5.0.0
66

7-
- [node] fix: Events created from exception shouldnt have top-level message attribute
7+
- **breaking** [node] fix: Events created from exception shouldnt have top-level message attribute
8+
- [utils] ref: Update wrap method to hide internal sentry flags
9+
- [utils] fix: Make internal Sentry flags non-enumerable in fill util
810

911
## 4.5.3
1012

packages/browser/src/integrations/helpers.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,26 @@ export function wrap(
113113
}
114114
} catch (_oO) {} // tslint:disable-line:no-empty
115115

116+
fn.prototype = fn.prototype || {};
116117
sentryWrapped.prototype = fn.prototype;
117-
fn.__sentry_wrapped__ = sentryWrapped;
118+
119+
Object.defineProperty(fn, '__sentry_wrapped__', {
120+
enumerable: false,
121+
value: sentryWrapped,
122+
});
118123

119124
// Signal that this function has been wrapped/filled already
120125
// for both debugging and to prevent it to being wrapped/filled twice
121-
sentryWrapped.__sentry__ = true;
122-
sentryWrapped.__sentry_original__ = fn;
126+
Object.defineProperties(sentryWrapped, {
127+
__sentry__: {
128+
enumerable: false,
129+
value: true,
130+
},
131+
__sentry_original__: {
132+
enumerable: false,
133+
value: fn,
134+
},
135+
});
123136

124137
return sentryWrapped;
125138
}

packages/browser/test/integrations/helpers.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,21 @@ describe('wrap()', () => {
179179
expect(error.message).equal('boom');
180180
}
181181
});
182+
183+
it.only('internal flags shouldnt be enumerable', () => {
184+
const fn = (() => 1337) as SentryWrappedFunction;
185+
const wrapped = wrap(fn);
186+
187+
// Shouldn't show up in iteration
188+
expect(Object.keys(fn)).to.not.include('__sentry__');
189+
expect(Object.keys(fn)).to.not.include('__sentry_original__');
190+
expect(Object.keys(fn)).to.not.include('__sentry_wrapped__');
191+
expect(Object.keys(wrapped)).to.not.include('__sentry__');
192+
expect(Object.keys(wrapped)).to.not.include('__sentry_original__');
193+
expect(Object.keys(wrapped)).to.not.include('__sentry_wrapped__');
194+
// But should be accessible directly
195+
expect(wrapped.__sentry__).to.equal(true);
196+
expect(wrapped.__sentry_original__).to.equal(fn);
197+
expect(fn.__sentry_wrapped__).to.equal(wrapped);
198+
});
182199
});

0 commit comments

Comments
 (0)