fix: add Error constructors to NodeVM context for jsonwebtoken tests (#6209)

When jsonwebtoken throws errors inside the NodeVM context, those errors
were instances of the VM's isolated Error class, which caused
instanceOf(Error) checks in tests to fail.

By adding Error constructors (Error, TypeError, ReferenceError,
SyntaxError, RangeError) from the global scope to the scriptContext,
errors thrown by jsonwebtoken and other modules now use the same Error
class that tests check against, ensuring instanceOf checks pass correctly.

This fixes jsonwebtoken test failures when using the NodeVM runtime.
This commit is contained in:
Chirag Chandrashekhar
2025-11-26 17:57:11 +05:30
committed by GitHub
parent b0405b1e1a
commit 7ed474c8ba

View File

@@ -58,7 +58,12 @@ async function runScriptInNodeVm({
clearTimeout: global.clearTimeout,
clearInterval: global.clearInterval,
setImmediate: global.setImmediate,
clearImmediate: global.clearImmediate
clearImmediate: global.clearImmediate,
Error: global.Error,
TypeError: global.TypeError,
ReferenceError: global.ReferenceError,
SyntaxError: global.SyntaxError,
RangeError: global.RangeError
};
mixinTypedArrays(scriptContext);