Skip to content
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
26 changes: 26 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2827,6 +2827,28 @@ Type: Documentation-only (supports [`--pending-deprecation`][])
The remapping of specifiers ending in `"/"` like `import 'pkg/x/'` is deprecated
for package `"exports"` and `"imports"` pattern resolutions.

### DEP0156: `.aborted` property and `'abort'`, `'aborted'` event in `http`
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/36670
description: Documentation-only deprecation.
-->

Type: Documentation-only

Move to {Stream} API instead, as the [`http.ClientRequest`][],
[`http.ServerResponse`][], and [`http.IncomingMessage`][] are all stream-based.
Check `stream.destroyed` instead of the `.aborted` property, and listen for
`'close'` instead of `'abort'`, `'aborted'` event.

The `.aborted` property and `'abort'` event are only useful for detecting
`.abort()` calls. For closing a request early, use the Stream
`.destroy([error])` then check the `.destroyed` property and `'close'` event
should have the same effect. The receiving end should also check the
[`readable.readableEnded`][] value on [`http.IncomingMessage`][] to get whether
it was an aborted or graceful destroy.

[Legacy URL API]: url.md#url_legacy_url_api
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
Expand Down Expand Up @@ -2884,6 +2906,9 @@ for package `"exports"` and `"imports"` pattern resolutions.
[`fs.read()`]: fs.md#fs_fs_read_fd_buffer_offset_length_position_callback
[`fs.readSync()`]: fs.md#fs_fs_readsync_fd_buffer_offset_length_position
[`fs.stat()`]: fs.md#fs_fs_stat_path_options_callback
[`http.ClientRequest`]: #http_class_http_clientrequest
[`http.IncomingMessage`]: #http_class_http_incomingmessage
[`http.ServerResponse`]: #http_class_http_serverresponse
[`http.get()`]: http.md#http_http_get_options_callback
[`http.request()`]: http.md#http_http_request_options_callback
[`https.get()`]: https.md#https_https_get_options_callback
Expand All @@ -2896,6 +2921,7 @@ for package `"exports"` and `"imports"` pattern resolutions.
[`process.env`]: process.md#process_process_env
[`process.mainModule`]: process.md#process_process_mainmodule
[`punycode`]: punycode.md
[`readable.readableEnded`]: stream.md#stream_readable_readableended
[`request.abort()`]: http.md#http_request_abort
[`request.connection`]: http.md#http_request_connection
[`request.destroy()`]: http.md#http_request_destroy_error
Expand Down
57 changes: 36 additions & 21 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,13 @@ a URL should be interpreted. The `format` returned also affects what the
acceptable forms of source values are for a module when parsing. This can be one
of the following:

| `format` | Description | Acceptable Types For `source` Returned by `getSource` or `transformSource` |
| ------------ | ------------------------------ | -------------------------------------------------------------------------- |
| `'builtin'` | Load a Node.js builtin module | Not applicable |
| `'commonjs'` | Load a Node.js CommonJS module | Not applicable |
| `'json'` | Load a JSON file | { [`string`][], [`ArrayBuffer`][], [`TypedArray`][] } |
| `'module'` | Load an ES module | { [`string`][], [`ArrayBuffer`][], [`TypedArray`][] } |
| `'wasm'` | Load a WebAssembly module | { [`ArrayBuffer`][], [`TypedArray`][] } |
| `format` | Description | Acceptable types for `source` returned by `load` |
| ------------ | ------------------------------ | ----------------------------------------------------- |
| `'builtin'` | Load a Node.js builtin module | Not applicable |
| `'commonjs'` | Load a Node.js CommonJS module | Not applicable |
| `'json'` | Load a JSON file | { [`string`][], [`ArrayBuffer`][], [`TypedArray`][] } |
| `'module'` | Load an ES module | { [`string`][], [`ArrayBuffer`][], [`TypedArray`][] } |
| `'wasm'` | Load a WebAssembly module | { [`ArrayBuffer`][], [`TypedArray`][] } |

Note: These types all correspond to classes defined in ECMAScript.

Expand Down Expand Up @@ -960,17 +960,33 @@ export function getFormat(url, context, defaultGetFormat) {
return defaultGetFormat(url, context, defaultGetFormat);
}

