mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
wasi: use missing validator
The `wasi` lib module's `initialize()` method is missing a validator. PR-URL: https://github.com/nodejs/node/pull/39070 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
parent
ffda9a8953
commit
46a7e61900
@ -229,6 +229,11 @@ const validateFunction = hideStackFrames((value, name) => {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value);
|
||||
});
|
||||
|
||||
const validateUndefined = hideStackFrames((value, name) => {
|
||||
if (value !== undefined)
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'undefined', value);
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
isInt32,
|
||||
isUint32,
|
||||
@ -247,6 +252,7 @@ module.exports = {
|
||||
validateSignalName,
|
||||
validateString,
|
||||
validateUint32,
|
||||
validateUndefined,
|
||||
validateCallback,
|
||||
validateAbortSignal,
|
||||
};
|
||||
|
||||
17
lib/wasi.js
17
lib/wasi.js
@ -21,6 +21,7 @@ const {
|
||||
validateFunction,
|
||||
validateInt32,
|
||||
validateObject,
|
||||
validateUndefined,
|
||||
} = require('internal/validators');
|
||||
const { WASI: _WASI } = internalBinding('wasi');
|
||||
const kExitCode = Symbol('kExitCode');
|
||||
@ -120,10 +121,7 @@ class WASI {
|
||||
const { _start, _initialize } = this[kInstance].exports;
|
||||
|
||||
validateFunction(_start, 'instance.exports._start');
|
||||
if (_initialize !== undefined) {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'instance.exports._initialize', 'undefined', _initialize);
|
||||
}
|
||||
validateUndefined(_initialize, 'instance.exports._initialize');
|
||||
|
||||
try {
|
||||
_start();
|
||||
@ -147,16 +145,9 @@ class WASI {
|
||||
|
||||
const { _start, _initialize } = this[kInstance].exports;
|
||||
|
||||
if (typeof _initialize !== 'function' && _initialize !== undefined) {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'instance.exports._initialize', 'function', _initialize);
|
||||
}
|
||||
if (_start !== undefined) {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'instance.exports._start', 'undefined', _initialize);
|
||||
}
|
||||
|
||||
validateUndefined(_start, 'instance.exports._start');
|
||||
if (_initialize !== undefined) {
|
||||
validateFunction(_initialize, 'instance.exports._initialize');
|
||||
_initialize();
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
|
||||
() => { wasi.initialize(instance); },
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: /"instance\.exports\._start" property must be undefined/
|
||||
message: 'The "instance.exports._start" property must be' +
|
||||
' undefined. Received function _start',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -78,7 +78,8 @@ const bufferSource = fixtures.readSync('simple.wasm');
|
||||
() => { wasi.start(instance); },
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: /"instance\.exports\._initialize" property must be undefined/
|
||||
message: 'The "instance.exports._initialize" property must be' +
|
||||
' undefined. Received function _initialize',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user