|
616 | 616 | // This builds process.allowedNodeEnvironmentFlags
|
617 | 617 | // from data in the config binding
|
618 | 618 |
|
619 |
| - const replaceDashesRegex = /-/g; |
| 619 | + const replaceUnderscoresRegex = /_/g; |
620 | 620 | const leadingDashesRegex = /^--?/;
|
621 | 621 | const trailingValuesRegex = /=.*$/;
|
622 | 622 |
|
|
628 | 628 | const get = () => {
|
629 | 629 | const {
|
630 | 630 | getOptions,
|
631 |
| - types: { kV8Option }, |
632 | 631 | envSettings: { kAllowedInEnvironment }
|
633 | 632 | } = internalBinding('options');
|
634 | 633 | const { options, aliases } = getOptions();
|
635 | 634 |
|
636 |
| - const allowedV8EnvironmentFlags = []; |
637 | 635 | const allowedNodeEnvironmentFlags = [];
|
638 | 636 | for (const [name, info] of options) {
|
639 | 637 | if (info.envVarSettings === kAllowedInEnvironment) {
|
640 |
| - if (info.type === kV8Option) { |
641 |
| - allowedV8EnvironmentFlags.push(name); |
642 |
| - } else { |
643 |
| - allowedNodeEnvironmentFlags.push(name); |
644 |
| - } |
| 638 | + allowedNodeEnvironmentFlags.push(name); |
645 | 639 | }
|
646 | 640 | }
|
647 | 641 |
|
|
675 | 669 | // process.allowedNodeEnvironmentFlags.has() which lack leading dashes.
|
676 | 670 | // Avoid interference w/ user code by flattening `Set.prototype` into
|
677 | 671 | // each object.
|
678 |
| - const [nodeFlags, v8Flags] = [ |
679 |
| - allowedNodeEnvironmentFlags, allowedV8EnvironmentFlags |
680 |
| - ].map((flags) => Object.defineProperties( |
681 |
| - new Set(flags.map(trimLeadingDashes)), |
682 |
| - Object.getOwnPropertyDescriptors(Set.prototype)) |
| 672 | + const nodeFlags = Object.defineProperties( |
| 673 | + new Set(allowedNodeEnvironmentFlags.map(trimLeadingDashes)), |
| 674 | + Object.getOwnPropertyDescriptors(Set.prototype) |
683 | 675 | );
|
684 | 676 |
|
685 | 677 | class NodeEnvironmentFlagsSet extends Set {
|
|
703 | 695 | has(key) {
|
704 | 696 | // This will return `true` based on various possible
|
705 | 697 | // permutations of a flag, including present/missing leading
|
706 |
| - // dash(es) and/or underscores-for-dashes in the case of V8-specific |
707 |
| - // flags. Strips any values after `=`, inclusive. |
| 698 | + // dash(es) and/or underscores-for-dashes. |
| 699 | + // Strips any values after `=`, inclusive. |
708 | 700 | // TODO(addaleax): It might be more flexible to run the option parser
|
709 | 701 | // on a dummy option set and see whether it rejects the argument or
|
710 | 702 | // not.
|
711 | 703 | if (typeof key === 'string') {
|
712 |
| - key = replace(key, trailingValuesRegex, ''); |
| 704 | + key = replace(key, replaceUnderscoresRegex, '-'); |
713 | 705 | if (test(leadingDashesRegex, key)) {
|
714 |
| - return has(this, key) || |
715 |
| - has(v8Flags, |
716 |
| - replace( |
717 |
| - replace( |
718 |
| - key, |
719 |
| - leadingDashesRegex, |
720 |
| - '' |
721 |
| - ), |
722 |
| - replaceDashesRegex, |
723 |
| - '_' |
724 |
| - ) |
725 |
| - ); |
| 706 | + key = replace(key, trailingValuesRegex, ''); |
| 707 | + return has(this, key); |
726 | 708 | }
|
727 |
| - return has(nodeFlags, key) || |
728 |
| - has(v8Flags, replace(key, replaceDashesRegex, '_')); |
| 709 | + return has(nodeFlags, key); |
729 | 710 | }
|
730 | 711 | return false;
|
731 | 712 | }
|
|
736 | 717 |
|
737 | 718 | return process.allowedNodeEnvironmentFlags = Object.freeze(
|
738 | 719 | new NodeEnvironmentFlagsSet(
|
739 |
| - allowedNodeEnvironmentFlags.concat(allowedV8EnvironmentFlags) |
| 720 | + allowedNodeEnvironmentFlags |
740 | 721 | ));
|
741 | 722 | };
|
742 | 723 |
|
|
0 commit comments