0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-buffer-constructor-node-modules.js
Joyee Cheung 14353387eb
src: implement IsInsideNodeModules() in C++
This previously compiles a script and run it in a new context
to avoid global pollution, which is more complex than necessary
and can be too slow for it to be reused in other cases. The
new implementation just checks the frames in C++ which is safe
from global pollution, faster and simpler.

The previous implementation also had a bug when the call site
is in a ESM, because ESM have URLs as their script names,
which don't start with '/' or '\' and will be skipped. The new
implementation removes the skipping to fix it for ESM.

PR-URL: https://github.com/nodejs/node/pull/55286
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2024-10-08 10:19:46 +00:00

49 lines
938 B
JavaScript

'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const { spawnSyncAndAssert } = require('../common/child_process');
if (process.env.NODE_PENDING_DEPRECATION)
common.skip('test does not work when NODE_PENDING_DEPRECATION is set');
spawnSyncAndAssert(
process.execPath,
[ fixtures.path('warning_node_modules', 'new-buffer-cjs.js') ],
{
trim: true,
stderr: '',
}
);
spawnSyncAndAssert(
process.execPath,
[ fixtures.path('warning_node_modules', 'new-buffer-esm.mjs') ],
{
trim: true,
stderr: '',
}
);
spawnSyncAndAssert(
process.execPath,
[
'--pending-deprecation',
fixtures.path('warning_node_modules', 'new-buffer-cjs.js'),
],
{
stderr: /DEP0005/
}
);
spawnSyncAndAssert(
process.execPath,
[
'--pending-deprecation',
fixtures.path('warning_node_modules', 'new-buffer-esm.mjs'),
],
{
stderr: /DEP0005/
}
);