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

Jason Orendorff <[email protected]> Wed, 20 Dec 2017 13:34:10 -0600
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <CA+W3DWE7MMozH0k3VYFwc8Rp6cNVXq0Ho+FBbYhdizeiBuZK0A@mail.gmail.com>
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



On Wed, Dec 20, 2017 at 12:22 PM, Boris Zbarsky <[email protected]> wrote:

> On 12/20/17 12:31 PM, Kent Williams wrote:
>
>> 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?
>>
>
> 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
>
>
> _______________________________________________
> dev-tech-js-engine mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>