-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: handle Top-Level Await non-fulfills better
Handle situations in which the main `Promise` from a TLA module is not fulfilled better: - When not resolving the `Promise` at all, set a non-zero exit code (unless another one has been requested explicitly) to distinguish the result from a successful completion. - When rejecting the `Promise`, always treat it like an uncaught exception. In particular, this also ensures a non-zero exit code. Refs: #34558 PR-URL: #34640 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
- Loading branch information
Showing
8 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import '../common/index.mjs'; | ||
import assert from 'assert'; | ||
import child_process from 'child_process'; | ||
import fixtures from '../common/fixtures.js'; | ||
|
||
{ | ||
// Unresolved TLA promise, --eval | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
['--input-type=module', '--eval', 'await new Promise(() => {})'], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout, stderr], [13, '', '']); | ||
} | ||
|
||
{ | ||
// Rejected TLA promise, --eval | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
['--input-type=module', '-e', 'await Promise.reject(new Error("Xyz"))'], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout], [1, '']); | ||
assert.match(stderr, /Error: Xyz/); | ||
} | ||
|
||
{ | ||
// Unresolved TLA promise with explicit exit code, --eval | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
['--input-type=module', '--eval', | ||
'process.exitCode = 42;await new Promise(() => {})'], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout, stderr], [42, '', '']); | ||
} | ||
|
||
{ | ||
// Rejected TLA promise with explicit exit code, --eval | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
['--input-type=module', '-e', | ||
'process.exitCode = 42;await Promise.reject(new Error("Xyz"))'], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout], [1, '']); | ||
assert.match(stderr, /Error: Xyz/); | ||
} | ||
|
||
{ | ||
// Unresolved TLA promise, module file | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
[fixtures.path('es-modules/tla/unresolved.mjs')], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout, stderr], [13, '', '']); | ||
} | ||
|
||
{ | ||
// Rejected TLA promise, module file | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
[fixtures.path('es-modules/tla/rejected.mjs')], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout], [1, '']); | ||
assert.match(stderr, /Error: Xyz/); | ||
} | ||
|
||
{ | ||
// Unresolved TLA promise, module file | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
[fixtures.path('es-modules/tla/unresolved-withexitcode.mjs')], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout, stderr], [42, '', '']); | ||
} | ||
|
||
{ | ||
// Rejected TLA promise, module file | ||
const { status, stdout, stderr } = child_process.spawnSync( | ||
process.execPath, | ||
[fixtures.path('es-modules/tla/rejected-withexitcode.mjs')], | ||
{ encoding: 'utf8' }); | ||
assert.deepStrictEqual([status, stdout], [1, '']); | ||
assert.match(stderr, /Error: Xyz/); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
process.exitCode = 42; | ||
await Promise.reject(new Error('Xyz')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await Promise.reject(new Error('Xyz')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
process.exitCode = 42; | ||
await new Promise(() => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
await new Promise(() => {}); |