|
1 |
| -/*! Raven.js 1.1.0-rc2 (eafd5f4) | github.com/getsentry/raven-js */ |
| 1 | +/*! Raven.js 1.1.0-rc3 (067521d) | github.com/getsentry/raven-js */ |
2 | 2 |
|
3 | 3 | /*
|
4 | 4 | * Includes TraceKit
|
@@ -1132,7 +1132,7 @@ TK.remoteFetching = false;
|
1132 | 1132 | * @this {Raven}
|
1133 | 1133 | */
|
1134 | 1134 | var Raven = {
|
1135 |
| - VERSION: '1.1.0-rc2', |
| 1135 | + VERSION: '1.1.0-rc3', |
1136 | 1136 |
|
1137 | 1137 | // Expose TraceKit to the Raven namespace
|
1138 | 1138 | TraceKit: TK,
|
@@ -1258,29 +1258,55 @@ var Raven = {
|
1258 | 1258 | * @return {function} The newly wrapped functions with a context
|
1259 | 1259 | */
|
1260 | 1260 | wrap: function(options, func) {
|
| 1261 | + // 1 argument has been passed, and it's not a function |
| 1262 | + // so just return it |
| 1263 | + if (isUndefined(func) && !isFunction(options)) { |
| 1264 | + return options; |
| 1265 | + } |
| 1266 | + |
1261 | 1267 | // options is optional
|
1262 | 1268 | if (isFunction(options)) {
|
1263 | 1269 | func = options;
|
1264 | 1270 | options = undefined;
|
1265 | 1271 | }
|
1266 | 1272 |
|
1267 |
| - var property, |
1268 |
| - wrappedFunction = function() { |
1269 |
| - try { |
1270 |
| - return func.apply(this, arguments); |
1271 |
| - } catch(e) { |
1272 |
| - Raven.captureException(e, options); |
1273 |
| - throw e; |
1274 |
| - } |
1275 |
| - }; |
| 1273 | + // At this point, we've passed along 2 arguments, and the second one |
| 1274 | + // is not a function either, so we'll just return the second argument. |
| 1275 | + if (!isFunction(func)) { |
| 1276 | + return func; |
| 1277 | + } |
1276 | 1278 |
|
1277 |
| - for (property in func) { |
| 1279 | + // We don't wanna wrap it twice! |
| 1280 | + if (func.__raven__) { |
| 1281 | + return func; |
| 1282 | + } |
| 1283 | + |
| 1284 | + var self = this; |
| 1285 | + |
| 1286 | + function wrapped() { |
| 1287 | + var args = [], i = arguments.length; |
| 1288 | + // Recursively wrap all of a function's arguments that are |
| 1289 | + // functions themselves. |
| 1290 | + while(i--) args[i] = Raven.wrap(options, arguments[i]); |
| 1291 | + try { |
| 1292 | + return func.apply(self, args); |
| 1293 | + } catch(e) { |
| 1294 | + Raven.captureException(e, options); |
| 1295 | + } |
| 1296 | + } |
| 1297 | + |
| 1298 | + // copy over properties of the old function |
| 1299 | + for (var property in func) { |
1278 | 1300 | if (func.hasOwnProperty(property)) {
|
1279 |
| - wrappedFunction[property] = func[property]; |
| 1301 | + wrapped[property] = func[property]; |
1280 | 1302 | }
|
1281 | 1303 | }
|
1282 | 1304 |
|
1283 |
| - return wrappedFunction; |
| 1305 | + // Signal that this function has been wrapped already |
| 1306 | + // for both debugging and to prevent it to being wrapped twice |
| 1307 | + wrapped.__raven__ = true; |
| 1308 | + |
| 1309 | + return wrapped; |
1284 | 1310 | },
|
1285 | 1311 |
|
1286 | 1312 | /*
|
@@ -1421,6 +1447,10 @@ function isFunction(what) {
|
1421 | 1447 | return typeof what === 'function';
|
1422 | 1448 | }
|
1423 | 1449 |
|
| 1450 | +function isString(what) { |
| 1451 | + return typeof what === 'string'; |
| 1452 | +} |
| 1453 | + |
1424 | 1454 | function each(obj, callback) {
|
1425 | 1455 | var i, j;
|
1426 | 1456 |
|
@@ -1703,27 +1733,20 @@ function isSetup() {
|
1703 | 1733 | return true;
|
1704 | 1734 | }
|
1705 | 1735 |
|
1706 |
| -function wrapArguments(what) { |
1707 |
| - if (!isFunction(what)) return what; |
1708 |
| - |
1709 |
| - function wrapped() { |
1710 |
| - var args = [], i = arguments.length, arg; |
1711 |
| - while(i--) { |
1712 |
| - arg = arguments[i]; |
1713 |
| - args[i] = isFunction(arg) ? Raven.wrap(arg) : arg; |
1714 |
| - } |
1715 |
| - what.apply(null, args); |
1716 |
| - } |
1717 |
| - // copy over properties of the old function |
1718 |
| - for (var k in what) wrapped[k] = what[k]; |
1719 |
| - return wrapped; |
1720 |
| -} |
1721 |
| - |
1722 | 1736 | function joinRegExp(patterns) {
|
1723 |
| - // Combine an array of regular expressions into one large regexp |
| 1737 | + // Combine an array of regular expressions and strings into one large regexp |
1724 | 1738 | var sources = [], i = patterns.length;
|
1725 | 1739 | // lol, map
|
1726 |
| - while (i--) sources[i] = patterns[i].source; |
| 1740 | + while (i--) { |
| 1741 | + if (isString(patterns[i])) { |
| 1742 | + // If it's a string, we need to escape it |
| 1743 | + // Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions |
| 1744 | + sources[i] = patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); |
| 1745 | + } else { |
| 1746 | + // If it's a regexp already, we want to extract the source |
| 1747 | + sources[i] = patterns[i].source; |
| 1748 | + } |
| 1749 | + } |
1727 | 1750 | return new RegExp(sources.join('|'), 'i');
|
1728 | 1751 | }
|
1729 | 1752 |
|
|
0 commit comments