diff --git a/package.json b/package.json index e276124c89bc..ddd91c7f4243 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "grunt-release": "~0.6.0", "grunt-s3": "~0.2.0-alpha.3", "grunt-sri": "mattrobenolt/grunt-sri#pretty", + "jquery": "^2.1.4", "lodash": "~2.4.0", "proxyquireify": "^3.0.0", "sinon": "~1.7.3", diff --git a/src/raven.js b/src/raven.js index f5fbacc75665..272059632588 100644 --- a/src/raven.js +++ b/src/raven.js @@ -55,6 +55,7 @@ function Raven() { this._originalConsoleMethods = {}; this._plugins = []; this._startTime = now(); + this._wrappedBuiltIns = []; for (var method in this._originalConsole) { this._originalConsoleMethods[method] = this._originalConsole[method]; @@ -267,6 +268,9 @@ Raven.prototype = { */ uninstall: function() { TraceKit.report.uninstall(); + + this._restoreBuiltIns(); + this._isRavenInstalled = false; return this; @@ -545,9 +549,12 @@ Raven.prototype = { _wrapBuiltIns: function() { var self = this; - function fill(obj, name, replacement) { + function fill(obj, name, replacement, noUndo) { var orig = obj[name]; obj[name] = replacement(orig); + if (!noUndo) { // xhr instances can't undo otherwise mem leaks + self._wrappedBuiltIns.push([obj, name, orig]); + } } function wrapTimeFn(orig) { @@ -613,7 +620,7 @@ Raven.prototype = { if (prop in xhr && Object.prototype.toString.call(xhr[prop]) === '[object Function]') { fill(xhr, prop, function (orig) { return self.wrap(orig); - }); + }, true); } }); origOpen.apply(this, arguments); @@ -621,12 +628,26 @@ Raven.prototype = { } var $ = window.jQuery || window.$; - var origReady; if ($ && $.fn && $.fn.ready) { - origReady = $.fn.ready; - $.fn.ready = function ravenjQueryReadyWrapper(fn) { - return origReady.call(this, self.wrap(fn)); - }; + fill($.fn, 'ready', function (orig) { + return function (fn) { + orig.call(this, self.wrap(fn)); + }; + }); + } + }, + + _restoreBuiltIns: function () { + // restore any wrapped builtins + var builtin; + while (this._wrappedBuiltIns.length) { + builtin = this._wrappedBuiltIns.shift(); + + var obj = builtin[0], + name = builtin[1], + orig = builtin[2]; + + obj[name] = orig; } }, diff --git a/test/integration/frame.html b/test/integration/frame.html index a902ccfca1b1..4fa3f84acf13 100644 --- a/test/integration/frame.html +++ b/test/integration/frame.html @@ -36,6 +36,7 @@ }; }()); +