MCPcopy Index your code
hub / github.com/nodejs/node / assertCrossThreadCallbackAbort

Function assertCrossThreadCallbackAbort

test/ffi/test-ffi-calls.js:352–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

350}
351
352function assertCrossThreadCallbackAbort() {
353 const workerSource = `
354const { workerData } = require('node:worker_threads');
355const ffi = require('node:ffi');
356const { fixtureSymbols, libraryPath } = require(${JSON.stringify(require.resolve('./ffi-test-common'))});
357const { functions } = ffi.dlopen(libraryPath, fixtureSymbols);
358functions.call_int_callback(workerData, 21);
359`;
360 const { stderr, status, signal } = spawnSync(process.execPath, [
361 '--experimental-ffi',
362 '-e',
363 `'use strict';
364const { Worker } = require('node:worker_threads');
365const ffi = require('node:ffi');
366const { fixtureSymbols, libraryPath } = require(${JSON.stringify(require.resolve('./ffi-test-common'))});
367const { lib } = ffi.dlopen(libraryPath, fixtureSymbols);
368const callback = lib.registerCallback(
369 { arguments: ['i32'], return: 'i32' },
370 (value) => value * 2,
371);
372new Worker(${JSON.stringify(workerSource)}, { eval: true, workerData: callback });`,
373 ], {
374 encoding: 'utf8',
375 });
376
377 assert.ok(common.nodeProcessAborted(status, signal),
378 `status: ${status}, signal: ${signal}
379stderr: ${stderr}`);
380 assert.match(stderr, /Callbacks can only be invoked on the system thread they were created on/);
381}
382
383test('ffi aborts on invalid callback return values', () => {
384 assertInvalidCallbackReturnAborts('1.5');

Callers 1

test-ffi-calls.jsFile · 0.85

Calls 4

matchMethod · 0.65
spawnSyncFunction · 0.50
resolveMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…