Skip to content

Commit 1906f19

Browse files
aduh95BethGriggs
authored andcommittedDec 15, 2020
vm: refactor to use more primordials
PR-URL: #36023 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 8d672b8 commit 1906f19

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,14 +3,17 @@
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
TypeError,
13-
WeakMap,
1417
} = primordials;
1518

1619
const { isContext } = internalBinding('contextify');
@@ -61,7 +64,7 @@ const STATUS_MAP = {
6164

6265
let globalModuleId = 0;
6366
const defaultModuleName = 'vm:module';
64-
const wrapToModuleMap = new WeakMap();
67+
const wrapToModuleMap = new SafeWeakMap();
6568

6669
const kWrap = Symbol('kWrap');
6770
const kContext = Symbol('kContext');
@@ -331,7 +334,7 @@ class SourceTextModule extends Module {
331334

332335
try {
333336
if (promises !== undefined) {
334-
await SafePromise.all(promises);
337+
await PromiseAll(promises);
335338
}
336339
} catch (e) {
337340
this.#error = e;
@@ -391,13 +394,13 @@ class SourceTextModule extends Module {
391394
class SyntheticModule extends Module {
392395
constructor(exportNames, evaluateCallback, options = {}) {
393396
if (!ArrayIsArray(exportNames) ||
394-
exportNames.some((e) => typeof e !== 'string')) {
397+
ArrayPrototypeSome(exportNames, (e) => typeof e !== 'string')) {
395398
throw new ERR_INVALID_ARG_TYPE('exportNames',
396399
'Array of unique strings',
397400
exportNames);
398401
} else {
399-
exportNames.forEach((name, i) => {
400-
if (exportNames.indexOf(name, i + 1) !== -1) {
402+
ArrayPrototypeForEach(exportNames, (name, i) => {
403+
if (ArrayPrototypeIndexOf(exportNames, name, i + 1) !== -1) {
401404
throw new ERR_INVALID_ARG_VALUE(`exportNames.${name}`,
402405
name,
403406
'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)
Please sign in to comment.