Skip to content

Commit 5f1055c

Browse files
committedJun 30, 2014
implemening and testing FlagList functions
1 parent e6645de commit 5f1055c

File tree

6 files changed

+179
-5
lines changed

6 files changed

+179
-5
lines changed
 

Diff for: ‎binding.gyp

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
'targets': [
3+
{
4+
'target_name': 'v8_flag_list',
5+
'sources': [
6+
'src/v8_flag_list.cc'
7+
],
8+
'include_dirs': [
9+
'<!(node -e "require(\'nan\')")',
10+
'<!(node -e \'console.log(require("path").join(process.env.HOME, ".node-gyp", process.versions.node, "src"))\')',
11+
'<!(node -e \'console.log(require("path").join(process.env.HOME, ".node-gyp", process.versions.node, "deps", "v8", "src"))\')'
12+
]
13+
},
314
{
415
'target_name': 'v8_flags',
516
'sources': [

Diff for: ‎index.js

+67-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
var v8_flags = require('./build/Release/v8_flags')
4-
, v8_meta = require('./build/Release/v8_flags_meta');
4+
, v8_meta = require('./build/Release/v8_flags_meta')
5+
, v8_flag_list = require('./build/Release/v8_flag_list')
56

67
// The following flags aren't configurable after startup since they activate (or don't) during the bootstrapping process
78
// https://github.com/v8/v8/blob/146bf7bec2518cf664994a658dfc4a72a9c6bb10/src/bootstrapper.cc#L86-L97
@@ -17,9 +18,41 @@ var notConfigurable = [
1718
, 'harmony_collections'
1819
]
1920

21+
/**
22+
* Exposes methods to get and set v8 flags.
23+
*
24+
* #### Example
25+
*
26+
* ```js
27+
* var flags = require('v8-flags').flags;
28+
* console.log(flags.use_strict()); // false
29+
* flags.use_strict(true)
30+
* console.log(flags.use_strict()); // true
31+
* ```
32+
*
33+
* @name flags
34+
* @function
35+
*/
2036
var flags = exports.flags = v8_flags;
2137

22-
// constant meta data is initialized on startup from the definitions found in C++ land
38+
//
39+
/**
40+
* The meta data for the flags.
41+
*
42+
* It is initialized on startup from the definitions found in C++ land.
43+
*
44+
* @name meta
45+
* @function
46+
* @return {Array.<Object>} array of objects with the folloing properties each
47+
* - **name:** flag name
48+
* - **default:** default setting of the flag
49+
* - **type:** type of the flag
50+
* - **description:** the description of the flag
51+
* - **readonly:** set `true` if flag cannot be set
52+
* - **configurable:** set `true` if setting the flag at runtime has the desired effect
53+
* - **implications:** flags that will be set to `true` whenever this flag is `true` and `enforceFlagImplications` is called
54+
* - **negativeImplications:** flags that will be set to `false` whenever this flag is `false` and `enforceFlagImplications` is called
55+
*/
2356
exports.meta = Object.keys(v8_meta)
2457
.filter(function (k) {
2558
return k.slice(0, 13) !== 'implications_'
@@ -48,11 +81,42 @@ exports.meta = Object.keys(v8_meta)
4881
return acc;
4982
}, {});
5083

84+
/**
85+
* Lists all flags along with their **current** value.
86+
*
87+
* @name listFlags
88+
* @function
89+
* @return {Object} key/value pair for each flag
90+
*/
5191
exports.listFlags = function () {
5292
return Object.keys(flags)
53-
.filter(function (k) { return k.slice(0, 4) !== 'set_' })
5493
.reduce(function (acc, k) {
5594
acc[k] = flags[k]();
5695
return acc;
5796
}, {})
5897
}
98+
99+
/**
100+
* Prints flag help to the console.
101+
*
102+
* @name printHelp
103+
* @function
104+
*/
105+
exports.printHelp = v8_flag_list.printHelp;
106+
107+
/**
108+
* Resets all flags to their default values
109+
*
110+
* @name resetAllFlags
111+
* @function
112+
*/
113+
exports.resetAllFlags = v8_flag_list.resetAllFlags;
114+
115+
116+
/**
117+
* Enforces all flag implications.
118+
*
119+
* @name enforceFlagImplications
120+
* @function
121+
*/
122+
exports.enforceFlagImplications = v8_flag_list.enforceFlagImplications;

Diff for: ‎src/v8_flag_list.cc

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <nan.h>
2+
#include "v8.h"
3+
4+
#include "atomicops.h"
5+
#include "flags.h"
6+
#include <node.h>
7+
8+
namespace i = v8::internal;
9+
10+
// Reset all flags to their default value.
11+
NAN_METHOD(ResetAllFlags) {
12+
i::FlagList::ResetAllFlags();
13+
NanReturnUndefined();
14+
}
15+
16+
// Print help to stdout with flags, types, and default values.
17+
NAN_METHOD(PrintHelp) {
18+
i::FlagList::PrintHelp();
19+
NanReturnUndefined();
20+
}
21+
22+
// Set flags as consequence of being implied by another flag.
23+
NAN_METHOD(EnforceFlagImplications) {
24+
i::FlagList::EnforceFlagImplications();
25+
NanReturnUndefined();
26+
}
27+
28+
void init(v8::Handle<v8::Object> exports) {
29+
exports->Set(NanNew<v8::String>("resetAllFlags"), NanNew<v8::FunctionTemplate>(ResetAllFlags)->GetFunction());
30+
exports->Set(NanNew<v8::String>("printHelp"), NanNew<v8::FunctionTemplate>(PrintHelp)->GetFunction());
31+
exports->Set(NanNew<v8::String>("enforceFlagImplications"), NanNew<v8::FunctionTemplate>(EnforceFlagImplications)->GetFunction());
32+
}
33+
34+
NODE_MODULE(v8_flag_list, init)

Diff for: ‎test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ fi
99

1010
export PATH=$DIR/node_modules/.bin:$PATH
1111

12-
set -e
12+
set -e;
1313

1414
if [[ -e $TRAVIS ]]
1515
then
1616
npm install
1717
tap $DIR/test/*.js
1818
else
1919
nave use $1 npm install
20-
nave use $1 node $DIR/test/index.js
20+
for t in $DIR/test/*.js; do nave use $1 node $t; done
2121
fi

Diff for: ‎test/implications.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
var test = require('tap').test
4+
var v8Flags = require('../')
5+
, flags = v8Flags.flags
6+
, enforceImplications = v8Flags.enforceFlagImplications
7+
8+
9+
test('\nwhen setting harmony all implied harmony flags get set ONLY after enforcing flag implications, and never when unsetting', function (t) {
10+
t.on('end', function () {
11+
flags.harmony(false)
12+
flags.harmony_scoping(false)
13+
flags.harmony_modules(false)
14+
flags.harmony_proxies(false)
15+
flags.harmony_collections(false)
16+
})
17+
18+
flags.harmony(true)
19+
t.ok(!flags.harmony_scoping(), 'harmony_scoping off')
20+
t.ok(!flags.harmony_modules(), 'harmony_modules off')
21+
t.ok(!flags.harmony_proxies(), 'harmony_proxies off')
22+
t.ok(!flags.harmony_collections(), 'harmony_collections off')
23+
24+
enforceImplications()
25+
26+
t.ok(flags.harmony_scoping(), 'harmony_scoping on after enforcement')
27+
t.ok(flags.harmony_modules(), 'harmony_modules on after enforcement')
28+
t.ok(flags.harmony_proxies(), 'harmony_proxies on after enforcement')
29+
t.ok(flags.harmony_collections(), 'harmony_collections on after enforcement')
30+
31+
flags.harmony(false)
32+
enforceImplications()
33+
34+
t.ok(flags.harmony_scoping(), 'harmony_scoping still on')
35+
t.ok(flags.harmony_modules(), 'harmony_modules still on')
36+
t.ok(flags.harmony_proxies(), 'harmony_proxies still on')
37+
t.ok(flags.harmony_collections(), 'harmony_collections still on')
38+
39+
t.end()
40+
})

Diff for: ‎test/reset-all-flags.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var test = require('tap').test
4+
var v8Flags = require('../')
5+
, flags = v8Flags.flags
6+
, resetAllFlags= v8Flags.resetAllFlags
7+
8+
test('\nresetting all flags resets only `false` by default flags to `false`', function (t) {
9+
t.on('end', resetAllFlags)
10+
11+
flags.use_strict(true)
12+
flags.trap_on_deopt(true)
13+
14+
t.ok(flags.use_strict(), 'use_strict on')
15+
t.ok(flags.trap_on_deopt(), 'trap_on_deopt on')
16+
t.ok(flags.crankshaft(), 'crankshaft on by default')
17+
18+
resetAllFlags()
19+
20+
t.ok(!flags.use_strict(), 'use_strict off')
21+
t.ok(!flags.trap_on_deopt(), 'trap_on_deopt off')
22+
t.ok(flags.crankshaft(), 'crankshaft on by default')
23+
24+
t.end()
25+
})

0 commit comments

Comments
 (0)
Please sign in to comment.