You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{ ObjectInfo, WeakTag }=require("@mhofman/weak-napi-native");constmap=newWeakMap();asyncfunctiontest(call){letlistener;constthrown=newPromise(resolve=>{listener=error=>voidresolve(error);process.on("uncaughtException",listener);});letobject={};constinfo=newObjectInfo(object,()=>{call(()=>{thrownewError("I should be able to get this in uncaughtException");});});map.set(object,newWeakTag(info));object=undefined;awaitPromise.resolve(resolve=>setImmediate(resolve));gc();constresult=awaitPromise.race([thrown,newPromise(resolve=>setTimeout(resolve,200,"Bailing")),]);process.removeListener("uncaughtException",listener);returnresult;}(async()=>{console.log("setImmediate start");console.log("setImmediate",awaittest(fn=>{console.log("setImmediate callback invoked");setImmediate(fn);}));console.log("direct start");console.log("direct",awaittest(fn=>{console.log("direct callback invoked");fn();}));try{constinfo=newObjectInfo({},()=>{});}catch(error){console.log("Caught error on construct",error);}console.log("done");process.exit();})();
Output:
setImmediate start
setImmediate callback invoked
setImmediate Error: I should be able to get this in uncaughtException
direct start
direct callback invoked
direct Bailing
Caught error on construct Error: I should be able to get this in uncaughtException
done
The text was updated successfully, but these errors were encountered:
mhofman
added a commit
to mhofman/tc39-weakrefs-shim
that referenced
this issue
May 10, 2019
It looks like errors thrown by
ObjectInfo
's callback cannot be caught in process'"uncaughtException"
event.What's even more surprising is that the error is subsequently thrown the next time an
ObjectInfo
is constructed.The workaround is to wrap the callback into a
setImmediate
call, but that shouldn't be necessary since the native side already does that.I have a feeling this is an issue for https://github.com/node-ffi-napi/setimmediate-napi
From a quick research I guess calling
napi_fatal_exception
instead ofe.ThrowAsJavaScriptException()
would do the trick, but I'm probably out of my depth here.Repro:
Output:
The text was updated successfully, but these errors were encountered: