Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/nodejs/node into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Pierre-Doray committed Nov 20, 2023
2 parents 7249d66 + a9a4778 commit 5b1c9b7
Show file tree
Hide file tree
Showing 42 changed files with 12,936 additions and 6,851 deletions.
2 changes: 1 addition & 1 deletion benchmark/crypto/webcrypto-digest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const bench = common.createBenchmark(main, {
sync: ['createHash', 'subtle'],
data: [10, 20, 50, 100],
method: ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'],
n: [1e3],
n: [1e5],
});

const kMethods = {
Expand Down
7 changes: 7 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,12 @@
help='Enable V8 transparent hugepage support. This feature is only '+
'available on Linux platform.')

parser.add_argument('--v8-enable-maglev',
action='store_true',
dest='v8_enable_maglev',
default=None,
help='Enable V8 Maglev compiler. Not available on all platforms.')

parser.add_argument('--v8-enable-short-builtin-calls',
action='store_true',
dest='v8_enable_short_builtin_calls',
Expand Down Expand Up @@ -1494,6 +1500,7 @@ def configure_v8(o):
o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
o['variables']['v8_promise_internal_field_count'] = 1 # Add internal field to promises for async hooks.
o['variables']['v8_use_siphash'] = 0 if options.without_siphash else 1
o['variables']['v8_enable_maglev'] = 1 if options.v8_enable_maglev else 0
o['variables']['v8_enable_pointer_compression'] = 1 if options.enable_pointer_compression else 0
o['variables']['v8_enable_31bit_smis_on_64bit_arch'] = 1 if options.enable_pointer_compression else 0
o['variables']['v8_enable_shared_ro_heap'] = 0 if options.enable_pointer_compression or options.disable_shared_ro_heap else 1
Expand Down
17,606 changes: 11,171 additions & 6,435 deletions deps/simdutf/simdutf.cpp

Large diffs are not rendered by default.

1,071 changes: 866 additions & 205 deletions deps/simdutf/simdutf.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -2722,15 +2722,15 @@ added: v15.9.0
The issuer certificate or `undefined` if the issuer certificate is not
available.

### `x509.keyUsage`
### `x509.extKeyUsage`

<!-- YAML
added: v15.6.0
-->

* Type: {string\[]}

An array detailing the key usages for this certificate.
An array detailing the key extended usages for this certificate.

### `x509.publicKey`

Expand Down
3 changes: 2 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6256,7 +6256,8 @@ changes:
* `flag` {string} See [support of file system `flags`][]. **Default:** `'w'`.
* `flush` {boolean} If all data is successfully written to the file, and
`flush` is `true`, `fs.fsyncSync()` is used to flush the data.
Returns `undefined`.
Returns `undefined`.
The `mode` option only affects the newly created file. See [`fs.open()`][]
for more details.
Expand Down
6 changes: 3 additions & 3 deletions doc/contributing/maintaining/maintaining-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This a list of all the dependencies:
* [openssl 3.0.8][]
* [postject 1.0.0-alpha.6][]
* [simdjson 3.6.0][]
* [simdutf 3.2.18][]
* [simdutf 4.0.4][]
* [undici 5.27.0][]
* [uvwasi 0.0.19][]
* [V8 11.8.172.12][]
Expand Down Expand Up @@ -292,7 +292,7 @@ The [postject](https://github.com/nodejs/postject) dependency is used for the
The [simdjson](https://github.com/simdjson/simdjson) dependency is
a C++ library for fast JSON parsing.

### simdutf 3.2.18
### simdutf 4.0.4

The [simdutf](https://github.com/simdutf/simdutf) dependency is
a C++ library for fast UTF-8 decoding and encoding.
Expand Down Expand Up @@ -351,7 +351,7 @@ performance improvements not currently available in standard zlib.
[openssl 3.0.8]: #openssl-308
[postject 1.0.0-alpha.6]: #postject-100-alpha6
[simdjson 3.6.0]: #simdutf-360
[simdutf 3.2.18]: #simdutf-3218
[simdutf 4.0.4]: #simdutf-404
[undici 5.27.0]: #undici-5270
[update-openssl-action]: ../../../.github/workflows/update-openssl.yml
[uvwasi 0.0.19]: #uvwasi-0019
Expand Down
57 changes: 24 additions & 33 deletions lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const {
JSONParse,
JSONStringify,
SafeMap,
Symbol,
SymbolDispose,
} = primordials;

Expand Down Expand Up @@ -45,28 +44,19 @@ const {
console,
} = internalBinding('inspector');

const connectionSymbol = Symbol('connectionProperty');
const messageCallbacksSymbol = Symbol('messageCallbacks');
const nextIdSymbol = Symbol('nextId');
const onMessageSymbol = Symbol('onMessage');

class Session extends EventEmitter {
constructor() {
super();
this[connectionSymbol] = null;
this[nextIdSymbol] = 1;
this[messageCallbacksSymbol] = new SafeMap();
}
#connection = null;
#nextId = 1;
#messageCallbacks = new SafeMap();

/**
* Connects the session to the inspector back-end.
* @returns {void}
*/
connect() {
if (this[connectionSymbol])
if (this.#connection)
throw new ERR_INSPECTOR_ALREADY_CONNECTED('The inspector session');
this[connectionSymbol] =
new Connection((message) => this[onMessageSymbol](message));
this.#connection = new Connection((message) => this.#onMessage(message));
}

/**
Expand All @@ -77,23 +67,24 @@ class Session extends EventEmitter {
connectToMainThread() {
if (isMainThread)
throw new ERR_INSPECTOR_NOT_WORKER();
if (this[connectionSymbol])
if (this.#connection)
throw new ERR_INSPECTOR_ALREADY_CONNECTED('The inspector session');
this[connectionSymbol] =
this.#connection =
new MainThreadConnection(
(message) => queueMicrotask(() => this[onMessageSymbol](message)));
(message) => queueMicrotask(() => this.#onMessage(message)));
}

[onMessageSymbol](message) {
#onMessage(message) {
const parsed = JSONParse(message);
try {
if (parsed.id) {
const callback = this[messageCallbacksSymbol].get(parsed.id);
this[messageCallbacksSymbol].delete(parsed.id);
const callback = this.#messageCallbacks.get(parsed.id);
this.#messageCallbacks.delete(parsed.id);
if (callback) {
if (parsed.error) {
return callback(new ERR_INSPECTOR_COMMAND(parsed.error.code,
parsed.error.message));
return callback(
new ERR_INSPECTOR_COMMAND(parsed.error.code, parsed.error.message),
);
}

callback(null, parsed.result);
Expand Down Expand Up @@ -127,18 +118,18 @@ class Session extends EventEmitter {
validateFunction(callback, 'callback');
}

if (!this[connectionSymbol]) {
if (!this.#connection) {
throw new ERR_INSPECTOR_NOT_CONNECTED();
}
const id = this[nextIdSymbol]++;
const id = this.#nextId++;
const message = { id, method };
if (params) {
message.params = params;
}
if (callback) {
this[messageCallbacksSymbol].set(id, callback);
this.#messageCallbacks.set(id, callback);
}
this[connectionSymbol].dispatch(JSONStringify(message));
this.#connection.dispatch(JSONStringify(message));
}

/**
Expand All @@ -148,16 +139,16 @@ class Session extends EventEmitter {
* @returns {void}
*/
disconnect() {
if (!this[connectionSymbol])
if (!this.#connection)
return;
this[connectionSymbol].disconnect();
this[connectionSymbol] = null;
const remainingCallbacks = this[messageCallbacksSymbol].values();
this.#connection.disconnect();
this.#connection = null;
const remainingCallbacks = this.#messageCallbacks.values();
for (const callback of remainingCallbacks) {
process.nextTick(callback, new ERR_INSPECTOR_CLOSED());
}
this[messageCallbacksSymbol].clear();
this[nextIdSymbol] = 1;
this.#messageCallbacks.clear();
this.#nextId = 1;
}
}

Expand Down
50 changes: 41 additions & 9 deletions lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
'use strict';

const {
ArrayPrototypeFilter,
ArrayPrototypeMap,
Boolean,
ObjectEntries,
PromisePrototypeThen,
PromiseResolve,
SafePromiseAll,
SafePromisePrototypeFinally,
SafeSet,
TypedArrayPrototypeGetBuffer,
TypedArrayPrototypeGetByteOffset,
TypedArrayPrototypeGetByteLength,
TypedArrayPrototypeGetByteOffset,
TypeError,
Uint8Array,
} = primordials;

Expand Down Expand Up @@ -82,6 +88,38 @@ const { UV_EOF } = internalBinding('uv');

const encoder = new TextEncoder();

// Collect all negative (error) ZLIB codes and Z_NEED_DICT
const ZLIB_FAILURES = new SafeSet([
...ArrayPrototypeFilter(
ArrayPrototypeMap(
ObjectEntries(internalBinding('constants').zlib),
({ 0: code, 1: value }) => (value < 0 ? code : null),
),
Boolean,
),
'Z_NEED_DICT',
]);

/**
* @param {Error|null} cause
* @returns {Error|null}
*/
function handleKnownInternalErrors(cause) {
switch (true) {
case cause?.code === 'ERR_STREAM_PREMATURE_CLOSE': {
return new AbortError(undefined, { cause });
}
case ZLIB_FAILURES.has(cause?.code): {
// eslint-disable-next-line no-restricted-syntax
const error = new TypeError(undefined, { cause });
error.code = cause.code;
return error;
}
default:
return cause;
}
}

/**
* @typedef {import('../../stream').Writable} Writable
* @typedef {import('../../stream').Readable} Readable
Expand Down Expand Up @@ -137,10 +175,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {
}

const cleanup = finished(streamWritable, (error) => {
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
const err = new AbortError(undefined, { cause: error });
error = err;
}
error = handleKnownInternalErrors(error);

cleanup();
// This is a protection against non-standard, legacy streams
Expand Down Expand Up @@ -440,10 +475,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj
streamReadable.pause();

const cleanup = finished(streamReadable, (error) => {
if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
const err = new AbortError(undefined, { cause: error });
error = err;
}
error = handleKnownInternalErrors(error);

cleanup();
// This is a protection against non-standard, legacy streams
Expand Down
11 changes: 11 additions & 0 deletions lib/internal/webstreams/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
ObjectDefineProperties,
SymbolToStringTag,
} = primordials;

const {
Expand Down Expand Up @@ -137,11 +138,21 @@ class DecompressionStream {
ObjectDefineProperties(CompressionStream.prototype, {
readable: kEnumerableProperty,
writable: kEnumerableProperty,
[SymbolToStringTag]: {
__proto__: null,
configurable: true,
value: 'CompressionStream',
},
});

ObjectDefineProperties(DecompressionStream.prototype, {
readable: kEnumerableProperty,
writable: kEnumerableProperty,
[SymbolToStringTag]: {
__proto__: null,
configurable: true,
value: 'DecompressionStream',
},
});

module.exports = {
Expand Down
12 changes: 8 additions & 4 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,14 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
}

static Local<Object> createImportAttributesContainer(
Realm* realm, Isolate* isolate, Local<FixedArray> raw_attributes) {
Realm* realm,
Isolate* isolate,
Local<FixedArray> raw_attributes,
const int elements_per_attribute) {
CHECK_EQ(raw_attributes->Length() % elements_per_attribute, 0);
Local<Object> attributes =
Object::New(isolate, v8::Null(isolate), nullptr, nullptr, 0);
for (int i = 0; i < raw_attributes->Length(); i += 3) {
for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) {
attributes
->Set(realm->context(),
raw_attributes->Get(realm->context(), i).As<String>(),
Expand Down Expand Up @@ -304,7 +308,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {

Local<FixedArray> raw_attributes = module_request->GetImportAssertions();
Local<Object> attributes =
createImportAttributesContainer(realm, isolate, raw_attributes);
createImportAttributesContainer(realm, isolate, raw_attributes, 3);

Local<Value> argv[] = {
specifier,
Expand Down Expand Up @@ -588,7 +592,7 @@ static MaybeLocal<Promise> ImportModuleDynamically(
}

Local<Object> attributes =
createImportAttributesContainer(realm, isolate, import_attributes);
createImportAttributesContainer(realm, isolate, import_attributes, 2);

Local<Value> import_args[] = {
id,
Expand Down
10 changes: 4 additions & 6 deletions src/permission/fs_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ namespace permission {
// allow = '/tmp/,/home/example.js'
void FSPermission::Apply(const std::vector<std::string>& allow,
PermissionScope scope) {
using std::string_view_literals::operator""sv;

for (const std::string_view res : allow) {
if (res == "*"sv) {
for (const std::string& res : allow) {
if (res == "*") {
if (scope == PermissionScope::kFileSystemRead) {
deny_all_in_ = false;
allow_all_in_ = true;
Expand All @@ -132,7 +130,7 @@ void FSPermission::Apply(const std::vector<std::string>& allow,
}
return;
}
GrantAccess(scope, std::string(res.data(), res.size()));
GrantAccess(scope, res);
}
}

Expand Down Expand Up @@ -172,7 +170,7 @@ FSPermission::RadixTree::~RadixTree() {
}

bool FSPermission::RadixTree::Lookup(const std::string_view& s,
bool when_empty_return = false) const {
bool when_empty_return) const {
FSPermission::RadixTree::Node* current_node = root_node_;
if (current_node->children.size() == 0) {
return when_empty_return;
Expand Down
2 changes: 1 addition & 1 deletion test/common/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ class WPTRunner {
'ReadableStreamBYOBReader', 'ReadableStreamBYOBRequest',
'ReadableByteStreamController', 'ReadableStreamDefaultController',
'ByteLengthQueuingStrategy', 'CountQueuingStrategy',
'TextEncoderStream', 'TextDecoderStream',
'TextEncoder', 'TextDecoder', 'TextEncoderStream', 'TextDecoderStream',
'CompressionStream', 'DecompressionStream',
];
if (Boolean(process.versions.openssl) && !process.env.NODE_SKIP_CRYPTO) {
Expand Down
Loading

0 comments on commit 5b1c9b7

Please sign in to comment.