mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
v8: migrate setFlagsFromString to internal/errors
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
65d2067936
commit
64168eb9b4
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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'
|
||||
}
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user