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: migrate setFlagsFromString to internal/errors #16535

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
3 changes: 2 additions & 1 deletion doc/api/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'use strict';

const { Buffer } = require('buffer');
const errors = require('internal/errors');
const {
Serializer: _Serializer,
Deserializer: _Deserializer
Expand All @@ -32,7 +33,7 @@ class Deserializer extends _Deserializer { }

const {
cachedDataVersionTag,
setFlagsFromString,
setFlagsFromString: _setFlagsFromString,
heapStatisticsArrayBuffer,
heapSpaceStatisticsArrayBuffer,
updateHeapStatisticsArrayBuffer,
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 1 addition & 7 deletions src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
17 changes: 11 additions & 6 deletions test/parallel/test-v8-flag-type-check.js
Original file line number Diff line number Diff line change
@@ -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'
}
);
});