worker: unify custom error creation
Mostly, this introduces a pattern that makes sure that if a custom
error is reported, stopped_
will be set to true
correctly in
every cast, which was previously missing for the
NewContext().IsEmpty()
case (which led to a hard crash from the
Worker
destructor).
This also leaves TODO comments for a few cases in which
ERR_WORKER_OUT_OF_MEMORY
was not used in accordance with the
documentation for that error code (or according to its intention).
Fixing that is semver-major.
(Testing this is hard without https://github.com/nodejs/node/pull/33085 which contains a feature that enables testing this.)
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines