mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 21:33:14 +00:00

Unlike JS-only modules, native add-ons are always associated with a dynamic shared object from which they are loaded. Being able to retrieve its absolute path is important to native-only add-ons, i.e. add-ons that are not themselves being loaded from a JS-only module located in the same package as the native add-on itself. Currently, the file name is obtained at environment construction time from the JS `module.filename`. Nevertheless, the presence of `module` is not required, because the file name could also be passed in via a private property added onto `exports` from the `process.dlopen` binding. As an attempt at future-proofing, the file name is provided as a URL, i.e. prefixed with the `file://` protocol. Fixes: https://github.com/nodejs/node-addon-api/issues/449 PR-URL: https://github.com/nodejs/node/pull/37195 Co-authored-by: Michael Dawson <mdawson@devrus.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
16 lines
608 B
JavaScript
16 lines
608 B
JavaScript
'use strict';
|
|
|
|
const common = require('../../common');
|
|
const filename = require.resolve(`./build/${common.buildType}/test_general`);
|
|
const test_general = require(filename);
|
|
const assert = require('assert');
|
|
|
|
// TODO(gabrielschulhof): This test may need updating if/when the filename
|
|
// becomes a full-fledged URL.
|
|
assert.strictEqual(test_general.filename, `file://${filename}`);
|
|
|
|
const [ major, minor, patch, release ] = test_general.testGetNodeVersion();
|
|
assert.strictEqual(process.version.split('-')[0],
|
|
`v${major}.${minor}.${patch}`);
|
|
assert.strictEqual(release, process.release.name);
|