export function transformSource(source, context, defaultTransformSource) {
const { url, format } = context;

if (extensionsRegex.test(url)) {
return {
source: CoffeeScript.compile(source, { bare: true })
};
}

// Let Node.js handle all other sources.
return defaultTransformSource(source, context, defaultTransformSource);
async function getPackageType(url) {
// `url` is only a file path during the first iteration when passed the
// resolved url from the load() hook
// an actual file path from load() will contain a file extension as it's
// required by the spec
// this simple truthy check for whether `url` contains a file extension will
// work for most projects but does not cover some edge-cases (such as
// extension-less files or a url ending in a trailing space)
const isFilePath = !!extname(url);
// If it is a file path, get the directory it's in
const dir = isFilePath ?
dirname(fileURLToPath(url)) :
url;
// Compose a file path to a package.json in the same directory,
// which may or may not exist
const packagePath = resolvePath(dir, 'package.json');
// Try to read the possibly nonexistent package.json
const type = await readFile(packagePath, { encoding: 'utf8' })
.then((filestring) => JSON.parse(filestring).type)
.catch((err) => {
if (err?.code !== 'ENOENT') console.error(err);
});
// Ff package.json existed and contained a `type` field with a value, voila
if (type) return type;
// Otherwise, (if not at the root) continue checking the next directory up
// If at the root, stop and return false
return dir.length > 1 && getPackageType(resolvePath(dir, '..'));
}
```

Expand Down Expand Up @@ -1127,9 +1143,8 @@ The resolver can throw the following errors:
> **undefined**, then
> 1. Return **undefined**.
> 1. If _pjson.name_ is equal to _packageName_, then
> 1. Return the _resolved_ destructured value of the result of
> **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_, _pjson.exports_,
> _defaultConditions_).
> 1. Return the result of **PACKAGE_EXPORTS_RESOLVE**(_packageURL_,
> _packageSubpath_, _pjson.exports_, _defaultConditions_).
> 1. Otherwise, return **undefined**.

**PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_, _exports_, _conditions_)
Expand Down
15 changes: 14 additions & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,11 @@ body which has been transmitted are equal or not.
### Event: `'abort'`
<!-- YAML
added: v1.4.1
deprecated: REPLACEME
-->

> Stability: 0 - Deprecated. Listen for the `'close'` event instead.

Emitted when the request has been aborted by the client. This event is only
emitted on the first call to `abort()`.

Expand Down Expand Up @@ -562,7 +565,7 @@ added: v0.7.8
-->

Emitted when the underlying socket times out from inactivity. This only notifies
that the socket has been idle. The request must be aborted manually.
that the socket has been idle. The request must be destroyed manually.

See also: [`request.setTimeout()`][].

Expand Down Expand Up @@ -643,12 +646,15 @@ in the response to be dropped and the socket to be destroyed.
### `request.aborted`
<!-- YAML
added: v0.11.14
deprecated: REPLACEME
changes:
- version: v11.0.0
pr-url: https://github.com/nodejs/node/pull/20230
description: The `aborted` property is no longer a timestamp number.
-->

> Stability: 0 - Deprecated. Check [`request.destroyed`][] instead.

* {boolean}

The `request.aborted` property will be `true` if the request has
Expand Down Expand Up @@ -1984,8 +1990,11 @@ may be reused multiple times in case of keep-alive.
### Event: `'aborted'`
<!-- YAML
added: v0.3.8
deprecated: REPLACEME
-->

> Stability: 0 - Deprecated. Listen for `'close'` event instead.

Emitted when the request has been aborted.

### Event: `'close'`
Expand All @@ -1998,8 +2007,11 @@ Indicates that the underlying connection was closed.
### `message.aborted`
<!-- YAML
added: v10.1.0
deprecated: REPLACEME
-->

> Stability: 0 - Deprecated. Check `message.destroyed` from {stream.Readable}.

* {boolean}

The `message.aborted` property will be `true` if the request has
Expand Down Expand Up @@ -3231,6 +3243,7 @@ try {
[`outgoingMessage.socket`]: #http_outgoingmessage_socket
[`removeHeader(name)`]: #http_request_removeheader_name
[`request.destroy()`]: #http_request_destroy_error
[`request.destroyed`]: #http_request_destroyed
[`request.end()`]: #http_request_end_data_encoding_callback
[`request.flushHeaders()`]: #http_request_flushheaders
[`request.getHeader()`]: #http_request_getheader_name
Expand Down
21 changes: 21 additions & 0 deletions lib/internal/structured_clone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const {
MessageChannel,
receiveMessageOnPort,
} = require('internal/worker/io');

let channel;
function structuredClone(value, options = undefined) {
// TODO: Improve this with a more efficient solution that avoids
// instantiating a MessageChannel
channel ??= new MessageChannel();
channel.port1.unref();
channel.port2.unref();
channel.port1.postMessage(value, options?.transfer);
return receiveMessageOnPort(channel.port2).message;
}

module.exports = {
structuredClone
};
7 changes: 0 additions & 7 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,6 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
return 12;
}

// TODO(mylesborins): remove this when the harmony-top-level-await flag
// is removed in V8
if (std::find(v8_args.begin(), v8_args.end(),
"--no-harmony-top-level-await") == v8_args.end()) {
v8_args.push_back("--harmony-top-level-await");
}

auto env_opts = per_process::cli_options->per_isolate->per_env;
if (std::find(v8_args.begin(), v8_args.end(),
"--abort-on-uncaught-exception") != v8_args.end() ||
Expand Down
4 changes: 0 additions & 4 deletions test/message/esm_display_syntax_error.mjs

This file was deleted.

8 changes: 0 additions & 8 deletions test/parallel/test-no-harmony-top-level-await.mjs

This file was deleted.

1 change: 0 additions & 1 deletion tools/code_cache/mkcodecache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ int main(int argc, char* argv[]) {
#endif // _WIN32

v8::V8::SetFlagsFromString("--random_seed=42");
v8::V8::SetFlagsFromString("--harmony-top-level-await");

if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <path/to/output.cc>\n";
Expand Down