11cb0ef41Sopenharmony_ci// Flags: --no-addons 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci'use strict'; 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../../common'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst path = require('path'); 81cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst binding = path.resolve(__dirname, `./build/${common.buildType}/binding`); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst assertError = (error) => { 131cb0ef41Sopenharmony_ci assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED'); 141cb0ef41Sopenharmony_ci assert.strictEqual( 151cb0ef41Sopenharmony_ci error.message, 161cb0ef41Sopenharmony_ci 'Cannot load native addon because loading addons is disabled.', 171cb0ef41Sopenharmony_ci ); 181cb0ef41Sopenharmony_ci}; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci{ 211cb0ef41Sopenharmony_ci // Flags should be inherited 221cb0ef41Sopenharmony_ci const worker = new Worker(`require(${JSON.stringify(binding)})`, { 231cb0ef41Sopenharmony_ci eval: true, 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci worker.on('error', common.mustCall(assertError)); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci{ 301cb0ef41Sopenharmony_ci // Should throw when using `process.dlopen` directly 311cb0ef41Sopenharmony_ci const worker = new Worker( 321cb0ef41Sopenharmony_ci `process.dlopen({ exports: {} }, ${JSON.stringify(binding)});`, 331cb0ef41Sopenharmony_ci { 341cb0ef41Sopenharmony_ci eval: true, 351cb0ef41Sopenharmony_ci }, 361cb0ef41Sopenharmony_ci ); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci worker.on('error', common.mustCall(assertError)); 391cb0ef41Sopenharmony_ci} 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci{ 421cb0ef41Sopenharmony_ci // Explicitly pass `--no-addons` 431cb0ef41Sopenharmony_ci const worker = new Worker(`require(${JSON.stringify(binding)})`, { 441cb0ef41Sopenharmony_ci eval: true, 451cb0ef41Sopenharmony_ci execArgv: ['--no-addons'], 461cb0ef41Sopenharmony_ci }); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci worker.on('error', common.mustCall(assertError)); 491cb0ef41Sopenharmony_ci} 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci{ 521cb0ef41Sopenharmony_ci // If `execArgv` is overwritten it should still fail to load addons 531cb0ef41Sopenharmony_ci const worker = new Worker(`require(${JSON.stringify(binding)})`, { 541cb0ef41Sopenharmony_ci eval: true, 551cb0ef41Sopenharmony_ci execArgv: [], 561cb0ef41Sopenharmony_ci }); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci worker.on('error', common.mustCall(assertError)); 591cb0ef41Sopenharmony_ci} 60