-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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] Implement System.Console.Clear #43002
Conversation
Tagging subscribers to this area: @dotnet/ncl |
@@ -74,6 +76,8 @@ public override void Flush() | |||
|
|||
internal static class ConsolePal | |||
{ | |||
private static readonly JSObject? s_console = (JSObject)System.Runtime.InteropServices.JavaScript.Runtime.GetGlobalObject("console"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Console.Clear
might not be used that much, I can move the initialization into Clear
itself if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer it happen in clear for now with a try catch that wraps the missing object exception just so we don't suddenly start throwing here if console is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing System.Runtime.InteropServices.JavaScript.Runtime.GetGlobalObject
did not throw an exception if the object does not exist, and just returns null
.
try
{
var abc = System.Runtime.InteropServices.JavaScript.Runtime.GetGlobalObject("abc");
if (abc is null) Console.WriteLine("abc is null");
else Console.WriteLine($"abc is {abc.GetType().FullName}");
}
catch (Exception ex)
{
Console.WriteLine($"{ex.GetType().FullName}: {ex.Message}\n{ex.StackTrace}");
}
logged
abc is null
Calling Invoke("clear")
would throw if the method does not exists:
System.Runtime.InteropServices.JavaScript.JSException: Error: Method: 'abc' not found for: '[object Object]'
Should this be catched and ignored?
Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@campersau thanks again for another catch. We're considering some more extensive changes for console in 6 but this doesn't need to wait for that. I'm curious if this has any size impact.
The failures here appear to be from #43037 |
53b1e8b
to
ec7710e
Compare
src/libraries/System.Console/src/System/ConsolePal.WebAssembly.cs
Outdated
Show resolved
Hide resolved
Failures are #43166 and unrelated to the change |
* [wasm] Implement System.Console.Clear * Add dummy console.clear implementation if it does not exist * Initialize console in Clear * Apply suggestions from codereview
In #41184 (comment) it was mentioned that
System.Console.Clear
should be implemented since now it is not marked asUnsupportedOSPlatformAttribute("browser")
but throwsPlatformNotSupportedException
.runtime/src/libraries/System.Console/src/System/ConsolePal.WebAssembly.cs
Line 166 in 271f008
So this PR does that by using the same code pattern as in
BrowserHttpClient
:runtime/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs
Line 32 in 271f008
runtime/src/libraries/System.Net.Http/src/System.Net.Http.csproj
Lines 722 to 724 in 271f008
Fixes mono/mono#19825