mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 06:08:50 +02:00

Previously the implemention of require(esm) only converted the rejected promise from module evaluation into an error, but the rejected promise was still treated as a pending unhandled rejection by the promise rejection callback, because the promise is created by V8 internals and we don't get a chance to mark it as handled, so the rejection incorrectly marked as unhandled would still go through unhandled rejection handling (if no global listener is set, the default handling would print a warning and make the Node.js instance exit with 1). This patch fixes it by calling into the JS promise rejection callback to mark the evalaution rejection handled so that it doesn't go through unhandled rejection handling. PR-URL: https://github.com/nodejs/node/pull/56122 Fixes: https://github.com/nodejs/node/issues/56115 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
21 lines
498 B
JavaScript
21 lines
498 B
JavaScript
// This tests synchronous errors in ESM from require(esm) can be caught.
|
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
// Runtime errors from throw should be caught.
|
|
assert.throws(() => {
|
|
require('../fixtures/es-modules/runtime-error-esm.js');
|
|
}, {
|
|
message: 'hello'
|
|
});
|
|
|
|
// References errors should be caught too.
|
|
assert.throws(() => {
|
|
require('../fixtures/es-modules/reference-error-esm.js');
|
|
}, {
|
|
name: 'ReferenceError',
|
|
message: 'exports is not defined'
|
|
});
|