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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/v8.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Returns an object with the following properties
}
```

## setFlagsFromString()
## setFlagsFromString(string)

Set additional V8 command line flags. Use with care; changing settings
after the VM has started may result in unpredictable behavior, including
Expand Down
7 changes: 7 additions & 0 deletions src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ void GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {


void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

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

Choose a reason for hiding this comment

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

Maybe make that args.Length() < 1? Or simply drop it and rely on the args[0]->IsString() check below to catch it.

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.

if (!args[0]->IsString())
return env->ThrowTypeError("v8 flag must be a string");

String::Utf8Value flags(args[0]);
V8::SetFlagsFromString(*flags, flags.length());
}
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-v8-flag-type-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var common = require('../common');
var assert = require('assert');
var v8 = require('v8');

assert.throws(function() {v8.setFlagsFromString(1)}, TypeError);
assert.throws(function() {v8.setFlagsFromString()}, TypeError);