Skip to content

Commit f7b2fce

Browse files
aduh95codebytere
authored andcommitted
vm: refactor to use more primordials
PR-URL: #36023 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 6678897 commit f7b2fce

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/internal/vm/module.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
const assert = require('internal/assert');
44
const {
55
ArrayIsArray,
6+
ArrayPrototypeForEach,
7+
ArrayPrototypeIndexOf,
8+
ArrayPrototypeSome,
69
ObjectCreate,
710
ObjectDefineProperty,
811
ObjectGetPrototypeOf,
912
ObjectSetPrototypeOf,
10-
SafePromise,
13+
PromiseAll,
14+
SafeWeakMap,
1115
Symbol,
1216
SymbolToStringTag,
1317
TypeError,
14-
WeakMap,
1518
} = primordials;
1619

1720
const { isContext } = internalBinding('contextify');
@@ -62,7 +65,7 @@ const STATUS_MAP = {
6265

6366
let globalModuleId = 0;
6467
const defaultModuleName = 'vm:module';
65-
const wrapToModuleMap = new WeakMap();
68+
const wrapToModuleMap = new SafeWeakMap();
6669

6770
const kWrap = Symbol('kWrap');
6871
const kContext = Symbol('kContext');
@@ -332,7 +335,7 @@ class SourceTextModule extends Module {
332335

333336
try {
334337
if (promises !== undefined) {
335-
await SafePromise.all(promises);
338+
await PromiseAll(promises);
336339
}
337340
} catch (e) {
338341
this.#error = e;
@@ -392,13 +395,13 @@ class SourceTextModule extends Module {
392395
class SyntheticModule extends Module {
393396
constructor(exportNames, evaluateCallback, options = {}) {
394397
if (!ArrayIsArray(exportNames) ||
395-
exportNames.some((e) => typeof e !== 'string')) {
398+
ArrayPrototypeSome(exportNames, (e) => typeof e !== 'string')) {
396399
throw new ERR_INVALID_ARG_TYPE('exportNames',
397400
'Array of unique strings',
398401
exportNames);
399402
} else {
400-
exportNames.forEach((name, i) => {
401-
if (exportNames.indexOf(name, i + 1) !== -1) {
403+
ArrayPrototypeForEach(exportNames, (name, i) => {
404+
if (ArrayPrototypeIndexOf(exportNames, name, i + 1) !== -1) {
402405
throw new ERR_INVALID_ARG_VALUE(`exportNames.${name}`,
403406
name,
404407
'is duplicated');

lib/vm.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
const {
2525
ArrayPrototypeForEach,
2626
Symbol,
27-
PromiseReject
27+
PromiseReject,
28+
ReflectApply,
2829
} = primordials;
2930

3031
const {
@@ -269,7 +270,7 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
269270
process.removeAllListeners('SIGINT');
270271

271272
try {
272-
return fn.apply(thisArg, argsArray);
273+
return ReflectApply(fn, thisArg, argsArray);
273274
} finally {
274275
// Add using the public methods so that the `newListener` handler of
275276
// process can re-attach the listeners.

0 commit comments

Comments
 (0)