Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/browser/src/integrations/trycatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ export class TryCatch implements Integration {
type: 'instrument',
},
};
// If Instrument integration has been called before TryCatch
// use it as "before" callback in the wrap and use the original instead
if (original.__sentry__ && original.__sentry_original__) {

// If Instrument integration has been called before TryCatch, get the name of original function
if (original.__sentry_original__) {
wrapOptions.mechanism.data.handler = getFunctionName(original.__sentry_original__);
return wrap(original.__sentry_original__, wrapOptions, original.__sentry_wrapped__);
}

// Otherwise wrap directly
Expand Down
16 changes: 16 additions & 0 deletions packages/browser/test/integration/suites/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,22 @@ describe("wrapped built-ins", function() {
});
});

it("should not call XMLHttpRequest onreadystatechange more than once", function() {
return runInSandbox(sandbox, { manual: true }, function() {
window.calls = 0;
var xhr = new XMLHttpRequest();
xhr.open("GET", "/base/subjects/example.json");
xhr.onreadystatechange = function wat() {
window.finalizeManualTest();
window.calls += 1;
};
xhr.send();
}).then(function(summary) {
assert.equal(summary.window.calls, 3);
delete summary.window.calls;
});
});

it(
optional(
"should capture built-in's mechanism type as instrument",
Expand Down
8 changes: 0 additions & 8 deletions packages/utils/src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,10 @@ export function fill(source: { [key: string]: any }, name: string, replacement:
try {
wrapped.prototype = wrapped.prototype || {};
Object.defineProperties(wrapped, {
__sentry__: {
enumerable: false,
value: true,
},
__sentry_original__: {
enumerable: false,
value: original,
},
__sentry_wrapped__: {
enumerable: false,
value: wrapped,
},
});
} catch (_Oo) {
// This can throw if multiple fill happens on a global object like XMLHttpRequest
Expand Down
4 changes: 0 additions & 4 deletions packages/utils/test/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,9 @@ describe('fill()', () => {
fill(source, name, replacement);

// Shouldn't show up in iteration
expect(Object.keys(replacement)).not.toContain('__sentry__');
expect(Object.keys(replacement)).not.toContain('__sentry_original__');
expect(Object.keys(replacement)).not.toContain('__sentry_wrapped__');
// But should be accessible directly
expect(source.foo.__sentry__).toBe(true);
expect(source.foo.__sentry_original__).toBe(source.foo);
expect(source.foo.__sentry_wrapped__).toBe(source.foo);
});

test('should preserve functions prototype if one exists', () => {
Expand Down