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.

2. JSErrorReport::linebuf() seems to always return null.

This is only set for syntax errors, I believe...

Am I doing something wrong?

No, the information you want simply isn't present.

-Boris

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

Reply via email to