Permalink
Browse files

v8: migrate setFlagsFromString to internal/errors

PR-URL: #16535
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information...
jasnell committed Oct 26, 2017
1 parent 4fdd76d commit ef238fb485f25c1c74edee5b390c849870e6ec53
Showing with 22 additions and 15 deletions.
  1. +2 −1 doc/api/v8.md
  2. +8 −1 lib/v8.js
  3. +1 −7 src/node_v8.cc
  4. +11 −6 test/parallel/test-v8-flag-type-check.js
View
@@ -133,10 +133,11 @@ For example:
}
```
## v8.setFlagsFromString(string)
## v8.setFlagsFromString(flags)
<!-- YAML
added: v1.0.0
-->
* `flags` {string}
The `v8.setFlagsFromString()` method can be used to programmatically set
V8 command line flags. This method should be used with care. Changing settings
View
@@ -15,6 +15,7 @@
'use strict';
const { Buffer } = require('buffer');
const errors = require('internal/errors');
const {
Serializer: _Serializer,
Deserializer: _Deserializer
@@ -32,7 +33,7 @@ class Deserializer extends _Deserializer { }
const {
cachedDataVersionTag,
setFlagsFromString,
setFlagsFromString: _setFlagsFromString,
heapStatisticsArrayBuffer,
heapSpaceStatisticsArrayBuffer,
updateHeapStatisticsArrayBuffer,
@@ -64,6 +65,12 @@ const heapStatisticsBuffer =
const heapSpaceStatisticsBuffer =
new Float64Array(heapSpaceStatisticsArrayBuffer);
function setFlagsFromString(flags) {
if (typeof flags !== 'string')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'flags', 'string');
_setFlagsFromString(flags);
}
function getHeapStatistics() {
const buffer = heapStatisticsBuffer;
View
@@ -114,13 +114,7 @@ void UpdateHeapSpaceStatisticsBuffer(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");
CHECK(args[0]->IsString());
String::Utf8Value flags(args[0]);
V8::SetFlagsFromString(*flags, flags.length());
}
@@ -1,9 +1,14 @@
'use strict';
require('../common');
const assert = require('assert');
const common = require('../common');
const v8 = require('v8');
assert.throws(function() { v8.setFlagsFromString(1); },
/^TypeError: v8 flag must be a string$/);
assert.throws(function() { v8.setFlagsFromString(); },
/^TypeError: v8 flag is required$/);
[ 1, undefined ].forEach((i) => {
common.expectsError(
() => v8.setFlagsFromString(i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "flags" argument must be of type string'
}
);
});

0 comments on commit ef238fb

Please sign in to comment.