Skip to content

Commit

Permalink
src: add type check to v8.setFlagsFromString()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
r-52 authored and bnoordhuis committed May 8, 2015
1 parent 8bf878d commit 931a0d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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");
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);

0 comments on commit 931a0d4

Please sign in to comment.