diff --git a/doc/api/v8.markdown b/doc/api/v8.markdown index adced82685eea4..cedd5c86d9b008 100644 --- a/doc/api/v8.markdown +++ b/doc/api/v8.markdown @@ -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 diff --git a/src/node_v8.cc b/src/node_v8.cc index f3bdda409d0f6e..2834a21496bbdb 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -60,6 +60,13 @@ void GetHeapStatistics(const FunctionCallbackInfo& args) { void SetFlagsFromString(const FunctionCallbackInfo& 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()); } diff --git a/test/parallel/test-v8-flag-type-check.js b/test/parallel/test-v8-flag-type-check.js new file mode 100644 index 00000000000000..1bb501df43606c --- /dev/null +++ b/test/parallel/test-v8-flag-type-check.js @@ -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);