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

v8: add type check to make failed calls visible #1652

Closed
wants to merge 1 commit into from
Closed

v8: add type check to make failed calls visible #1652

wants to merge 1 commit into from

Conversation

r-52
Copy link
Contributor

@r-52 r-52 commented May 7, 2015

Calling v8.setFlagsFromString with e.g a function as a flag argument gave no exception or warning that the function call will fail. There is now an exception if the function gets called with the wrong flag type (string is required) or that a flag is expected. v8 flags are only possible as strings.
Other APIs (fs or net) already provide exceptions if the argument has not the expected type.

@Fishrock123 Fishrock123 added the c++ Issues and PRs that require attention from people who are familiar with C++. label May 7, 2015
@@ -60,6 +60,14 @@ void GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {


void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Environment* env = Environment::GetCurrent(isolate);
Copy link
Member

Choose a reason for hiding this comment

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

You can use the slightly more efficient Environment::GetCurrent(args) method here.

Calling v8.setFlagsFromString with e.g a function as a flag
argument gave no exception or warning that the function call will
fail. There is now an exception if the function gets called with
the wrong flag type (string is required) or that a flag is
expected.
Other APIs already provide exceptions if the argument has
not the expected type.
Environment* env = Environment::GetCurrent(args);

if (args.Length() < 1)
return env->ThrowTypeError("v8 flag is required");
Copy link

Choose a reason for hiding this comment

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

Would a RangeError not be more appropriate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't RangeErrors for integer argument values that are not between some min and max value?

Copy link

Choose a reason for hiding this comment

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

Yes, that might be right, but args.Length() is an integer value that should be between 1 and infinity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

args.Length returns the number of JavaScript arguments that were passed over. It should prevent, that no argument gets passed in. Other io.js APIs handle this special case with a TypeError, too. RangeError typically thrown if e.g. the process.uid is out of the possible range. My main thought was to keep it in sync with the other APIs.

Copy link

Choose a reason for hiding this comment

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

Alright, nevermind then. If the existing code uses TypeError then TypeError it is.

bnoordhuis pushed a commit that referenced this pull request May 8, 2015
Calling v8.setFlagsFromString with e.g a function as a flag argument
gave no exception or warning that the function call will fail.

There is now an exception if the function gets called with the wrong
flag type (string is required) or that a flag is expected.

Other APIs already provide exceptions if the argument has not the
expected type.

PR-URL: #1652
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@bnoordhuis
Copy link
Member

LGTM, thanks; landed in 931a0d4. I changed the commit log a little because v8: is usually the prefix we use for floating patches on top of the bundled V8. Thanks again!

@bnoordhuis bnoordhuis closed this May 8, 2015
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request May 19, 2015
Calling v8.setFlagsFromString with e.g a function as a flag argument
gave no exception or warning that the function call will fail.

There is now an exception if the function gets called with the wrong
flag type (string is required) or that a flag is expected.

Other APIs already provide exceptions if the argument has not the
expected type.

PR-URL: nodejs#1652
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants