📜 ⬆️ ⬇️

Why Math.Round opens a print window from a browser in Try .NET

Today, the public’s attention was drawn by a funny, illogical bug found in Try .NET , a tool designed to embed interactive C # examples into the documentation. See the open issue on Github at the link .

The above code, when executed (when calling the Math.Round method) instead of the expected result, suddenly opens a print window from the browser:

using System; public class Example { public static void Main() { var x = Math.Round(11.1, MidpointRounding.AwayFromZero); } } 


image
')
With the help of error error and breakpoint users found the alleged reason for this behavior - it was hidden in the mono.js library.

image

The answer is simple. Apparently, someone wanted to use his own print () function in JS (or confused it with console.log ), but since such was not found in the scope, the program calls window.print () , which really should open the current print window Document - since window is a global object for the main thread in the browser.

This folbek was not immediately noticed, but one of the users claims that this error was corrected last November .

In order to avoid situations in which errors of this kind arise, the create-react-app project keeps a list of “confusing” browser global variables , since it is quite simple to make a similar error:

 handleClick() { //   `event` this.setState({ text: event.target.value //    `event`- ! }); } 

Source: https://habr.com/ru/post/456880/


All Articles