News for hackers. Stuff that matters.
Re:Math.Round opens the browser print dialog by tedunangst on Wednesday June 19, 2019 @07:00PM (#20228195)
What is the expected behavior from calling print()?
Re:Math.Round opens the browser print dialog by masswerk on Wednesday June 19, 2019 @11:39PM (#20229642)
The JavaScript function "window.print()" is expected to open a print dialog for the current document. Since "window" is also the global object for the main/UI thread in a browser, "print()" resolves to "window.print()", if no function has been defined otherwise. This is, BTW, also a potential issue in Emscripten, which uses a similar logging mechanism by a custom "print()" function. (I guess, this is also, where it came from in the WASM implementation. A few years ago, I actually replaced all references to "print" by a more safe name for a customized Emscripten runtime, in order to prevent similar from happening in any edge cases. I suggest to treat "print" and similar global function names just as if they were reserved words in your projects to avoid "expectable unexpecteds" like this. For similar reasons, using a variable "self" to store a reference to the current this-object isn't a great idea, since "self" is already the canonical reference to the global object…)

Edit: To be more specific, "window" is only the global object for the scripting context in a browser window (anything inside "script" tags). Meaning, you would have to use the full form, "window.print()", when calling the print function from outside this context, like inside an event handler attribute of an HTML tag. (E.g., '<button onclick="window.print()">Print page<button>'. Here, a simple "print()" wouldn't work.)

Re:Math.Round opens the browser print dialog by komali2 on Wednesday June 19, 2019 @07:11PM (#20228263)
A globally defined print function is invoked I guess? It's weird for me to see it in the raw like that instead of this.print or errorController.print or this.emit('error', error) or just throw(error)...
Re:Math.Round opens the browser print dialog by AgentME on Wednesday June 19, 2019 @07:57PM (#20228536)
Calling print() opens a print dialog in Javascript. The error-handling code in this project is doing the wrong thing. It's not an example of a wild Javascript-specific error, just an example of untested error handling code doing the wrong thing.