Skip to content
Merged
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
9 changes: 9 additions & 0 deletions lib/internal/streams/iter/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@
if (this.#consumerState !== 'active') return;
this.#consumerState = 'returned';
this.#cleanup();
this.#resolvePendingReads();
this.#rejectPendingWrites(
new ERR_INVALID_STATE.TypeError('Stream closed by consumer'));
// If closing, reject the pending end promise
Expand All @@ -443,7 +444,12 @@
this.#consumerState = 'thrown';
this.#error = error;
this.#cleanup();
this.#rejectPendingReads(error);
this.#rejectPendingWrites(error);
if (this.#writerState === 'closing' && this.#pendingEnd) {
this.#pendingEnd.reject(error);
this.#pendingEnd = null;
}
// Reject pending drains - the consumer errored
this.#rejectPendingDrains(error);
}
Expand Down Expand Up @@ -485,6 +491,9 @@
} else if (this.#writerState === 'errored' && this.#error) {
const pending = this.#pendingReads.shift();
pending.reject(this.#error);
} else if (this.#consumerState === 'returned') {
const pending = this.#pendingReads.shift();
pending.resolve({ __proto__: null, value: undefined, done: true });

Check failure on line 496 in lib/internal/streams/iter/push.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Iterator result objects should place `done` before `value`

Check failure on line 496 in lib/internal/streams/iter/push.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Iterator result objects should place `done` before `value`
} else {
break;
}
Expand Down
9 changes: 9 additions & 0 deletions src/ffi/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ Maybe<FunctionSignature> ParseFunctionSignature(Environment* env,
if (!ToFFIType(env, arg_str.ToStringView()).To(&arg_type)) {
return {};
}
if (arg_type == &ffi_type_void) {
THROW_ERR_INVALID_ARG_VALUE(
env,
"Argument %u of function %s must not be 'void'; "
"use an empty array for no-argument functions",
i,
name);
return {};
}

args.push_back(arg_type);
arg_type_names.emplace_back(arg_str.ToString());
Expand Down
6 changes: 4 additions & 2 deletions src/node_webstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ using v8::PropertyAttribute;
using v8::PropertyCallbackInfo;
using v8::PropertyDescriptor;
using v8::PropertyHandlerFlags;
using v8::Signature;
using v8::String;
using v8::Value;

Expand Down Expand Up @@ -737,8 +738,9 @@ static void Initialize(Local<Object> target,
Local<Value>(),
PropertyHandlerFlags::kHasNoSideEffect));

Local<FunctionTemplate> length_getter =
FunctionTemplate::New(isolate, StorageLengthGetter);
Local<Signature> length_signature = Signature::New(isolate, ctor_tmpl);
Local<FunctionTemplate> length_getter = FunctionTemplate::New(
isolate, StorageLengthGetter, Local<Value>(), length_signature);
ctor_tmpl->PrototypeTemplate()->SetAccessorProperty(env->length_string(),
length_getter,
Local<FunctionTemplate>(),
Expand Down
29 changes: 29 additions & 0 deletions test/ffi/test-ffi-void-parameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Flags: --experimental-ffi
'use strict';

const common = require('../common');
common.skipIfFFIMissing();

const assert = require('node:assert');
const ffi = require('node:ffi');
const { libraryPath } = require('./ffi-test-common');

// Regression test for https://github.com/nodejs/node/issues/63461
// 'void' as a parameter type should throw ERR_INVALID_ARG_VALUE
// instead of triggering ERR_INTERNAL_ASSERTION.

const lib = new ffi.DynamicLibrary(libraryPath);

try {
assert.throws(() => {
lib.getFunction('add_i32', { return: 'i32', arguments: ['void'] });
}, { code: 'ERR_INVALID_ARG_VALUE' });

assert.throws(() => {
lib.getFunctions({
add_i32: { return: 'i32', arguments: ['void'] },
});
}, { code: 'ERR_INVALID_ARG_VALUE' });
} finally {
lib.close();
}
5 changes: 3 additions & 2 deletions test/parallel/test-debugger-probe-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const { spawnSyncAndExit } = require('../common/child_process');
const { assertProbeJson } = require('../common/debugger-probe');
const cwd = fixtures.path('debugger');

const timeout = common.platformTimeout(1000);
spawnSyncAndExit(process.execPath, [
'inspect',
'--json',
'--timeout=200',
`--timeout=${timeout}`,
'--probe', 'probe-timeout.js:99',
'--expr', '1',
'probe-timeout.js',
Expand All @@ -31,7 +32,7 @@ spawnSyncAndExit(process.execPath, [
pending: [0],
error: {
code: 'probe_timeout',
message: 'Timed out after 200ms waiting for probes: probe-timeout.js:99',
message: `Timed out after ${timeout}ms waiting for probes: probe-timeout.js:99`,
},
}],
});
Expand Down
40 changes: 40 additions & 0 deletions test/parallel/test-stream-iter-push-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,44 @@ async function testFailRejectsPendingRead() {
);
}

// iterator.return() resolves a pending read with done:true
async function testConsumerReturnResolvesPendingRead() {
const { readable } = push();

const iter = readable[Symbol.asyncIterator]();
const readPromise = iter.next();

await new Promise(setImmediate);

const returnResult = await iter.return();
assert.strictEqual(returnResult.value, undefined);
assert.strictEqual(returnResult.done, true);

const readResult = await readPromise;
assert.strictEqual(readResult.value, undefined);
assert.strictEqual(readResult.done, true);
}

// iterator.throw() rejects a pending read with the thrown error
async function testConsumerThrowRejectsPendingRead() {
const { readable } = push();

const iter = readable[Symbol.asyncIterator]();
const readPromise = iter.next();

await new Promise(setImmediate);

const err = new Error('consumer read boom');
const throwResult = await iter.throw(err);
assert.strictEqual(throwResult.value, undefined);
assert.strictEqual(throwResult.done, true);

await assert.rejects(
() => readPromise,
(e) => e === err,
);
}

// end() while writes are pending rejects those writes
async function testEndRejectsPendingWrites() {
const { writer, readable } = push({ highWaterMark: 1, backpressure: 'block' });
Expand Down Expand Up @@ -435,6 +473,8 @@ Promise.all([
testConsumerThrowRejectsWrites(),
testEndResolvesPendingRead(),
testFailRejectsPendingRead(),
testConsumerReturnResolvesPendingRead(),
testConsumerThrowRejectsPendingRead(),
testEndRejectsPendingWrites(),
testEndIdempotentWhenClosed(),
testEndRejectsWhenErrored(),
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-webstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ test('Storage instances cannot be created in userland', async () => {
assert.match(cp.stderr, /Error: Illegal constructor/);
});

test('calling "length" getter on invalid this throws', async () => {
assert.throws(() => Storage.prototype.length, TypeError);
const { get } = Object.getOwnPropertyDescriptor(Storage.prototype, 'length');
for (const thisArg of [null, undefined, 1n, -0, NaN, true, false, '', [], {}, Symbol()]) {
assert.throws(() => get.call(thisArg), TypeError);
}
});

test('sessionStorage is not persisted', async () => {
let cp = await spawnPromisified(process.execPath, [
'-pe', 'sessionStorage.foo = "barbaz"',
Expand Down
Loading