what is the replacement of JS_SetErrorReporter in spidermonkey 60

I want to report errors from js engine to c++ code side.
0
msami
4/10/2019 7:36:45 PM
mozilla.dev.tech.js-engine 2034 articles. 0 followers. Post Follow

3 Replies
50 Views

Similar Articles

[PageSpeed] 59

Well it's replaced by JS::SetWarningReporter.

That will report warnings.

You also probably want to catch exceptions that abort script evaluation, 
which you do by code kind of like this, if JS_ExecuteScript returns 
false, call this guy to report errors.

void ReportJSException(JSContext *context) {
     if(JS_IsExceptionPending(context)) {
         JS::RootedValue exception(context);
         if(JS_GetPendingException(context,&exception) && 
exception.isObject()) {
             JS::AutoSaveExceptionState savedExc(context);
             JS::Rooted<JSObject*> exceptionObject(context,
&exception.toObject());
             JSErrorReport *what =
                 JS_ErrorFromException(context,exceptionObject);
             if(what) {
                 std::cerr << "compilation exception: " << what->message;
                 std::cerr << ": file: " << what->filename;
                 std::cerr << ", line: " << (int) what->lineno << "\n";
             }
         }
         JS_ClearPendingException(context);
     }
}

On 4/10/19 2:36 PM, msami wrote:
> I want to report errors from js engine to c++ code side.
> _______________________________________________
> dev-tech-js-engine mailing list
> dev-tech-js-engine@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
0
Kent
4/10/2019 7:54:48 PM
On 4/10/19 3:36 PM, msami wrote:
> I want to report errors from js engine to c++ code side.

The idea in the new setup is that whatever code is doing the entrypoint 
into the JS engine should deal with the resulting exception, if any, 
instead of having some unrelated code called that should guess how to deal.

So your code should generally look like this, given a `JSContext* cx`:

   if (!JS::Call(....)) {
     if (!JS_IsExceptionPending(cx)) {
       // This is an "uncatchable exception" like a slow script
       // interrupt or worker termination.  Generally,
       // SpiderMonkey does not do this on its own; embeddings
       // have to trigger it explicitly.  Handle it however you
       // want.
     } else {
       // Use JS_GetPendingException, then JS_ClearPendingException, 
then report the exception however you want.
     }
   }

You can use js::ErrorReport and its init() method to generate a 
JSErrorReport and then do whatever with it.

-Boris
0
Boris
4/10/2019 8:06:35 PM
On Wednesday, April 10, 2019 at 9:36:47 PM UTC+2, msami wrote:
> I want to report errors from js engine to c++ code side.

Thanks guys very helpful stuff.
0
msami
4/11/2019 1:00:46 PM
Reply: