-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
vm: move some common tests to the top #18816
Conversation
lib/vm.js
Outdated
@@ -79,21 +79,21 @@ Script.prototype.runInNewContext = function(sandbox, options) { | |||
return this.runInContext(context, options); | |||
}; | |||
|
|||
function validateType(prop, propName, type = 'string') { | |||
if (prop !== undefined && | |||
typeof prop !== type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this should fit on the line above.
lib/vm.js
Outdated
@@ -79,21 +79,21 @@ Script.prototype.runInNewContext = function(sandbox, options) { | |||
return this.runInContext(context, options); | |||
}; | |||
|
|||
function validateType(prop, propName, type = 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type is always a string and setting a default value is a minor overhead. So instead, please just directly use 'string' in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, please change the function name to validateString
.
lib/vm.js
Outdated
'string', contextOptions.origin); | ||
} | ||
validateType(contextOptions.name, 'options.contextName'); | ||
validateType(contextOptions.origin, 'options.contextOrigin'); | ||
return contextOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you are here: would you be so kind and rewrite this to:
if (options) {
const contextOptions = {
name: ...
...
};
validateType(contextOptions.name, 'contextOptions.name');
validate...
return contextOptions;
}
return {};
lib/vm.js
Outdated
'string', contextOptions.origin); | ||
} | ||
validateType(contextOptions.name, 'options.contextName'); | ||
validateType(contextOptions.origin, 'options.contextOrigin'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not change the error message itself here. So please stick to contextOptions.name
and contextOptions.origin
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BridgeAR, the error messages are as it was.
lib/vm.js
Outdated
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.origin', | ||
'string', options.origin); | ||
} else { | ||
validateType(options.name, 'options.name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this as it was. Otherwise there is an extra check from now on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with my comment addressed.
lib/vm.js
Outdated
if (prop !== undefined && typeof prop !== 'string') | ||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', propName, | ||
'string', prop); | ||
} | ||
function getContextOptions(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a new line in between functions.
PR-URL: nodejs#18816 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Landed in 3cb3618 🎉 |
PR-URL: nodejs#18816 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: #18816 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#18816 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Noticed some repeated tests, extract it into a function .
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
vm