diff --git a/src/notifier.js b/src/notifier.js index 1c6866f99..6cb4d602f 100644 --- a/src/notifier.js +++ b/src/notifier.js @@ -620,6 +620,10 @@ Notifier.prototype.scope = _wrapNotifierFn(function(payloadOptions) { Notifier.prototype.wrap = function(f) { var _this = this; + if (typeof f !== 'function') { + return f; + } + // If the given function is already a wrapped function, just // return it instead of wrapping twice if (f._isWrap) { diff --git a/src/shim.js b/src/shim.js index 3d686c28c..676625d82 100644 --- a/src/shim.js +++ b/src/shim.js @@ -127,6 +127,10 @@ Rollbar.prototype.loadFull = function(window, document, immediate, config) { Rollbar.prototype.wrap = function(f) { var _this = this; + if (typeof f !== 'function') { + return f; + } + if (f._isWrap) { return f; } diff --git a/test/notifier.test.js b/test/notifier.test.js index b580787bf..519019e56 100644 --- a/test/notifier.test.js +++ b/test/notifier.test.js @@ -1475,4 +1475,9 @@ describe("Notifier.wrap()", function() { done(); }); + + it("should let non-functions pass through unchanged", function() { + var object = {}; + expect(window.Rollbar.wrap(object)).to.be.equal(object); + }); }); diff --git a/test/shim.test.js b/test/shim.test.js index 007556d98..54af99e33 100644 --- a/test/shim.test.js +++ b/test/shim.test.js @@ -296,6 +296,13 @@ describe("window.Rollbar.log/debug/info/warn/warning/error/critical()", function }); }); +describe("window.Rollbar.wrap()", function() { + it("should let non-functions pass through unchanged", function() { + var object = {}; + expect(window.Rollbar.wrap(object)).to.be.equal(object); + }); +}); + describe("window.Rollbar.loadFull()", function() { var errArgs;