Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JS52 Compiler: JS::Compile returns false, but no errors reported by WarningReporter

24 views
Skip to first unread message

Kent Williams

unread,
Dec 20, 2017, 12:32:34 PM12/20/17
to dev-tech-...@lists.mozilla.org
Trying to do something rather complex (*cough* TypeScript *cough*) and
having trouble diagnosing the problem.  The compile fails but I'm not
getting any error messages via the handler I set using
JS::SetWarningReporter.

Is there something I'm missing here?

Boris Zbarsky

unread,
Dec 20, 2017, 1:22:25 PM12/20/17
to
JS::SetWarningReporter sets a thing to be used for warnings, not errors.

To handle errors, you should examine the pending exception on the
JSContext if a JSAPI call fails.

-Boris

Jason Orendorff

unread,
Dec 20, 2017, 2:34:22 PM12/20/17
to Boris Zbarsky, dev-tech-...@lists.mozilla.org
I discovered this week that there is no good public way to print an Error
in the JSAPI. This is not ideal.

The easiest workaround is to write your own try/catch block in JavaScript
and print the various parts of the Error object in the catch block.

That's not what the JS shell does, though. The shell takes advantage of
SpiderMonkey-internal APIs, including at least `js::PrintError()`. If you'd
like to wrap that behavior up into a nice, public
JS::PrintAndClearPendingException(cx, stderr) function, I'd take that
patch. It wouldn't be hard!

-j
> _______________________________________________
> dev-tech-js-engine mailing list
> dev-tech-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>

Kent Williams

unread,
Dec 20, 2017, 2:45:11 PM12/20/17
to dev-tech-...@lists.mozilla.org
Yeah, OK I found a good example of grabbing the exception error message.

https://dxr.mozilla.org/mozilla-central/source/dom/file/FileReader.cpp
0 new messages