@sebastianwessel/quickjs
Version:
A typescript package to execute JavaScript and TypeScript code in a WebAssembly QuickJS sandbox
36 lines (35 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleEvalError = exports.normalizeInterruptedExecution = void 0;
const normalizeInterruptedExecution = (err, timeoutMs) => {
if (!(timeoutMs > 0 && err instanceof Error && err.message === 'interrupted')) {
return err;
}
const timeoutError = new Error('The script execution has exceeded the maximum allowed time limit.');
timeoutError.name = 'ExecutionTimeout';
timeoutError.stack = err.stack;
return timeoutError;
};
exports.normalizeInterruptedExecution = normalizeInterruptedExecution;
const handleEvalError = (err) => {
return err instanceof Error
? {
ok: false,
error: {
name: err.name,
message: err.message,
stack: err.stack,
},
isSyntaxError: err.name === 'SyntaxError',
}
: {
ok: false,
error: {
name: 'UnknownError',
message: typeof err === 'string' ? err : 'An unknown error occurred.',
stack: '',
},
isSyntaxError: false,
};
};
exports.handleEvalError = handleEvalError;