Skip to content

Commit 46d42ca

Browse files
author
Yiyun Lei
committed
Merge branch 'main' of https://github.com/nodejs/node into node47707-migrate-message-tests-source-map
2 parents 187e031 + 5c9daf4 commit 46d42ca

File tree

70 files changed

+289
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+289
-219
lines changed

.github/workflows/test-internet.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ on:
77

88
pull_request:
99
types: [opened, synchronize, reopened, ready_for_review]
10-
paths: [test/internet/**]
10+
paths:
11+
- test/internet/**
12+
- internal/dns/**
13+
- lib/dns.js
14+
- lib/net.js
1115
push:
1216
branches:
1317
- main
1418
- canary
1519
- v[0-9]+.x-staging
1620
- v[0-9]+.x
17-
paths: [test/internet/**]
21+
paths:
22+
- test/internet/**
23+
- internal/dns/**
24+
- lib/dns.js
25+
- lib/net.js
1826

1927
concurrency:
2028
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

benchmark/esm/esm-loader-import.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// general startup, does not test lazy operations
33
'use strict';
44
const fs = require('node:fs');
5-
const path = require('node:path');
65
const common = require('../common.js');
76

87
const tmpdir = require('../../test/common/tmpdir.js');
9-
const { pathToFileURL } = require('node:url');
108

11-
const benchmarkDirectory = pathToFileURL(path.resolve(tmpdir.path, 'benchmark-import'));
9+
const benchmarkDirectory = tmpdir.fileURL('benchmark-import');
1210

1311
const configs = {
1412
n: [1e3],

doc/api/esm.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ behind the `--experimental-import-meta-resolve` flag:
376376
377377
* `parent` {string|URL} An optional absolute parent module URL to resolve from.
378378
379+
> **Caveat** This feature is not available within custom loaders (it would
380+
> create a deadlock).
381+
379382
## Interoperability with CommonJS
380383
381384
### `import` statements
@@ -1712,14 +1715,14 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
17121715
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
17131716
[`initialize`]: #initialize
17141717
[`module.createRequire()`]: module.md#modulecreaterequirefilename
1715-
[`module.register()`]: module.md#moduleregister
1718+
[`module.register()`]: module.md#moduleregisterspecifier-parenturl-options
17161719
[`module.syncBuiltinESMExports()`]: module.md#modulesyncbuiltinesmexports
17171720
[`package.json`]: packages.md#nodejs-packagejson-field-definitions
17181721
[`port.postMessage`]: worker_threads.md#portpostmessagevalue-transferlist
17191722
[`port.ref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portref
17201723
[`port.unref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portunref
17211724
[`process.dlopen`]: process.md#processdlopenmodule-filename-flags
1722-
[`register`]: module.md#moduleregister
1725+
[`register`]: module.md#moduleregisterspecifier-parenturl-options
17231726
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
17241727
[`util.TextDecoder`]: util.md#class-utiltextdecoder
17251728
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2

doc/api/module.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,29 @@ isBuiltin('fs'); // true
8080
isBuiltin('wss'); // false
8181
```
8282
83-
### `module.register()`
83+
### `module.register(specifier[, parentURL][, options])`
8484
8585
<!-- YAML
8686
added: REPLACEME
8787
-->
8888
89-
In addition to using the `--experimental-loader` option in the CLI,
90-
loaders can be registered programmatically using the
91-
`module.register()` method.
89+
> Stability: 1.1 - Active development
90+
91+
* `specifier` {string} Customization hooks to be registered; this should be the
92+
same string that would be passed to `import()`, except that if it is relative,
93+
it is resolved relative to `parentURL`.
94+
* `parentURL` {string} If you want to resolve `specifier` relative to a base
95+
URL, such as `import.meta.url`, you can pass that URL here. **Default:**
96+
`'data:'`
97+
* `options` {Object}
98+
* `data` {any} Any arbitrary, cloneable JavaScript value to pass into the
99+
[`initialize`][] hook.
100+
* `transferList` {Object\[]} [transferrable objects][] to be passed into the
101+
`initialize` hook.
102+
* Returns: {any} returns whatever was returned by the `initialize` hook.
103+
104+
Register a module that exports hooks that customize Node.js module resolution
105+
and loading behavior.
92106
93107
```mjs
94108
import { register } from 'node:module';
@@ -390,3 +404,4 @@ returned object contains the following keys:
390404
[`module`]: modules.md#the-module-object
391405
[module wrapper]: modules.md#the-module-wrapper
392406
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
407+
[transferrable objects]: worker_threads.md#portpostmessagevalue-transferlist

doc/api/n-api.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,13 +3070,18 @@ napi_status napi_get_buffer_info(napi_env env,
30703070
```
30713071

30723072
* `[in] env`: The environment that the API is invoked under.
3073-
* `[in] value`: `napi_value` representing the `node::Buffer` being queried.
3074-
* `[out] data`: The underlying data buffer of the `node::Buffer`.
3075-
If length is `0`, this may be `NULL` or any other pointer value.
3073+
* `[in] value`: `napi_value` representing the `node::Buffer` or `Uint8Array`
3074+
being queried.
3075+
* `[out] data`: The underlying data buffer of the `node::Buffer` or
3076+
`Uint8Array`. If length is `0`, this may be `NULL` or any other pointer value.
30763077
* `[out] length`: Length in bytes of the underlying data buffer.
30773078

30783079
Returns `napi_ok` if the API succeeded.
30793080

3081+
This method returns the identical `data` and `byte_length` as
3082+
[`napi_get_typedarray_info`][]. And `napi_get_typedarray_info` accepts a
3083+
`node::Buffer` (a Uint8Array) as the value too.
3084+
30803085
This API is used to retrieve the underlying data buffer of a `node::Buffer`
30813086
and its length.
30823087

@@ -3827,12 +3832,14 @@ napi_status napi_is_buffer(napi_env env, napi_value value, bool* result)
38273832

38283833
* `[in] env`: The environment that the API is invoked under.
38293834
* `[in] value`: The JavaScript value to check.
3830-
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer`
3831-
object.
3835+
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer` or
3836+
`Uint8Array` object.
38323837

38333838
Returns `napi_ok` if the API succeeded.
38343839

3835-
This API checks if the `Object` passed in is a buffer.
3840+
This API checks if the `Object` passed in is a buffer or Uint8Array.
3841+
[`napi_is_typedarray`][] should be preferred if the caller needs to check if the
3842+
value is a Uint8Array.
38363843

38373844
### `napi_is_date`
38383845

@@ -6502,11 +6509,13 @@ the add-on's file name during loading.
65026509
[`napi_get_last_error_info`]: #napi_get_last_error_info
65036510
[`napi_get_property`]: #napi_get_property
65046511
[`napi_get_reference_value`]: #napi_get_reference_value
6512+
[`napi_get_typedarray_info`]: #napi_get_typedarray_info
65056513
[`napi_get_value_external`]: #napi_get_value_external
65066514
[`napi_has_property`]: #napi_has_property
65076515
[`napi_instanceof`]: #napi_instanceof
65086516
[`napi_is_error`]: #napi_is_error
65096517
[`napi_is_exception_pending`]: #napi_is_exception_pending
6518+
[`napi_is_typedarray`]: #napi_is_typedarray
65106519
[`napi_make_callback`]: #napi_make_callback
65116520
[`napi_open_callback_scope`]: #napi_open_callback_scope
65126521
[`napi_open_escapable_handle_scope`]: #napi_open_escapable_handle_scope

doc/api/webstreams.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,13 +1219,13 @@ changes:
12191219
description: This class is now exposed on the global object.
12201220
-->
12211221
1222-
#### `new ByteLengthQueuingStrategy(options)`
1222+
#### `new ByteLengthQueuingStrategy(init)`
12231223
12241224
<!-- YAML
12251225
added: v16.5.0
12261226
-->
12271227
1228-
* `options` {Object}
1228+
* `init` {Object}
12291229
* `highWaterMark` {number}
12301230
12311231
#### `byteLengthQueuingStrategy.highWaterMark`
@@ -1256,13 +1256,13 @@ changes:
12561256
description: This class is now exposed on the global object.
12571257
-->
12581258
1259-
#### `new CountQueuingStrategy(options)`
1259+
#### `new CountQueuingStrategy(init)`
12601260
12611261
<!-- YAML
12621262
added: v16.5.0
12631263
-->
12641264
1265-
* `options` {Object}
1265+
* `init` {Object}
12661266
* `highWaterMark` {number}
12671267
12681268
#### `countQueuingStrategy.highWaterMark`

lib/internal/crypto/util.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ const {
7575
const kHandle = Symbol('kHandle');
7676
const kKeyObject = Symbol('kKeyObject');
7777

78-
// TODO(tniessen): remove all call sites and this function
79-
function getDefaultEncoding() {
80-
return 'buffer';
81-
}
82-
8378
// This is here because many functions accepted binary strings without
8479
// any explicit encoding in older versions of node, and we don't want
8580
// to break them unnecessarily.
@@ -555,7 +550,6 @@ module.exports = {
555550
getCiphers,
556551
getCurves,
557552
getDataViewOrTypedArrayBuffer,
558-
getDefaultEncoding,
559553
getHashes,
560554
kHandle,
561555
kKeyObject,

lib/internal/modules/esm/load.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,30 @@ async function getSource(url, context) {
7070
return { __proto__: null, responseURL, source };
7171
}
7272

73+
/**
74+
* @param {URL} url URL to the module
75+
* @param {ESModuleContext} context used to decorate error messages
76+
* @returns {{ responseURL: string, source: string | BufferView }}
77+
*/
7378
function getSourceSync(url, context) {
74-
const parsed = new URL(url);
75-
const responseURL = url;
79+
const { protocol, href } = url;
80+
const responseURL = href;
7681
let source;
77-
if (parsed.protocol === 'file:') {
78-
source = readFileSync(parsed);
79-
} else if (parsed.protocol === 'data:') {
80-
const match = RegExpPrototypeExec(DATA_URL_PATTERN, parsed.pathname);
82+
if (protocol === 'file:') {
83+
source = readFileSync(url);
84+
} else if (protocol === 'data:') {
85+
const match = RegExpPrototypeExec(DATA_URL_PATTERN, url.pathname);
8186
if (!match) {
82-
throw new ERR_INVALID_URL(url);
87+
throw new ERR_INVALID_URL(responseURL);
8388
}
8489
const { 1: base64, 2: body } = match;
8590
source = BufferFrom(decodeURIComponent(body), base64 ? 'base64' : 'utf8');
8691
} else {
8792
const supportedSchemes = ['file', 'data'];
88-
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, supportedSchemes);
93+
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supportedSchemes);
8994
}
9095
if (policy?.manifest) {
91-
policy.manifest.assertIntegrity(parsed, source);
96+
policy.manifest.assertIntegrity(url, source);
9297
}
9398
return { __proto__: null, responseURL, source };
9499
}
@@ -159,14 +164,18 @@ function defaultLoadSync(url, context = kEmptyObject) {
159164
source,
160165
} = context;
161166

