Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/nodejs/node into node47707-…
Browse files Browse the repository at this point in the history
…migrate-message-tests-source-map
  • Loading branch information
Yiyun Lei committed Aug 22, 2023
2 parents 187e031 + 5c9daf4 commit 46d42ca
Show file tree
Hide file tree
Showing 70 changed files with 289 additions and 219 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/test-internet.yml
Expand Up @@ -7,14 +7,22 @@ on:

pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths: [test/internet/**]
paths:
- test/internet/**
- internal/dns/**
- lib/dns.js
- lib/net.js
push:
branches:
- main
- canary
- v[0-9]+.x-staging
- v[0-9]+.x
paths: [test/internet/**]
paths:
- test/internet/**
- internal/dns/**
- lib/dns.js
- lib/net.js

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
4 changes: 1 addition & 3 deletions benchmark/esm/esm-loader-import.js
Expand Up @@ -2,13 +2,11 @@
// general startup, does not test lazy operations
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const common = require('../common.js');

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

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

const configs = {
n: [1e3],
Expand Down
7 changes: 5 additions & 2 deletions doc/api/esm.md
Expand Up @@ -376,6 +376,9 @@ behind the `--experimental-import-meta-resolve` flag:
* `parent` {string|URL} An optional absolute parent module URL to resolve from.
> **Caveat** This feature is not available within custom loaders (it would
> create a deadlock).
## Interoperability with CommonJS
### `import` statements
Expand Down Expand Up @@ -1712,14 +1715,14 @@ for ESM specifiers is [commonjs-extension-resolution-loader][].
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
[`initialize`]: #initialize
[`module.createRequire()`]: module.md#modulecreaterequirefilename
[`module.register()`]: module.md#moduleregister
[`module.register()`]: module.md#moduleregisterspecifier-parenturl-options
[`module.syncBuiltinESMExports()`]: module.md#modulesyncbuiltinesmexports
[`package.json`]: packages.md#nodejs-packagejson-field-definitions
[`port.postMessage`]: worker_threads.md#portpostmessagevalue-transferlist
[`port.ref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portref
[`port.unref()`]: https://nodejs.org/dist/latest-v17.x/docs/api/worker_threads.html#portunref
[`process.dlopen`]: process.md#processdlopenmodule-filename-flags
[`register`]: module.md#moduleregister
[`register`]: module.md#moduleregisterspecifier-parenturl-options
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
[`util.TextDecoder`]: util.md#class-utiltextdecoder
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2
Expand Down
23 changes: 19 additions & 4 deletions doc/api/module.md
Expand Up @@ -80,15 +80,29 @@ isBuiltin('fs'); // true
isBuiltin('wss'); // false
```
### `module.register()`
### `module.register(specifier[, parentURL][, options])`
<!-- YAML
added: REPLACEME
-->
In addition to using the `--experimental-loader` option in the CLI,
loaders can be registered programmatically using the
`module.register()` method.
> Stability: 1.1 - Active development
* `specifier` {string} Customization hooks to be registered; this should be the
same string that would be passed to `import()`, except that if it is relative,
it is resolved relative to `parentURL`.
* `parentURL` {string} If you want to resolve `specifier` relative to a base
URL, such as `import.meta.url`, you can pass that URL here. **Default:**
`'data:'`
* `options` {Object}
* `data` {any} Any arbitrary, cloneable JavaScript value to pass into the
[`initialize`][] hook.
* `transferList` {Object\[]} [transferrable objects][] to be passed into the
`initialize` hook.
* Returns: {any} returns whatever was returned by the `initialize` hook.
Register a module that exports hooks that customize Node.js module resolution
and loading behavior.
```mjs
import { register } from 'node:module';
Expand Down Expand Up @@ -390,3 +404,4 @@ returned object contains the following keys:
[`module`]: modules.md#the-module-object
[module wrapper]: modules.md#the-module-wrapper
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
[transferrable objects]: worker_threads.md#portpostmessagevalue-transferlist
21 changes: 15 additions & 6 deletions doc/api/n-api.md
Expand Up @@ -3070,13 +3070,18 @@ napi_status napi_get_buffer_info(napi_env env,
```

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

Returns `napi_ok` if the API succeeded.

This method returns the identical `data` and `byte_length` as
[`napi_get_typedarray_info`][]. And `napi_get_typedarray_info` accepts a
`node::Buffer` (a Uint8Array) as the value too.

This API is used to retrieve the underlying data buffer of a `node::Buffer`
and its length.

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

* `[in] env`: The environment that the API is invoked under.
* `[in] value`: The JavaScript value to check.
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer`
object.
* `[out] result`: Whether the given `napi_value` represents a `node::Buffer` or
`Uint8Array` object.

Returns `napi_ok` if the API succeeded.

This API checks if the `Object` passed in is a buffer.
This API checks if the `Object` passed in is a buffer or Uint8Array.
[`napi_is_typedarray`][] should be preferred if the caller needs to check if the
value is a Uint8Array.

### `napi_is_date`

Expand Down Expand Up @@ -6502,11 +6509,13 @@ the add-on's file name during loading.
[`napi_get_last_error_info`]: #napi_get_last_error_info
[`napi_get_property`]: #napi_get_property
[`napi_get_reference_value`]: #napi_get_reference_value
[`napi_get_typedarray_info`]: #napi_get_typedarray_info
[`napi_get_value_external`]: #napi_get_value_external
[`napi_has_property`]: #napi_has_property
[`napi_instanceof`]: #napi_instanceof
[`napi_is_error`]: #napi_is_error
[`napi_is_exception_pending`]: #napi_is_exception_pending
[`napi_is_typedarray`]: #napi_is_typedarray
[`napi_make_callback`]: #napi_make_callback
[`napi_open_callback_scope`]: #napi_open_callback_scope
[`napi_open_escapable_handle_scope`]: #napi_open_escapable_handle_scope
Expand Down
8 changes: 4 additions & 4 deletions doc/api/webstreams.md
Expand Up @@ -1219,13 +1219,13 @@ changes:
description: This class is now exposed on the global object.
-->
#### `new ByteLengthQueuingStrategy(options)`
#### `new ByteLengthQueuingStrategy(init)`
<!-- YAML
added: v16.5.0
-->
* `options` {Object}
* `init` {Object}
* `highWaterMark` {number}
#### `byteLengthQueuingStrategy.highWaterMark`
Expand Down Expand Up @@ -1256,13 +1256,13 @@ changes:
description: This class is now exposed on the global object.
-->
#### `new CountQueuingStrategy(options)`
#### `new CountQueuingStrategy(init)`
<!-- YAML
added: v16.5.0
-->
* `options` {Object}
* `init` {Object}
* `highWaterMark` {number}
#### `countQueuingStrategy.highWaterMark`
Expand Down
6 changes: 0 additions & 6 deletions lib/internal/crypto/util.js
Expand Up @@ -75,11 +75,6 @@ const {
const kHandle = Symbol('kHandle');
const kKeyObject = Symbol('kKeyObject');

// TODO(tniessen): remove all call sites and this function
function getDefaultEncoding() {
return 'buffer';
}

// This is here because many functions accepted binary strings without
// any explicit encoding in older versions of node, and we don't want
// to break them unnecessarily.
Expand Down Expand Up @@ -555,7 +550,6 @@ module.exports = {
getCiphers,
getCurves,
getDataViewOrTypedArrayBuffer,
getDefaultEncoding,
getHashes,
kHandle,
kKeyObject,
Expand Down
31 changes: 20 additions & 11 deletions lib/internal/modules/esm/load.js
Expand Up @@ -70,25 +70,30 @@ async function getSource(url, context) {
return { __proto__: null, responseURL, source };
}

/**
* @param {URL} url URL to the module
* @param {ESModuleContext} context used to decorate error messages
* @returns {{ responseURL: string, source: string | BufferView }}
*/
function getSourceSync(url, context) {
const parsed = new URL(url);
const responseURL = url;
const { protocol, href } = url;
const responseURL = href;
let source;
if (parsed.protocol === 'file:') {
source = readFileSync(parsed);
} else if (parsed.protocol === 'data:') {
const match = RegExpPrototypeExec(DATA_URL_PATTERN, parsed.pathname);
if (protocol === 'file:') {
source = readFileSync(url);
} else if (protocol === 'data:') {
const match = RegExpPrototypeExec(DATA_URL_PATTERN, url.pathname);
if (!match) {
throw new ERR_INVALID_URL(url);
throw new ERR_INVALID_URL(responseURL);
}
const { 1: base64, 2: body } = match;
source = BufferFrom(decodeURIComponent(body), base64 ? 'base64' : 'utf8');
} else {
const supportedSchemes = ['file', 'data'];
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, supportedSchemes);
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supportedSchemes);
}
if (policy?.manifest) {
policy.manifest.assertIntegrity(parsed, source);
policy.manifest.assertIntegrity(url, source);
}
return { __proto__: null, responseURL, source };
}
Expand Down Expand Up @@ -159,14 +164,18 @@ function defaultLoadSync(url, context = kEmptyObject) {
source,
} = context;

