FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

vm: move some common tests to the top by timotew · Pull Request #18816 · nodejs/node · GitHub

/ node Public

vm: move some common tests to the top - #18816

Closed
timotew wants to merge 2 commits into
nodejs:masterfrom
timotew:null-check
Closed

vm: move some common tests to the top#18816
timotew wants to merge 2 commits into
nodejs:masterfrom
timotew:null-check

Conversation

timotew commented Feb 16, 2018

Copy link
Copy Markdown
Contributor

Noticed some repeated tests, extract it into a function .

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

vm

nodejs-github-bot added the vm Issues and PRs related to the vm subsystem. label Feb 16, 2018
Comment thread lib/vm.js Outdated

function validateType(prop, propName, type = 'string') {
if (prop !== undefined &&
typeof prop !== type) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nit: this should fit on the line above.

Comment thread lib/vm.js Outdated
return this.runInContext(context, options);
};

function validateType(prop, propName, type = 'string') {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In that case, please change the function name to validateString.

Comment thread lib/vm.js Outdated
}
validateType(contextOptions.name, 'options.contextName');
validateType(contextOptions.origin, 'options.contextOrigin');
return contextOptions;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 {};

Comment thread lib/vm.js Outdated
'string', contextOptions.origin);
}
validateType(contextOptions.name, 'options.contextName');
validateType(contextOptions.origin, 'options.contextOrigin');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please do not change the error message itself here. So please stick to contextOptions.name and contextOptions.origin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@BridgeAR, the error messages are as it was.

Comment thread lib/vm.js Outdated
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options.origin',
'string', options.origin);
} else {
validateType(options.name, 'options.name');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please keep this as it was. Otherwise there is an extra check from now on.

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM with my comment addressed.

Comment thread lib/vm.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please add a new line in between functions.

BridgeAR added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Feb 17, 2018

Copy link
Copy Markdown
Member

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Feb 22, 2018
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>

Copy link
Copy Markdown
Member

Landed in 3cb3618 🎉

BridgeAR closed this Feb 22, 2018
addaleax pushed a commit to addaleax/node that referenced this pull request Feb 26, 2018
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>
addaleax pushed a commit that referenced this pull request Feb 26, 2018
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>
addaleax mentioned this pull request Feb 27, 2018
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. vm Issues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL