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

Modernize the webserver code (part 1) #17661

Merged
merged 4 commits into from
Feb 12, 2024

Conversation

timvandermeij
Copy link
Contributor

The commit messages contain more details about the individual changes. This first part mainly focuses on extracting self-contained functionality from the large handler method to make it more manageable and to get rid of using variables from the outer scope (with the end goal of enabling the no-var rule for this file).

The first and last commits should be reviewed with the ?w=1 flag for an easier diff.

The `handler` method contained this code in an inline function, which
made the `handler` method big and harder to read. Moreover, this code
relied on variables from the outer scope, which made it harder to reason
about because the inputs and outputs weren't easily visible.

This commit fixes the problems by extracting the file serving code into
a dedicated private method, and modernizing it to use e.g. `const`/`let`
instead of `var` and using template strings.
The `handler` method contained this code in an inline function, which
made the `handler` method big and harder to read. Moreover, this code
relied on variables from the outer scope, which made it harder to reason
about because the inputs and outputs weren't easily visible.

This commit fixes the problems by extracting the range file serving code
into a dedicated private method, and modernizing it to use e.g. `const`/
`let` instead of `var` and using template strings.
test/webserver.mjs Outdated Show resolved Hide resolved
test/webserver.mjs Fixed Show fixed Hide fixed
@timvandermeij
Copy link
Contributor Author

The changes since the original commits are easiest to view with the interdiff in no-whitespace mode: https://github.com/mozilla/pdf.js/compare/af5764273b29b2e34ead0b54bfefe3ca912fedd1..935e8c8c5bec6cb1e36d8976780ca2d61e9118f2?w=1.

I made the following changes:

  • Use fsPromises.readdir instead of fs.readdir and making the method asynchronous.
  • Use for/of loop for the files instead of files.forEach.
  • Moved all and escapeHTML down in the method to have the definition closer to where it's actually used.
  • Introduced a couple of newlines to visually separate blocks of logic in the method for better readability.

test/webserver.mjs Dismissed Show dismissed Hide dismissed
test/webserver.mjs Outdated Show resolved Hide resolved
The `handler` method contained this code in an inline function, which
made the `handler` method big and harder to read. Moreover, this code
relied on variables from the outer scope, which made it harder to reason
about because the inputs and outputs weren't easily visible.

This commit fixes the problems by extracting the directory listing code
into a dedicated private method, and modernizing it to use e.g. `const`/
`let` instead of `var` and using template strings.
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

I've tested this locally and everything seems to work just as before.

r=me, thank you!

@Snuffleupagus
Copy link
Collaborator

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/46d9eddfe1f86c7/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/69b208165afe520/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/46d9eddfe1f86c7/output.txt

Total script time: 24.67 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 16
  different first/second rendering: 2

Image differences available at: http://54.241.84.105:8877/46d9eddfe1f86c7/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/69b208165afe520/output.txt

Total script time: 41.61 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 4

Image differences available at: http://54.193.163.58:8877/69b208165afe520/reftest-analyzer.html#web=eq.log

@Snuffleupagus Snuffleupagus merged commit 18959e8 into mozilla:master Feb 12, 2024
7 checks passed
@timvandermeij timvandermeij deleted the modernize-webserver branch February 17, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants