不要怂,就是干,撸起袖子干!

Commit 1a82d8ed by Brian Lauber

Bug fix: call stack is computed properly now (#3016)

Adjust the stack function to the it references itself more directly (rather than using this.stack)

Added a unit test for Util.stack()
1 parent 01d86c28
Showing with 29 additions and 2 deletions
......@@ -294,11 +294,11 @@ var Utils = module.exports = {
},
stack: function() {
stack: function _stackGrabber() {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack) { return stack; };
var err = new Error();
Error.captureStackTrace(err, this);
Error.captureStackTrace(err, _stackGrabber);
var errStack = err.stack;
Error.prepareStackTrace = orig;
return errStack;
......
......@@ -114,4 +114,30 @@ suite(Support.getTestDialectTeaser('Utils'), function() {
});
});
});
suite('stack', function() {
test('stack trace starts after call to Util.stack()', function this_here_test() {
function a() {
return b();
}
function b() {
return c();
}
function c() {
return Utils.stack();
}
var stack = a();
expect(stack[0].getFunctionName()).to.eql('c');
expect(stack[1].getFunctionName()).to.eql('b');
expect(stack[2].getFunctionName()).to.eql('a');
expect(stack[3].getFunctionName()).to.eql('this_here_test');
});
});
});
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!