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 nodejs-github-bot committed Nov 14, 2020
1 parent 8297860 commit 1d02a35
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,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

0 comments on commit 1d02a35

Please sign in to comment.