Collect stack trace with Error.stack
Closed this issue · 6 comments
Throwable
uses .caller
to collect the stack trace. However, use of .caller
is explicitly prohibited in ES5 strict mode; thus, attempting to create a Throwable
in strict mode fails with a TypeError
. (This was the cause of eclipse-archived/ceylon-web-ide-backend#75.)
All modern engines also offer another way to get a stack trace: Error().stack
. This is, unfortunately, also unspecified, but available even in strict mode. Therefore, I think Throwable
should try to use that first, and only fall back to .caller
if Error().stack
isn’t available.
I think this is actually an issue for the language module. But anyway I've added some try-catches around the .caller
bits so strict mode will at least not cause any problems anymore.
Well, if an empty stacktrace isn’t a problem, sure :P
(And yeah, this probably belongs in ceylon.language, didn’t think about that. Sorry.)
I've wondered about this before. But this stack won't have any refs to Ceylon code, just the generated code (not like we show source locations anyway). I guess we could make Throwable
extend Error
, or maybe just use Error.stack
inside its constructor... or maybe the throwexc
function from the language module could use that.
or maybe just use
Error.stack
inside its constructor
yes, that’s what I meant – check Error().stack
(stack of new error) in the Throwable
constructor, where we currently walk .caller
.
Fixed by ceylon/ceylon.language@8a010e1
Thanks!