vm: use kEmptyObject

PR-URL: https://github.com/nodejs/node/pull/43159
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
LiviaMedeiros authored and Michaël Zasso committed 2022-07-31 09:44:30 +02:00
1 parent 444d77391c
commit ca8da5f3f8
2 files changed
+12 -10

No files matched your search

+5 -4
View File
@@ -24,9 +24,10 @@ const {
isArrayBufferView,
} = require('internal/util/types');
const {
getConstructorOf,
customInspectSymbol,
emitExperimentalWarning,
getConstructorOf,
kEmptyObject,
} = require('internal/util');
const {
ERR_INVALID_ARG_TYPE,
@@ -198,7 +199,7 @@ class Module {
this[kWrap].instantiate();
}
async evaluate(options = {}) {
async evaluate(options = kEmptyObject) {
if (this[kWrap] === undefined) {
throw new ERR_VM_MODULE_NOT_MODULE();
}
@@ -256,7 +257,7 @@ class SourceTextModule extends Module {
#error = kNoError;
#statusOverride;
constructor(sourceText, options = {}) {
constructor(sourceText, options = kEmptyObject) {
validateString(sourceText, 'sourceText');
validateObject(options, 'options');
@@ -385,7 +386,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',
+7 -6
View File
@@ -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 };
@@ -152,7 +153,7 @@ function validateContext(contextifiedObject) {
}
}
function getRunInContextArgs(options = {}) {
function getRunInContextArgs(options = kEmptyObject) {
validateObject(options, 'options');
let timeout = options.timeout;
@@ -212,7 +213,7 @@ function isContext(object) {
}
let defaultContextNameIndex = 1;
function createContext(contextObject = {}, options = {}) {
function createContext(contextObject = {}, options = kEmptyObject) {
if (isContext(contextObject)) {
return contextObject;
}
@@ -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');
@@ -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;