From 51db0d26468d2e2707442ad7e72dae2eac29d4ef Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Fri, 31 May 2013 16:21:57 -0700 Subject: [PATCH] Test logging from evaled string. --- packages/logging/logging.js | 7 +++---- packages/logging/logging_test.js | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/logging/logging.js b/packages/logging/logging.js index 825adc693e..156676f214 100644 --- a/packages/logging/logging.js +++ b/packages/logging/logging.js @@ -67,8 +67,6 @@ Log._getCallerDetails = function () { var orig = Error.prepareStackTrace; Error.prepareStackTrace = function(_, stack){ return stack; }; var err = new Error; - if (_.isFunction(Error.captureStackTrace)) - Error.captureStackTrace(err, arguments.callee); var stack = err.stack; Error.prepareStackTrace = orig; return stack; @@ -89,7 +87,8 @@ Log._getCallerDetails = function () { var line = lines[index]; // looking for the first line outside the logging package - while ((isV8?line.getFileName():line).indexOf('/packages/logging.js') !== -1) + while ((isV8 ? line.getFileName() || '' : line) + .indexOf('/packages/logging.js') !== -1) line = lines[++index]; var details = {}; @@ -101,7 +100,7 @@ Log._getCallerDetails = function () { // Possible format: https://foo.bar.com/scripts/file.js?random=foobar // For FF we parse the line, for V8 we call built-in function // XXX: if you can write the following in better way, please do it - details.file = isV8 ? line.getFileName() + details.file = isV8 ? line.getFileName() || (line.isEval() ? 'eval' : '') : line.split('@')[1].split(':').slice(0, -1).join(':'); details.file = details.file.split('/').slice(-1)[0].split('?')[0]; diff --git a/packages/logging/logging_test.js b/packages/logging/logging_test.js index 54099cb634..e634b71760 100644 --- a/packages/logging/logging_test.js +++ b/packages/logging/logging_test.js @@ -8,6 +8,10 @@ Tinytest.add("logging - _getCallerDetails", function (test) { // XXX: When we have source maps, we should uncomment the test above and // remove this one test.isTrue(details.file === 'logging.tests.js'); + + // evaled statements shouldn't crash + var code = "Log._getCallerDetails().file"; + test.matches(eval(code), /^eval|logging.tests.js$/); } }); @@ -118,3 +122,4 @@ Tinytest.add("logging - format", function (test) { level.charAt(0).toUpperCase() + '20120908-07:06:05.004 (app.js:42) message'); }); }); +