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