This repository was archived by the owner on Jun 5, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
Latest commit
58 lines (49 loc) · 1.78 KB
/
Copy pathindex.js
File metadata and controls
58 lines (49 loc) · 1.78 KB
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
"use strict";
module.exports=harmonize;
varchild_process=require("child_process");
/**
* Enables --harmony flags programmatically.
* @param {Array.<string>} [flags] Flags to enable, defaults to just `harmony`
* @returns {undefined}
* @property {Array.<string>} enabled Enabled flags
* @property {Array.<string>} supported Supported flags
*/
functionharmonize(flags){
// assume to be the spawned child if there are any enabled flags
if(harmonize.enabled.length)
return;
// default to just "harmony"
if(!Array.isArray(flags))
flags=["harmony"];
// filter out unsupported flags while adding hyphens
for(vari=0;i<flags.length;){
if(harmonize.supported.indexOf(flags[i])<0)
flags.splice(i,1);
else
flags[i]="--"+flags[i++];
}
// now just spawn a child with inherited stdio using the specified flags
child_process.spawn(process.argv[0],flags.concat(process.argv.slice(1)),{stdio: 'inherit'})
.on("close",function(code){
process.exit(code);
});
// and interrupt process flow in the parent (do not try this at home!)
process.once("uncaughtException",function(e){});
throw"harmony";
};
// Get enabled flags
harmonize.enabled=(function(){
varflags=[];
for(vari=0,match;i<process.execArgv.length;++i)
if(match=/\-\-(harmony[\w\-]*)/.exec(process.execArgv[i]))
flags.push(match[1]);
returnflags;
})();
// Get supported flags
harmonize.supported=(function(){
varflags=[];
varoutput=child_process.spawnSync(process.argv[0],["--v8-options"]).output.toString("utf8");
for(varre=/\-\-(harmony[\w\-]*)/g,match;match=re.exec(output);)
flags.push(match[1]);
returnflags;
})();