On 2016-05-04 12:02 PM, Boris Zbarsky wrote:
> On 5/4/16 11:40 AM, Ehsan Akhgari wrote:
>> 1. If the JS code throws an ErrorObject (such as |throw new
>> Error("foo");|)
>> I get the line and column info as expected, but if it throws something
>> else
>> (such as |throw new "foo";|) then the line and column number seem to
>> always
>> be 0.
> 
> That's because we don't store the line and column out-of-band.
> 
> That is, an Error object has a line (and maybe column; I dunno what the
> state of columns is) that it captures when it's _constructed_.  Note
> that this may NOT be when it's thrown.  A testcase:
> 
> <script>
>   var error = new Error();
>   /*
>   filler
>   filler
>   filler
>   */
>   throw error;
> </script>
> <script>
>   throw 5;
> </script>
> 
> In Firefox this shows an exception at line 2 for the Error and an
> exception at an unknown location for the 5.  In Chrome it shows line 2
> for the Error and line 11 for the 5 (in the devtools).  error.stack also
> shows "2" in both browsers.
> 
> (For comparison, error.stack shows "2" in Safari, but the devtools show
> the throw location, afaict).
> 
> Anyway, the upshot is that when throwing the only thing one does in
> SpiderMonkey is put an exception JS::Value on the JSContext, and that
> doesn't have intrinsic line/number information unless it's some object
> that stores it internally somewhere.

Thanks for the explanation!

Out of curiosity, is there any reason why this information is not
captured?  For example, couldn't we remember the current stack trace in
JSContext::setPendingException() on the JSContext alongside
unwrappedException_, so that we can both have a precise stack trace of
the throwing location and also access to the line and column info
through the first frame of the stack trace?

Cheers,
Ehsan
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals

Reply via email to