Skip to content

Commit

Permalink
vm: refactor to use more primordials
Browse files Browse the repository at this point in the history
PR-URL: #36023
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
aduh95 authored and BethGriggs committed Dec 15, 2020
1 parent 8d672b8 commit 1906f19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions lib/internal/vm/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
const assert = require('internal/assert');
const {
ArrayIsArray,
ArrayPrototypeForEach,
ArrayPrototypeIndexOf,
ArrayPrototypeSome,
ObjectCreate,
ObjectDefineProperty,
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
SafePromise,
PromiseAll,
SafeWeakMap,
Symbol,
TypeError,
WeakMap,
} = primordials;

const { isContext } = internalBinding('contextify');
Expand Down Expand Up @@ -61,7 +64,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 @@ -331,7 +334,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 @@ -391,13 +394,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

0 comments on commit 1906f19

Please sign in to comment.