-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
123 lines (114 loc) · 3.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict';
var v8_flags = require('./build/Release/v8_flags')
, v8_meta = require('./build/Release/v8_flags_meta')
, v8_flag_list = require('./build/Release/v8_flag_list')
// The following flags aren't configurable after startup since they activate (or don't) during the bootstrapping process
// https://github.com/v8/v8/blob/146bf7bec2518cf664994a658dfc4a72a9c6bb10/src/bootstrapper.cc#L86-L97
var notConfigurable = [
'expose_gc'
, 'expose_gc_as'
, 'expose_natives_as'
, 'debugger'
, 'debugger_agent'
, 'debugger_port'
, 'expose_debug_as'
, 'harmony_proxies'
, 'harmony_collections'
]
/**
* Exposes methods to get and set v8 flags.
*
* #### Example
*
* ```js
* var flags = require('v8-flags').flags;
* console.log(flags.use_strict()); // false
* flags.use_strict(true)
* console.log(flags.use_strict()); // true
* ```
*
* @name flags
* @function
*/
var flags = exports.flags = v8_flags;
//
/**
* The meta data for the flags.
*
* It is initialized on startup from the definitions found in C++ land.
*
* @name meta
* @function
* @return {Array.<Object>} array of objects with the folloing properties each
*
* - **name:** flag name
* - **default:** default setting of the flag
* - **type:** type of the flag
* - **description:** the description of the flag
* - **readonly:** set `true` if flag cannot be set
* - **configurable:** set `true` if setting the flag at runtime has the desired effect
* - **implications:** flags that will be set to `true` whenever this flag is `true` and `enforceFlagImplications` is called
* - **negativeImplications:** flags that will be set to `false` whenever this flag is `false` and `enforceFlagImplications` is called
*/
exports.meta = Object.keys(v8_meta)
.filter(function (k) {
return k.slice(0, 13) !== 'implications_'
&& k.slice(0, 17) !== 'neg_implications_'
})
.reduce(function (acc, k) {
var implications, neg_implications;
v8_meta['implications_' + k](function () {
implications = [].slice.call(arguments);
})
v8_meta['neg_implications_' + k](function () {
neg_implications = [].slice.call(arguments);
})
v8_meta[k](function () {
acc[k] = {
name : arguments[0]
, default : arguments[1]
, description : arguments[2]
, type : arguments[3]
, readonly : arguments[4]
, implications : implications
, negativeImplications : neg_implications
, configurable : !~notConfigurable.indexOf(k)
}
});
return acc;
}, {});
/**
* Lists all flags along with their **current** value.
*
* @name listFlags
* @function
* @return {Object} key/value pair for each flag
*/
exports.listFlags = function () {
return Object.keys(flags)
.reduce(function (acc, k) {
acc[k] = flags[k]();
return acc;
}, {})
}
/**
* Prints flag help to the console.
*
* @name printHelp
* @function
*/
exports.printHelp = v8_flag_list.printHelp;
/**
* Resets all flags to their default values
*
* @name resetAllFlags
* @function
*/
exports.resetAllFlags = v8_flag_list.resetAllFlags;
/**
* Enforces all flag implications.
*
* @name enforceFlagImplications
* @function
*/
exports.enforceFlagImplications = v8_flag_list.enforceFlagImplications;