Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: improve validation utils and refactor vm argument validation #31480

Closed
wants to merge 2 commits into from

Conversation

lundibundi
Copy link
Member

The first commit adds basic validation utilities like validateArray, validateBoolean,
validateObject.

The second commit refactors vm.js with the new validators as an example. There are multiple places in the codebase where we manually validate objects and arrays which can be simplified with validators.js.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

//cc @nodejs/vm

Add common validators: `validateArray`, `validateBoolean`,
`validateObject` and appropriate tests.
@nodejs-github-bot nodejs-github-bot added the vm Issues and PRs related to the vm subsystem. label Jan 23, 2020
}
return {};
return contextOptions;
}

function isContext(object) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not changed as currently, it skips Arrays to the _isContext function which in turn rejects them. If I use validateObject it would change the error message for Arrays passed to the isContext from expected to be vm.Context to expected to be an Object and since we have explicit tests for this case I decided to not change this for now.

@nodejs-github-bot
Copy link
Collaborator

@lundibundi
Copy link
Member Author

ping @nodejs/vm @BridgeAR (I guess there is no proper group for this one too).

@nodejs-github-bot
Copy link
Collaborator

@lundibundi
Copy link
Member Author

Started another CI to make sure everything is fine, the previous one is quite old.

@lundibundi lundibundi added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 9, 2020
lundibundi added a commit that referenced this pull request Feb 10, 2020
Add common validators: `validateArray`, `validateBoolean`,
`validateObject` and appropriate tests.

PR-URL: #31480
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
lundibundi added a commit that referenced this pull request Feb 10, 2020
PR-URL: #31480
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
@lundibundi
Copy link
Member Author

Landed in c405e9b and 2abf0af.

@lundibundi lundibundi closed this Feb 10, 2020
@lundibundi lundibundi deleted the improve-validation-utils branch February 10, 2020 19:46
@codebytere
Copy link
Member

@lundibundi does this need to be backported to v13.x? it'll need manual if so.

MylesBorins pushed a commit that referenced this pull request Mar 10, 2020
PR-URL: #31480
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
@MylesBorins
Copy link
Contributor

was able to get this backported... must have been some new changes that landed that made this work. removing label

MylesBorins pushed a commit that referenced this pull request Mar 10, 2020
Add common validators: `validateArray`, `validateBoolean`,
`validateObject` and appropriate tests.

PR-URL: #31480
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
@MylesBorins MylesBorins mentioned this pull request Mar 10, 2020
@targos targos added backport-blocked-v12.x and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-blocked-v12.x labels Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants