diff options
Diffstat (limited to 'lib/vm.js')
-rw-r--r-- | lib/vm.js | 24 |
1 files changed, 6 insertions, 18 deletions
@@ -28,11 +28,9 @@ const { isContext: _isContext, } = process.binding('contextify'); -const { - ERR_INVALID_ARG_TYPE, - ERR_OUT_OF_RANGE -} = require('internal/errors').codes; +const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; const { isUint8Array } = require('internal/util/types'); +const { validateInt32, validateUint32 } = require('internal/validators'); class Script extends ContextifyScript { constructor(code, options = {}) { @@ -56,8 +54,8 @@ class Script extends ContextifyScript { if (typeof filename !== 'string') { throw new ERR_INVALID_ARG_TYPE('options.filename', 'string', filename); } - validateInteger(lineOffset, 'options.lineOffset'); - validateInteger(columnOffset, 'options.columnOffset'); + validateInt32(lineOffset, 'options.lineOffset'); + validateInt32(columnOffset, 'options.columnOffset'); if (cachedData !== undefined && !isUint8Array(cachedData)) { throw new ERR_INVALID_ARG_TYPE('options.cachedData', ['Buffer', 'Uint8Array'], cachedData); @@ -119,15 +117,6 @@ function validateContext(sandbox) { } } -function validateInteger(prop, propName) { - if (!Number.isInteger(prop)) { - throw new ERR_INVALID_ARG_TYPE(propName, 'integer', prop); - } - if ((prop >> 0) !== prop) { - throw new ERR_OUT_OF_RANGE(propName, '32-bit integer', prop); - } -} - function validateString(prop, propName) { if (prop !== undefined && typeof prop !== 'string') throw new ERR_INVALID_ARG_TYPE(propName, 'string', prop); @@ -151,9 +140,8 @@ function getRunInContextArgs(options = {}) { let timeout = options.timeout; if (timeout === undefined) { timeout = -1; - } else if (!Number.isInteger(timeout) || timeout <= 0) { - throw new ERR_INVALID_ARG_TYPE('options.timeout', 'a positive integer', - timeout); + } else { + validateUint32(timeout, 'options.timeout', true); } const { |