Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Migrating from process.binding('config') to getOptions
  • Loading branch information
burgerboydaddy authored and Trott committed Oct 22, 2018
commit 61b495a5c19580d72481e41c180d453f9de57979
10 changes: 5 additions & 5 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
setupQueueMicrotask();
}

if (process.binding('config').experimentalWorker) {
if (internalBinding('options').getOptions('--experimental-worker')) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you factor out the internalBinding into a single call up top and also save the flag calls as variables to be used later?

something like

const { getOptions } = internalBinding('options');
const experimentalModules = getOptions('experimentalModules');
// ...
if (experimentalModules) {
  // ...

Copy link
Copy Markdown
Contributor Author

@burgerboydaddy burgerboydaddy Oct 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will do that.
But one question. There is already some similar code in place, like line 114:

const options = internalBinding('options');
    if (options.getOptions('--help')) {
      NativeModule.require('internal/print_help').print(process.stdout);
      return;
    }

Should I redo that part also and change code to use as mentioned:

const { getOptions } = internalBinding('options');
const experimentalModules = getOptions('experimentalModules');
// ...
if (experimentalModules) {
  // ...

Thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in my previous comment, will code like this (replacing line 114) be Ok:

    const { getOptions } = internalBinding('options');
    const helpOption = getOptions('--help');
    const completionBashOption = getOptions('--completion-bash');
    const experimentalModulesOption = getOptions('--experimental-modules');
    const experimentalVMModulesOption = getOptions('--experimental-vm-modules');
    const experimentalWorkerOption = getOptions('--experimental-worker');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burgerboydaddy Yes, that definitely looks okay :)

setupDOMException();
}

Expand Down Expand Up @@ -169,9 +169,9 @@
'DeprecationWarning', 'DEP0062', startup, true);
}

if (process.binding('config').experimentalModules ||
process.binding('config').experimentalVMModules) {
if (process.binding('config').experimentalModules) {
if (internalBinding('options').getOptions('--experimental-modules') ||
internalBinding('options').getOptions('--experimental-vm-modules')) {
if (internalBinding('options').getOptions('--experimental-modules')) {
process.emitWarning(
'The ESM module loader is experimental.',
'ExperimentalWarning', undefined);
Expand All @@ -183,7 +183,7 @@
{
// Install legacy getters on the `util` binding for typechecking.
// TODO(addaleax): Turn into a full runtime deprecation.
const { pendingDeprecation } = process.binding('config');
const { pendingDeprecation } = internalBinding('options').getOptions();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burgerboydaddy I think something went wrong with this one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax initial request was to replace process.binding('config') to
internalBinding('options).getOptions(). Is there any reason why this line shouldn't be included?
If yes, I will restore this line to original one.
Please let me know what is your opinion.

thanks

const utilBinding = internalBinding('util');
const types = internalBinding('types');
for (const name of [
Expand Down