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

[WASM] Normalize runtime-test.js #54281

Closed
wants to merge 19 commits into from

Conversation

Daniel-Genkin
Copy link
Contributor

@Daniel-Genkin Daniel-Genkin commented Jun 16, 2021

Work in Progress

This PR aims to reorganize runtime-test.js and add the framework for the follow up PR which will add NodeJS support to WASM!

Why is this needed

The runtime-test.js file is currently an amalgamation of functions and glue code that makes it hard to understand and hard to work with. The primary goal of this PR is to essentially refactor it such that it maintains the same functionality but in a more readable way. The most heavily affected aspect of the file is the way IO is handled. The secondary goal is to add the is_node variable along with require and other node specific methods for doing various operations which would be useful later on when adding NodeJS support to WASM.

What's changed

  • The readability of runtime-test.js
    • There is now a new IOHandler object which abstracts all IO related operations and offers simple async load, read and fetch functions.
    • All related code snippets are closer together now
    • Unused/redundant variables have been removed
    • All var have been updated to be either let or const
  • A basic framework for nodejs support has been added to runtime-test.js

@ghost
Copy link

ghost commented Jun 16, 2021

Tagging subscribers to this area: @directhex
See info in area-owners.md if you want to be subscribed.

Issue Details

Work in Progress

This PR aims to reorganize runtime-test.js and add the framework for the follow up PR which will add NodeJS support to WASM!

Why is this needed

The runtime-test.js file is currently an amalgamation of functions and glue code that makes it hard to understand and hard to work with. The primary goal of this PR is to essentially refactor it such that it maintains the same functionality but in a more readable way. The most heavily affected aspect of the file is the way IO is handled. The secondary goal is to add the is_node variable along with require and other node specific methods for doing various operations which would be useful later on when adding NodeJS support to WASM.

What's changed

  • The readability of runtime-test.js
    • There is now a new IOHandler object which abstracts all IO related operations and offers simple async load and read functions.
    • All related code snippets are closer together now
    • Unused/redundant variables have been removed
    • All var have been update to be either let or const
  • A basic framework for nodejs support has been added to runtime-test.js
Author: Daniel-Genkin
Assignees: -
Labels:

area-Infrastructure-mono

Milestone: -

@ghost ghost added this to In Progress in Infrastructure Backlog Jun 16, 2021
@Daniel-Genkin
Copy link
Contributor Author

/azp run runtime

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 54281 in repo dotnet/runtime

@thaystg
Copy link
Member

thaystg commented Jun 16, 2021

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Daniel-Genkin Daniel-Genkin marked this pull request as ready for review June 16, 2021 18:45
@thaystg thaystg requested review from lewing, kg and radical June 17, 2021 03:14
@@ -49,28 +47,16 @@ if (is_browser) {
let consoleWebSocket = new WebSocket(consoleUrl);
consoleWebSocket.onopen = function(event) {
proxyJson(function (msg) { consoleWebSocket.send (msg); });
globalThis.testConsole.log("browser: Console websocket connected.");
console.log("browser: Console websocket connected.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Not opposed to this, but do you know whether there were specific use cases for testConsole that won't be addressed as a result of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see any uses for it when I did a search within the repo but I am not entirely sure. Could it be referenced indirectly somehow from C#? Although looks like the tests pass, so it probably isn't used anywhere.

Also this was a change that Larry did in his PR upon which this one is loosely based. @lewing do you know if this is used anywhere besides this file?

Copy link
Contributor

@kg kg left a comment

Choose a reason for hiding this comment

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

Looks good otherwise

src/mono/wasm/runtime-test.js Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime-test.js Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

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

some formatting issues

src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
src/mono/wasm/runtime-test.js Outdated Show resolved Hide resolved
@Daniel-Genkin Daniel-Genkin mentioned this pull request Jun 22, 2021
9 tasks
resolve (response);
})
}
return IOHandler.fetch (asset, { credentials: 'same-origin' });
Copy link
Member

Choose a reason for hiding this comment

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

Missing .catch ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure that when this is used (library-mono.js line 1950) the surrounding try catch block handles this.

try {
  if (asset.name === attemptUrl) {
    if (ctx.tracing)
        console.log ("Attempting to fetch '" + attemptUrl + "'");
  } else {
    if (ctx.tracing)
      console.log ("Attempting to fetch '" + attemptUrl + "' for", asset.name);
  }
  var fetch_promise = fetch_file_cb (attemptUrl);
  fetch_promise.then (handleFetchResponse);
} catch (exc) {
  console.error ("MONO_WASM: Error fetching " + attemptUrl, exc);
  attemptNextSource ();
}

@SamMonoRT
Copy link
Member

Looking at the changes, don't believe there will be any perf implications. Am I correct ?

@Daniel-Genkin
Copy link
Contributor Author

Looking at the changes, don't believe there will be any perf implications. Am I correct ?

This is mostly just for readability and to add the is_node variable. There shouldn't be any performance implications

@Daniel-Genkin
Copy link
Contributor Author

Closing PR to save time as the NodeJS PR (#54640 ) includes all these changes

Infrastructure Backlog automation moved this from In Progress to Done Jul 9, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants