1'use strict'; 2const common = require('../../common'); 3 4if (common.isWindows) 5 common.skip('dlopen global symbol loading is not supported on this os.'); 6 7const assert = require('assert'); 8const path = require('path'); 9const os = require('os'); 10 11const bindingPath = require.resolve(`./build/${common.buildType}/binding`); 12console.log('process.dlopen:', bindingPath); 13process.dlopen(module, bindingPath, 14 os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL); 15console.log('module.exports.load:', `${path.dirname(bindingPath)}/ping.so`); 16module.exports.load(`${path.dirname(bindingPath)}/ping.so`); 17assert.strictEqual(module.exports.ping(), 'pong'); 18 19// Check that after the addon is loaded with 20// process.dlopen() a require() call fails. 21console.log('require:', `./build/${common.buildType}/binding`); 22const re = /^Error: Module did not self-register: '.*[\\/]binding\.node'\.$/; 23assert.throws(() => require(`./build/${common.buildType}/binding`), re); 24