Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: refactor the bootstrap mode branching for readability #24673

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

This patch refactors the branches for choosing the mode to run
Node.js in internal/bootstrap/node.js. Instead of inlining the
decision making all in startup, we create a startExecution()
function which either detects and start the non-user-code mode,
or prepares for user code execution (worker setup, preloading modules)
and starts user code execution.
We use early returns when we decide the mode to run Node.js in for fewer
indentations and better readability.

This patch also adds a few comments about the command-line switches
and a few TODOs to remove underscore properties on process that
are mainly used for bootstrap mode branching. It also includes
a few other refactoring such as inlining functions/variables
that are not reused and removing the default argument of
evalScript for better clarity.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot
Copy link
Collaborator

@joyeecheung sadly an error occured when I tried to trigger a build :(

@@ -12,4 +12,4 @@ RangeError: Invalid input
at tryModuleLoad (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at startup (internal/bootstrap/node.js:*:*)
Copy link
Member Author

Choose a reason for hiding this comment

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

These stack frames are truncated because we have a default Error.stackTraceLimit = 10. Makes me wonder again that we probably should implement #20505

Copy link
Member

Choose a reason for hiding this comment

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

i can put it on the list of things to add once #23926 is complete

@joyeecheung
Copy link
Member Author

joyeecheung commented Nov 27, 2018

cc @devsnek @addaleax @nodejs/process

For ease of review please use https://github.com/nodejs/node/pull/24673/files?w=1 to skip the indentation changes

Copy link
Member

@devsnek devsnek left a comment

Choose a reason for hiding this comment

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

looks pretty good, i'm a fan of the new function names

@danbev
Copy link
Contributor

danbev commented Nov 28, 2018

@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 28, 2018
This patch refactors the branches for choosing the mode to run
Node.js in `internal/bootstrap/node.js`. Instead of inlining the
decision making all in `startup`, we create a `startExecution()`
function which either detects and start the non-user-code mode,
or prepares for user code execution (worker setup, preloading modules)
and starts user code execution.
We use early returns when we decide the mode to run Node.js in for fewer
indentations and better readability.

This patch also adds a few comments about the command-line switches
and a few TODOs to remove underscore properties on `process` that
are mainly used for bootstrap mode branching. It also includes
a few other refactoring such as inlining functions/variables
that are not reused and removing the default argument of
`evalScript` for better clarity.
@joyeecheung
Copy link
Member Author

Rebased for the recent arrow function changes in node.js.
CI: https://ci.nodejs.org/job/node-test-pull-request/19042/

@@ -9,7 +9,7 @@ SyntaxError: Strict mode code may not include a with statement
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
at evalScript (internal/bootstrap/node.js:*:*)
at Socket.<anonymous> (internal/bootstrap/node.js:*:*)
at Socket.process.stdin.on (internal/bootstrap/node.js:*:*)
Copy link
Member Author

Choose a reason for hiding this comment

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

Fun fact: somehow this change and the arrow function change help V8 infer the name of the process stdin callbacks

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Nice!

@Trott
Copy link
Member

Trott commented Nov 29, 2018

@Trott
Copy link
Member

Trott commented Nov 29, 2018

@Trott
Copy link
Member

Trott commented Nov 29, 2018

Landed in 7b8058a

@Trott Trott closed this Nov 29, 2018
Trott pushed a commit to Trott/io.js that referenced this pull request Nov 29, 2018
This patch refactors the branches for choosing the mode to run
Node.js in `internal/bootstrap/node.js`. Instead of inlining the
decision making all in `startup`, we create a `startExecution()`
function which either detects and start the non-user-code mode,
or prepares for user code execution (worker setup, preloading modules)
and starts user code execution.
We use early returns when we decide the mode to run Node.js in for fewer
indentations and better readability.

This patch also adds a few comments about the command-line switches
and a few TODOs to remove underscore properties on `process` that
are mainly used for bootstrap mode branching. It also includes
a few other refactoring such as inlining functions/variables
that are not reused and removing the default argument of
`evalScript` for better clarity.

PR-URL: nodejs#24673
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
BridgeAR pushed a commit that referenced this pull request Dec 5, 2018
This patch refactors the branches for choosing the mode to run
Node.js in `internal/bootstrap/node.js`. Instead of inlining the
decision making all in `startup`, we create a `startExecution()`
function which either detects and start the non-user-code mode,
or prepares for user code execution (worker setup, preloading modules)
and starts user code execution.
We use early returns when we decide the mode to run Node.js in for fewer
indentations and better readability.

This patch also adds a few comments about the command-line switches
and a few TODOs to remove underscore properties on `process` that
are mainly used for bootstrap mode branching. It also includes
a few other refactoring such as inlining functions/variables
that are not reused and removing the default argument of
`evalScript` for better clarity.

PR-URL: #24673
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Dec 5, 2018
4 tasks
refack pushed a commit to refack/node that referenced this pull request Jan 14, 2019
This patch refactors the branches for choosing the mode to run
Node.js in `internal/bootstrap/node.js`. Instead of inlining the
decision making all in `startup`, we create a `startExecution()`
function which either detects and start the non-user-code mode,
or prepares for user code execution (worker setup, preloading modules)
and starts user code execution.
We use early returns when we decide the mode to run Node.js in for fewer
indentations and better readability.

This patch also adds a few comments about the command-line switches
and a few TODOs to remove underscore properties on `process` that
are mainly used for bootstrap mode branching. It also includes
a few other refactoring such as inlining functions/variables
that are not reused and removing the default argument of
`evalScript` for better clarity.

PR-URL: nodejs#24673
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants