Skip to content

Commit

Permalink
Merge pull request #17 from kmontag/wrap-nonfunctions
Browse files Browse the repository at this point in the history
Allow non-functions to be passed to Rollbar.wrap
  • Loading branch information
coryvirok committed Mar 7, 2014
2 parents 2c9f47c + edd71d0 commit b0d3613
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions test/notifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
7 changes: 7 additions & 0 deletions test/shim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b0d3613

Please sign in to comment.