Skip to content

Commit 64168eb

Browse files
committedOct 30, 2017
v8: migrate setFlagsFromString to internal/errors
PR-URL: #16535 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 65d2067 commit 64168eb

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed
 

‎doc/api/v8.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ For example:
133133
}
134134
```
135135

136-
## v8.setFlagsFromString(string)
136+
## v8.setFlagsFromString(flags)
137137
<!-- YAML
138138
added: v1.0.0
139139
-->
140+
* `flags` {string}
140141

141142
The `v8.setFlagsFromString()` method can be used to programmatically set
142143
V8 command line flags. This method should be used with care. Changing settings

‎lib/v8.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'use strict';
1616

1717
const { Buffer } = require('buffer');
18+
const errors = require('internal/errors');
1819
const {
1920
Serializer: _Serializer,
2021
Deserializer: _Deserializer
@@ -32,7 +33,7 @@ class Deserializer extends _Deserializer { }
3233

3334
const {
3435
cachedDataVersionTag,
35-
setFlagsFromString,
36+
setFlagsFromString: _setFlagsFromString,
3637
heapStatisticsArrayBuffer,
3738
heapSpaceStatisticsArrayBuffer,
3839
updateHeapStatisticsArrayBuffer,
@@ -64,6 +65,12 @@ const heapStatisticsBuffer =
6465
const heapSpaceStatisticsBuffer =
6566
new Float64Array(heapSpaceStatisticsArrayBuffer);
6667

68+
function setFlagsFromString(flags) {
69+
if (typeof flags !== 'string')
70+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'flags', 'string');
71+
_setFlagsFromString(flags);
72+
}
73+
6774
function getHeapStatistics() {
6875
const buffer = heapStatisticsBuffer;
6976

‎src/node_v8.cc

+1-7
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,7 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
114114

115115

116116
void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
117-
Environment* env = Environment::GetCurrent(args);
118-
119-
if (args.Length() < 1)
120-
return env->ThrowTypeError("v8 flag is required");
121-
if (!args[0]->IsString())
122-
return env->ThrowTypeError("v8 flag must be a string");
123-
117+
CHECK(args[0]->IsString());
124118
String::Utf8Value flags(args[0]);
125119
V8::SetFlagsFromString(*flags, flags.length());
126120
}
+11-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
'use strict';
2-
require('../common');
3-
const assert = require('assert');
2+
const common = require('../common');
43
const v8 = require('v8');
54

6-
assert.throws(function() { v8.setFlagsFromString(1); },
7-
/^TypeError: v8 flag must be a string$/);
8-
assert.throws(function() { v8.setFlagsFromString(); },
9-
/^TypeError: v8 flag is required$/);
5+
[ 1, undefined ].forEach((i) => {
6+
common.expectsError(
7+
() => v8.setFlagsFromString(i),
8+
{
9+
code: 'ERR_INVALID_ARG_TYPE',
10+
type: TypeError,
11+
message: 'The "flags" argument must be of type string'
12+
}
13+
);
14+
});

0 commit comments

Comments
 (0)
Please sign in to comment.