diff options
author | Michaƫl Zasso <targos@protonmail.com> | 2018-04-15 11:16:50 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-26 19:42:48 +0200 |
commit | e8361287030fbaa773761bb3798d45903bb160f6 (patch) | |
tree | 31d6820edf67fbd3167e05e6bf00ed05463466b8 /test/parallel/test-vm-options-validation.js | |
parent | d5e363b77ebaf1caf67cd7528224b651c86815c1 (diff) | |
download | android-node-v8-e8361287030fbaa773761bb3798d45903bb160f6.tar.gz android-node-v8-e8361287030fbaa773761bb3798d45903bb160f6.tar.bz2 android-node-v8-e8361287030fbaa773761bb3798d45903bb160f6.zip |
lib: introduce internal/validators
Create a file to centralize argument validators that are used in
multiple internal modules.
Move validateInt32 and validateUint32 to this file.
PR-URL: https://github.com/nodejs/node/pull/19973
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-vm-options-validation.js')
-rw-r--r-- | test/parallel/test-vm-options-validation.js | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/test/parallel/test-vm-options-validation.js b/test/parallel/test-vm-options-validation.js index e00a14e4b9..67a27d58ff 100644 --- a/test/parallel/test-vm-options-validation.js +++ b/test/parallel/test-vm-options-validation.js @@ -17,7 +17,7 @@ common.expectsError(() => { new vm.Script('void 0', 42); }, invalidArgType); -[null, {}, [1], 'bad', true, 0.1].forEach((value) => { +[null, {}, [1], 'bad', true].forEach((value) => { common.expectsError(() => { new vm.Script('void 0', { lineOffset: value }); }, invalidArgType); @@ -27,6 +27,16 @@ common.expectsError(() => { }, invalidArgType); }); +[0.1, 2 ** 32].forEach((value) => { + common.expectsError(() => { + new vm.Script('void 0', { lineOffset: value }); + }, outOfRange); + + common.expectsError(() => { + new vm.Script('void 0', { columnOffset: value }); + }, outOfRange); +}); + common.expectsError(() => { new vm.Script('void 0', { lineOffset: Number.MAX_SAFE_INTEGER }); }, outOfRange); @@ -53,26 +63,31 @@ common.expectsError(() => { const script = new vm.Script('void 0'); const sandbox = vm.createContext(); - function assertErrors(options) { + function assertErrors(options, errCheck) { common.expectsError(() => { script.runInThisContext(options); - }, invalidArgType); + }, errCheck); common.expectsError(() => { script.runInContext(sandbox, options); - }, invalidArgType); + }, errCheck); common.expectsError(() => { script.runInNewContext({}, options); - }, invalidArgType); + }, errCheck); } - [null, 'bad', 42].forEach(assertErrors); - [{}, [1], 'bad', null, -1, 0, NaN].forEach((value) => { - assertErrors({ timeout: value }); + [null, 'bad', 42].forEach((value) => { + assertErrors(value, invalidArgType); + }); + [{}, [1], 'bad', null].forEach((value) => { + assertErrors({ timeout: value }, invalidArgType); + }); + [-1, 0, NaN].forEach((value) => { + assertErrors({ timeout: value }, outOfRange); }); [{}, [1], 'bad', 1, null].forEach((value) => { - assertErrors({ displayErrors: value }); - assertErrors({ breakOnSigint: value }); + assertErrors({ displayErrors: value }, invalidArgType); + assertErrors({ breakOnSigint: value }, invalidArgType); }); } |