format ??= defaultGetFormat(new URL(url), context);
const urlInstance = new URL(url);

throwIfUnsupportedURLScheme(urlInstance, false);

format ??= defaultGetFormat(urlInstance, context);

validateAssertions(url, format, importAssertions);

if (format === 'builtin') {
source = null;
} else if (source == null) {
({ responseURL, source } = getSourceSync(url, context));
({ responseURL, source } = getSourceSync(urlInstance, context));
}

return {
Expand Down
6 changes: 1 addition & 5 deletions lib/internal/streams/lazy_transform.js
Expand Up @@ -11,10 +11,6 @@ const {

const stream = require('stream');

const {
getDefaultEncoding,
} = require('internal/crypto/util');

module.exports = LazyTransform;

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

if (!this._options || !this._options.defaultEncoding) {
this._writableState.defaultEncoding = getDefaultEncoding();
this._writableState.defaultEncoding = 'buffer'; // TODO(tniessen): remove
}

return this[name];
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/webstreams/queuingstrategies.js
Expand Up @@ -69,7 +69,7 @@ class ByteLengthQueuingStrategy {
constructor(init) {
validateObject(init, 'init');
if (init.highWaterMark === undefined)
throw new ERR_MISSING_OPTION('options.highWaterMark');
throw new ERR_MISSING_OPTION('init.highWaterMark');

// The highWaterMark value is not checked until the strategy
// is actually used, per the spec.
Expand Down Expand Up @@ -121,7 +121,7 @@ class CountQueuingStrategy {
constructor(init) {
validateObject(init, 'init');
if (init.highWaterMark === undefined)
throw new ERR_MISSING_OPTION('options.highWaterMark');
throw new ERR_MISSING_OPTION('init.highWaterMark');

// The highWaterMark value is not checked until the strategy
// is actually used, per the spec.
Expand Down
26 changes: 13 additions & 13 deletions src/cares_wrap.cc
Expand Up @@ -830,62 +830,62 @@ void ChannelWrap::EnsureServers() {

int AnyTraits::Send(QueryWrap<AnyTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_any);
return 0;
return ARES_SUCCESS;
}

int ATraits::Send(QueryWrap<ATraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_a);
return 0;
return ARES_SUCCESS;
}

int AaaaTraits::Send(QueryWrap<AaaaTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_aaaa);
return 0;
return ARES_SUCCESS;
}

int CaaTraits::Send(QueryWrap<CaaTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, T_CAA);
return 0;
return ARES_SUCCESS;
}

int CnameTraits::Send(QueryWrap<CnameTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_cname);
return 0;
return ARES_SUCCESS;
}

int MxTraits::Send(QueryWrap<MxTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_mx);
return 0;
return ARES_SUCCESS;
}

int NsTraits::Send(QueryWrap<NsTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_ns);
return 0;
return ARES_SUCCESS;
}

int TxtTraits::Send(QueryWrap<TxtTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_txt);
return 0;
return ARES_SUCCESS;
}

int SrvTraits::Send(QueryWrap<SrvTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_srv);
return 0;
return ARES_SUCCESS;
}

int PtrTraits::Send(QueryWrap<PtrTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_ptr);
return 0;
return ARES_SUCCESS;
}

int NaptrTraits::Send(QueryWrap<NaptrTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_naptr);
return 0;
return ARES_SUCCESS;
}

int SoaTraits::Send(QueryWrap<SoaTraits>* wrap, const char* name) {
wrap->AresQuery(name, ns_c_in, ns_t_soa);
return 0;
return ARES_SUCCESS;
}

int AnyTraits::Parse(
Expand Down Expand Up @@ -1381,7 +1381,7 @@ int ReverseTraits::Send(GetHostByAddrWrap* wrap, const char* name) {
family,
GetHostByAddrWrap::Callback,
wrap->MakeCallbackPointer());
return 0;
return ARES_SUCCESS;
}

int ReverseTraits::Parse(
Expand Down

0 comments on commit 46d42ca

Please sign in to comment.