162-
format ??= defaultGetFormat(new URL(url), context);
167+
const urlInstance = new URL(url);
168+
169+
throwIfUnsupportedURLScheme(urlInstance, false);
170+
171+
format ??= defaultGetFormat(urlInstance, context);
163172

164173
validateAssertions(url, format, importAssertions);
165174

166175
if (format === 'builtin') {
167176
source = null;
168177
} else if (source == null) {
169-
({ responseURL, source } = getSourceSync(url, context));
178+
({ responseURL, source } = getSourceSync(urlInstance, context));
170179
}
171180

172181
return {

lib/internal/streams/lazy_transform.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ const {
1111

1212
const stream = require('stream');
1313

14-
const {
15-
getDefaultEncoding,
16-
} = require('internal/crypto/util');
17-
1814
module.exports = LazyTransform;
1915

2016
function LazyTransform(options) {
@@ -29,7 +25,7 @@ function makeGetter(name) {
2925
this._writableState.decodeStrings = false;
3026

3127
if (!this._options || !this._options.defaultEncoding) {
32-
this._writableState.defaultEncoding = getDefaultEncoding();
28+
this._writableState.defaultEncoding = 'buffer'; // TODO(tniessen): remove
3329
}
3430

3531
return this[name];

lib/internal/webstreams/queuingstrategies.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ByteLengthQueuingStrategy {
6969
constructor(init) {
7070
validateObject(init, 'init');
7171
if (init.highWaterMark === undefined)
72-
throw new ERR_MISSING_OPTION('options.highWaterMark');
72+
throw new ERR_MISSING_OPTION('init.highWaterMark');
7373

7474
// The highWaterMark value is not checked until the strategy
7575
// is actually used, per the spec.
@@ -121,7 +121,7 @@ class CountQueuingStrategy {
121121
constructor(init) {
122122
validateObject(init, 'init');
123123
if (init.highWaterMark === undefined)
124-
throw new ERR_MISSING_OPTION('options.highWaterMark');
124+
throw new ERR_MISSING_OPTION('init.highWaterMark');
125125

126126
// The highWaterMark value is not checked until the strategy
127127
// is actually used, per the spec.

0 commit comments

Comments
 (0)