Skip to content

Commit e42dcc2

Browse files
r-52Fishrock123
authored andcommitted
src: add type check to v8.setFlagsFromString()
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 <[email protected]>
1 parent e628b19 commit e42dcc2

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/api/v8.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Returns an object with the following properties
2020
}
2121
```
2222

23-
## setFlagsFromString()
23+
## setFlagsFromString(string)
2424

2525
Set additional V8 command line flags. Use with care; changing settings
2626
after the VM has started may result in unpredictable behavior, including

src/node_v8.cc

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ void GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {
6060

6161

6262
void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
63+
Environment* env = Environment::GetCurrent(args);
64+
65+
if (args.Length() < 1)
66+
return env->ThrowTypeError("v8 flag is required");
67+
if (!args[0]->IsString())
68+
return env->ThrowTypeError("v8 flag must be a string");
69+
6370
String::Utf8Value flags(args[0]);
6471
V8::SetFlagsFromString(*flags, flags.length());
6572
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var common = require('../common');
2+
var assert = require('assert');
3+
var v8 = require('v8');
4+
5+
assert.throws(function() {v8.setFlagsFromString(1)}, TypeError);
6+
assert.throws(function() {v8.setFlagsFromString()}, TypeError);

0 commit comments

Comments
 (0)