Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: refactor to use more primordials #36023

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/internal/vm/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
const assert = require('internal/assert');
const {
ArrayIsArray,
ArrayPrototypeForEach,
ArrayPrototypeIndexOf,
ArrayPrototypeSome,
ObjectCreate,
ObjectDefineProperty,
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
SafePromise,
PromiseAll,
SafeWeakMap,
Symbol,
SymbolToStringTag,
TypeError,
WeakMap,
} = primordials;

const { isContext } = internalBinding('contextify');
Expand Down Expand Up @@ -62,7 +65,7 @@ const STATUS_MAP = {

let globalModuleId = 0;
const defaultModuleName = 'vm:module';
const wrapToModuleMap = new WeakMap();
const wrapToModuleMap = new SafeWeakMap();

const kWrap = Symbol('kWrap');
const kContext = Symbol('kContext');
Expand Down Expand Up @@ -332,7 +335,7 @@ class SourceTextModule extends Module {

try {
if (promises !== undefined) {
await SafePromise.all(promises);
await PromiseAll(promises);
}
} catch (e) {
this.#error = e;
Expand Down Expand Up @@ -392,13 +395,13 @@ class SourceTextModule extends Module {
class SyntheticModule extends Module {
constructor(exportNames, evaluateCallback, options = {}) {
if (!ArrayIsArray(exportNames) ||
exportNames.some((e) => typeof e !== 'string')) {
ArrayPrototypeSome(exportNames, (e) => typeof e !== 'string')) {
throw new ERR_INVALID_ARG_TYPE('exportNames',
'Array of unique strings',
exportNames);
} else {
exportNames.forEach((name, i) => {
if (exportNames.indexOf(name, i + 1) !== -1) {
ArrayPrototypeForEach(exportNames, (name, i) => {
if (ArrayPrototypeIndexOf(exportNames, name, i + 1) !== -1) {
throw new ERR_INVALID_ARG_VALUE(`exportNames.${name}`,
name,
'is duplicated');
Expand Down
5 changes: 3 additions & 2 deletions lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
const {
ArrayPrototypeForEach,
Symbol,
PromiseReject
PromiseReject,
ReflectApply,
} = primordials;

const {
Expand Down Expand Up @@ -269,7 +270,7 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
process.removeAllListeners('SIGINT');

try {
return fn.apply(thisArg, argsArray);
return ReflectApply(fn, thisArg, argsArray);
} finally {
// Add using the public methods so that the `newListener` handler of
// process can re-attach the listeners.
Expand Down