|
619 | 619 | consthas=Function.call.bind(Set.prototype.has); |
620 | 620 | consttest=Function.call.bind(RegExp.prototype.test); |
621 | 621 |
|
622 | | -const{ |
623 | | - getOptions, |
624 | | -types: { kV8Option }, |
625 | | -envSettings: { kAllowedInEnvironment } |
626 | | -}=internalBinding('options'); |
627 | | -const{ options, aliases }=getOptions(); |
628 | | - |
629 | | -constallowedV8EnvironmentFlags=[]; |
630 | | -constallowedNodeEnvironmentFlags=[]; |
631 | | -for(const[name,info]ofoptions){ |
632 | | -if(info.envVarSettings===kAllowedInEnvironment){ |
633 | | -if(info.type===kV8Option){ |
634 | | -allowedV8EnvironmentFlags.push(name); |
635 | | -}else{ |
636 | | -allowedNodeEnvironmentFlags.push(name); |
| 622 | +constget=()=>{ |
| 623 | +const{ |
| 624 | + getOptions, |
| 625 | +types: { kV8Option }, |
| 626 | +envSettings: { kAllowedInEnvironment } |
| 627 | +}=internalBinding('options'); |
| 628 | +const{ options, aliases }=getOptions(); |
| 629 | + |
| 630 | +constallowedV8EnvironmentFlags=[]; |
| 631 | +constallowedNodeEnvironmentFlags=[]; |
| 632 | +for(const[name,info]ofoptions){ |
| 633 | +if(info.envVarSettings===kAllowedInEnvironment){ |
| 634 | +if(info.type===kV8Option){ |
| 635 | +allowedV8EnvironmentFlags.push(name); |
| 636 | +}else{ |
| 637 | +allowedNodeEnvironmentFlags.push(name); |
| 638 | +} |
637 | 639 | } |
638 | 640 | } |
639 | | -} |
640 | 641 |
|
641 | | -for(const[from,expansion]ofaliases){ |
642 | | -letisAccepted=true; |
643 | | -for(consttoofexpansion){ |
644 | | -if(!to.startsWith('-'))continue; |
645 | | -constrecursiveExpansion=aliases.get(to); |
646 | | -if(recursiveExpansion){ |
647 | | -expansion.push(...recursiveExpansion); |
648 | | -continue; |
| 642 | +for(const[from,expansion]ofaliases){ |
| 643 | +letisAccepted=true; |
| 644 | +for(consttoofexpansion){ |
| 645 | +if(!to.startsWith('-'))continue; |
| 646 | +constrecursiveExpansion=aliases.get(to); |
| 647 | +if(recursiveExpansion){ |
| 648 | +expansion.push(...recursiveExpansion); |
| 649 | +continue; |
| 650 | +} |
| 651 | +isAccepted=options.get(to).envVarSettings===kAllowedInEnvironment; |
| 652 | +if(!isAccepted)break; |
| 653 | +} |
| 654 | +if(isAccepted){ |
| 655 | +letcanonical=from; |
| 656 | +if(canonical.endsWith('=')) |
| 657 | +canonical=canonical.substr(0,canonical.length-1); |
| 658 | +if(canonical.endsWith(' <arg>')) |
| 659 | +canonical=canonical.substr(0,canonical.length-4); |
| 660 | +allowedNodeEnvironmentFlags.push(canonical); |
649 | 661 | } |
650 | | -isAccepted=options.get(to).envVarSettings===kAllowedInEnvironment; |
651 | | -if(!isAccepted)break; |
652 | | -} |
653 | | -if(isAccepted){ |
654 | | -letcanonical=from; |
655 | | -if(canonical.endsWith('=')) |
656 | | -canonical=canonical.substr(0,canonical.length-1); |
657 | | -if(canonical.endsWith(' <arg>')) |
658 | | -canonical=canonical.substr(0,canonical.length-4); |
659 | | -allowedNodeEnvironmentFlags.push(canonical); |
660 | 662 | } |
661 | | -} |
662 | 663 |
|
663 | | -consttrimLeadingDashes=(flag)=>replace(flag,leadingDashesRegex,''); |
664 | | - |
665 | | -// Save these for comparison against flags provided to |
666 | | -// process.allowedNodeEnvironmentFlags.has() which lack leading dashes. |
667 | | -// Avoid interference w/ user code by flattening `Set.prototype` into |
668 | | -// each object. |
669 | | -const[nodeFlags,v8Flags]=[ |
670 | | -allowedNodeEnvironmentFlags,allowedV8EnvironmentFlags |
671 | | -].map((flags)=>Object.defineProperties( |
672 | | -newSet(flags.map(trimLeadingDashes)), |
673 | | -Object.getOwnPropertyDescriptors(Set.prototype)) |
674 | | -); |
675 | | - |
676 | | -classNodeEnvironmentFlagsSetextendsSet{ |
677 | | -constructor(...args){ |
678 | | -super(...args); |
679 | | - |
680 | | -// the super constructor consumes `add`, but |
681 | | -// disallow any future adds. |
682 | | -this.add=()=>this; |
683 | | -} |
| 664 | +consttrimLeadingDashes=(flag)=>replace(flag,leadingDashesRegex,''); |
| 665 | + |
| 666 | +// Save these for comparison against flags provided to |
| 667 | +// process.allowedNodeEnvironmentFlags.has() which lack leading dashes. |
| 668 | +// Avoid interference w/ user code by flattening `Set.prototype` into |
| 669 | +// each object. |
| 670 | +const[nodeFlags,v8Flags]=[ |
| 671 | +allowedNodeEnvironmentFlags,allowedV8EnvironmentFlags |
| 672 | +].map((flags)=>Object.defineProperties( |
| 673 | +newSet(flags.map(trimLeadingDashes)), |
| 674 | +Object.getOwnPropertyDescriptors(Set.prototype)) |
| 675 | +); |
684 | 676 |
|
685 | | -delete(){ |
686 | | -// noop, `Set` API compatible |
687 | | -returnfalse; |
688 | | -} |
| 677 | +classNodeEnvironmentFlagsSetextendsSet{ |
| 678 | +constructor(...args){ |
| 679 | +super(...args); |
689 | 680 |
|
690 | | -clear(){ |
691 | | -// noop |
692 | | -} |
| 681 | +// the super constructor consumes `add`, but |
| 682 | +// disallow any future adds. |
| 683 | +this.add=()=>this; |
| 684 | +} |
693 | 685 |
|
694 | | -has(key){ |
695 | | -// This will return `true` based on various possible |
696 | | -// permutations of a flag, including present/missing leading |
697 | | -// dash(es) and/or underscores-for-dashes in the case of V8-specific |
698 | | -// flags. Strips any values after `=`, inclusive. |
699 | | -// TODO(addaleax): It might be more flexible to run the option parser |
700 | | -// on a dummy option set and see whether it rejects the argument or |
701 | | -// not. |
702 | | -if(typeofkey==='string'){ |
703 | | -key=replace(key,trailingValuesRegex,''); |
704 | | -if(test(leadingDashesRegex,key)){ |
705 | | -returnhas(this,key)|| |
706 | | -has(v8Flags, |
707 | | -replace( |
| 686 | +delete(){ |
| 687 | +// noop, `Set` API compatible |
| 688 | +returnfalse; |
| 689 | +} |
| 690 | + |
| 691 | +clear(){ |
| 692 | +// noop |
| 693 | +} |
| 694 | + |
| 695 | +has(key){ |
| 696 | +// This will return `true` based on various possible |
| 697 | +// permutations of a flag, including present/missing leading |
| 698 | +// dash(es) and/or underscores-for-dashes in the case of V8-specific |
| 699 | +// flags. Strips any values after `=`, inclusive. |
| 700 | +// TODO(addaleax): It might be more flexible to run the option parser |
| 701 | +// on a dummy option set and see whether it rejects the argument or |
| 702 | +// not. |
| 703 | +if(typeofkey==='string'){ |
| 704 | +key=replace(key,trailingValuesRegex,''); |
| 705 | +if(test(leadingDashesRegex,key)){ |
| 706 | +returnhas(this,key)|| |
| 707 | +has(v8Flags, |
708 | 708 | replace( |
709 | | -key, |
710 | | -leadingDashesRegex, |
711 | | -'' |
712 | | -), |
713 | | -replaceDashesRegex, |
714 | | -'_' |
715 | | -) |
716 | | -); |
| 709 | +replace( |
| 710 | +key, |
| 711 | +leadingDashesRegex, |
| 712 | +'' |
| 713 | +), |
| 714 | +replaceDashesRegex, |
| 715 | +'_' |
| 716 | +) |
| 717 | +); |
| 718 | +} |
| 719 | +returnhas(nodeFlags,key)|| |
| 720 | +has(v8Flags,replace(key,replaceDashesRegex,'_')); |
717 | 721 | } |
718 | | -returnhas(nodeFlags,key)|| |
719 | | -has(v8Flags,replace(key,replaceDashesRegex,'_')); |
| 722 | +returnfalse; |
720 | 723 | } |
721 | | -returnfalse; |
722 | 724 | } |
723 | | -} |
724 | 725 |
|
725 | | -Object.freeze(NodeEnvironmentFlagsSet.prototype.constructor); |
726 | | -Object.freeze(NodeEnvironmentFlagsSet.prototype); |
| 726 | +Object.freeze(NodeEnvironmentFlagsSet.prototype.constructor); |
| 727 | +Object.freeze(NodeEnvironmentFlagsSet.prototype); |
| 728 | + |
| 729 | +returnprocess.allowedNodeEnvironmentFlags=Object.freeze( |
| 730 | +newNodeEnvironmentFlagsSet( |
| 731 | +allowedNodeEnvironmentFlags.concat(allowedV8EnvironmentFlags) |
| 732 | +)); |
| 733 | +}; |
727 | 734 |
|
728 | | -process.allowedNodeEnvironmentFlags=Object.freeze( |
729 | | -newNodeEnvironmentFlagsSet( |
730 | | -allowedNodeEnvironmentFlags.concat(allowedV8EnvironmentFlags) |
731 | | -) |
732 | | -); |
| 735 | +Object.defineProperty(process,'allowedNodeEnvironmentFlags',{ |
| 736 | + get, |
| 737 | +set(value){ |
| 738 | +Object.defineProperty(this,'allowedNodeEnvironmentFlags',{ |
| 739 | + value, |
| 740 | +configurable: true, |
| 741 | +enumerable: true, |
| 742 | +writable: true |
| 743 | +}); |
| 744 | +}, |
| 745 | +enumerable: true, |
| 746 | +configurable: true |
| 747 | +}); |
733 | 748 | } |
734 | 749 |
|
735 | 750 | startup(); |
|
0 commit comments