1// Flags: --no-addons 2 3'use strict'; 4 5const common = require('../../common'); 6const assert = require('assert'); 7const path = require('path'); 8const { Worker } = require('worker_threads'); 9 10const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`); 11 12const assertError = (error) => { 13 assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED'); 14 assert.strictEqual( 15 error.message, 16 'Cannot load native addon because loading addons is disabled.', 17 ); 18}; 19 20{ 21 // Flags should be inherited 22 const worker = new Worker(`require(${JSON.stringify(binding)})`, { 23 eval: true, 24 }); 25 26 worker.on('error', common.mustCall(assertError)); 27} 28 29{ 30 // Should throw when using `process.dlopen` directly 31 const worker = new Worker( 32 `process.dlopen({ exports: {} }, ${JSON.stringify(binding)});`, 33 { 34 eval: true, 35 }, 36 ); 37 38 worker.on('error', common.mustCall(assertError)); 39} 40 41{ 42 // Explicitly pass `--no-addons` 43 const worker = new Worker(`require(${JSON.stringify(binding)})`, { 44 eval: true, 45 execArgv: ['--no-addons'], 46 }); 47 48 worker.on('error', common.mustCall(assertError)); 49} 50 51{ 52 // If `execArgv` is overwritten it should still fail to load addons 53 const worker = new Worker(`require(${JSON.stringify(binding)})`, { 54 eval: true, 55 execArgv: [], 56 }); 57 58 worker.on('error', common.mustCall(assertError)); 59} 60