Test logging from evaled string.

This commit is contained in:
Slava Kim
2013-05-31 16:21:57 -07:00
parent 7d4ee2209e
commit 51db0d2646
2 changed files with 8 additions and 4 deletions

View File

@@ -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];

View File

@@ -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');
});
});