Skip to content

Commit

Permalink
vm: use kEmptyObject
Browse files Browse the repository at this point in the history
PR-URL: #43159
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
LiviaMedeiros authored and danielleadams committed Jun 13, 2022
1 parent e31baca commit 024b396
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lib/internal/vm/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ const {
isArrayBufferView,
} = require('internal/util/types');
const {
getConstructorOf,
customInspectSymbol,
emitExperimentalWarning,
getConstructorOf,
kEmptyObject,
} = require('internal/util');
const {
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -199,7 +200,7 @@ class Module {
this[kWrap].instantiate();
}

async evaluate(options = {}) {
async evaluate(options = kEmptyObject) {
if (this[kWrap] === undefined) {
throw new ERR_VM_MODULE_NOT_MODULE();
}
Expand Down Expand Up @@ -258,7 +259,7 @@ class SourceTextModule extends Module {
#error = kNoError;
#statusOverride;

constructor(sourceText, options = {}) {
constructor(sourceText, options = kEmptyObject) {
validateString(sourceText, 'sourceText');
validateObject(options, 'options');

Expand Down Expand Up @@ -387,7 +388,7 @@ class SourceTextModule extends Module {
}

class SyntheticModule extends Module {
constructor(exportNames, evaluateCallback, options = {}) {
constructor(exportNames, evaluateCallback, options = kEmptyObject) {
if (!ArrayIsArray(exportNames) ||
ArrayPrototypeSome(exportNames, (e) => typeof e !== 'string')) {
throw new ERR_INVALID_ARG_TYPE('exportNames',
Expand Down
13 changes: 7 additions & 6 deletions lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ const {
validateUint32,
} = require('internal/validators');
const {
kVmBreakFirstLineSymbol,
emitExperimentalWarning,
kEmptyObject,
kVmBreakFirstLineSymbol,
} = require('internal/util');
const kParsingContext = Symbol('script parsing context');

class Script extends ContextifyScript {
constructor(code, options = {}) {
constructor(code, options = kEmptyObject) {
code = `${code}`;
if (typeof options === 'string') {
options = { filename: options };
Expand Down Expand Up @@ -152,7 +153,7 @@ function validateContext(contextifiedObject) {
}
}

function getRunInContextArgs(options = {}) {
function getRunInContextArgs(options = kEmptyObject) {
validateObject(options, 'options');

let timeout = options.timeout;
Expand Down Expand Up @@ -212,7 +213,7 @@ function isContext(object) {
}

let defaultContextNameIndex = 1;
function createContext(contextObject = {}, options = {}) {
function createContext(contextObject = {}, options = kEmptyObject) {
if (isContext(contextObject)) {
return contextObject;
}
Expand Down Expand Up @@ -305,7 +306,7 @@ function runInThisContext(code, options) {
return createScript(code, options).runInThisContext(options);
}

function compileFunction(code, params, options = {}) {
function compileFunction(code, params, options = kEmptyObject) {
validateString(code, 'code');
if (params !== undefined) {
validateArray(params, 'params');
Expand Down Expand Up @@ -395,7 +396,7 @@ const measureMemoryExecutions = {
eager: constants.measureMemory.execution.EAGER,
};

function measureMemory(options = {}) {
function measureMemory(options = kEmptyObject) {
emitExperimentalWarning('vm.measureMemory');
validateObject(options, 'options');
const { mode = 'summary', execution = 'default' } = options;
Expand Down

0 comments on commit 024b396

Please sign in to comment.