Skip to content

module: fix e.stack error when throwing undefined or null #19282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class ModuleJob {
try {
module.evaluate();
} catch (e) {
e.stack;
this.hadError = true;
this.error = e;
throw e;
Expand Down
16 changes: 16 additions & 0 deletions test/es-module/test-esm-throw-undefined.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Flags: --experimental-modules
/* eslint-disable node-core/required-modules */
import common from '../common/index.js';
import assert from 'assert';

Copy link
Member

@TimothyGu TimothyGu Mar 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a common.crashOnUnhandledRejection(); line here, and remove the .then(common.mustCall()) later.

Copy link
Contributor Author

@zhanzhenzhen zhanzhenzhen Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu Thank you. As this is the first time I make a pull request I'm not very familiar with the these functions. You can add it later :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu I added.

async function doTest() {
await assert.rejects(
async () => {
await import('../fixtures/es-module-loaders/throw-undefined');
},
(e) => e === undefined
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

await assert.rejects(
  import('../fixtures/es-module-loaders/throw-undefined'),
  (e) => e === undefined);

The extra arrow function doesn't seem needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed the example here:
https://github.com/nodejs/node/blob/master/doc/api/assert.md

You mean, the first parameter can be a promise (not a function)? I don't know, but I think mine is more formal :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oops, never mind that.

}

common.crashOnUnhandledRejection();
doTest();
3 changes: 3 additions & 0 deletions test/fixtures/es-module-loaders/throw-undefined.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

throw undefined;