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
Poor code quality of window.console.dir #17508
Comments
There are multiple issues here.
It is surprisingly difficult to optimize a lazy initializer. In the general case a lazy initializer can fail (throw) forcing a null value. At the time we do global type analysis we don't have sufficient information to tell the initializer can never fail, so we can't remove null from the type, forcing the null guard.
All this code comes from inlining on this basic body: C.Window_methods.get$console(get$window()).dir$1(e); I think inlining Console.dir is a mistake. We replaced a call with a null guard and the body of the callee. The body of the callee could not be optimized in the new context. There is no performance benefit since the JavaScript engine likely inlines the monomorphic call anyway. Something like the following is probably the best compromise given the current source: window; If we could pre-initialize Console._safeConsole: window; Window get window => JS('Window', 'window'); class Window ... class Console { Added Library-Html label. |
cc @kmillikin. |
re: Stephen's first question -- I haven't ever worked on the internals of the (window.)console code so I don't know that we've added any error messages indicating "debug" is not available on specific browsers. Is this something we should add? |
https://chromiumcodereview.appspot.com/202983002/ addresses points 1. and 2. from comment #1 window; ---> Set owner to @rakudrama. |
Are the improvements good enough to close this issue? Added NeedsInfo label. |
Set owner to @peter-ahe-google. |
The new version isn't callable from a Worker. This one works like a charm from a Worker, and works in IE9: function dir(o) { !!self.console && self.console.dir(o) } (if you know where to find the worker's console). I believe we could get there relatively easily:
void dir(Object arg) => _isConsoleDefined ? to: void dir(Object arg) => JS('', '# && self.console.dir(#)', _isConsoleDefined, arg);
bool get _isConsoleDefined => JS('bool', 'typeof console != "undefined"'); to: bool get _isConsoleDefined => JS('bool', '!!self.console'); Set owner to @rakudrama. |
Part of this issue has been fixed, but at this point it seems unlikely we'll have a chance to revisit. We can reopen this issue if it causes problems down the road. |
onSelect(Event e) {
window.console.dir(e);
}
Compiles to:
function(e) {
window;
$.get$Console__safeConsole().toString;
if (typeof console != "undefined")
console.debug(e);
}
This is code is pretty awful compared to what I would have written myself:
function(e) {
!!self.console && self.console.dir(e)
}
I'm also puzzled why console.debug is used. But perhaps console.debug and console.dir are the same. If so, dir is shorter.
The text was updated successfully, but these errors were encountered: