-
Notifications
You must be signed in to change notification settings - Fork 70
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
Static console functions / binding #3
Comments
👍 This is very convenient when you want to log the output of a callback |
I don't think any browsers currently support this, although Node.js does. I think it's sensible, but I think we'd have some work to do before getting it in browsers:
|
FYI. |
I'd be happy to try to revisit WebKit and Blink implementations for bound console.log and its siblings if the standard goes in that direction. I'm still a bit annoyed when I can't pass console.log as a callback when debugging or feeling my way around new browser features, so I'd be sufficiently motivated to get it implemented. |
Chrome DevTools team discussed this yesterday and it's doable though more work than it appears to be. These methods are implemented in native, rather than JS. We may fix this in the next few months, though we'd be happy for your help with it @pwnall |
@paulirish one approach that the spec might consider is to change the IDL from [NoInterfaceObject]
interface Console {
void assert(boolean condition, optional any message);
void clear();
...
};
partial interface Window {
attribute Console console;
}; to // [NoInterfaceObject is gone]
interface console { // note lowercase
static void assert(boolean condition, optional any message);
static void clear();
};
// no need for adding it to Window explicitly This would change things slightly: The alternative would be custom bindings of a sort. |
@paulirish @domenic Is this definitely going to happen in spec-land? I'm asking to make sure I don't waste effort trying to implement it. If so, I can probably find some time in the second half of February. Also, 🎆 |
@pwnall well, specs are driven by implementation willingness, so that question is kind of backward. If we can get at least two implementations to pledge to implement something then we can in good conscience put it in the spec. |
a typical chicken-egg situation. :) @frewsxcv what do you think about it in regard to FF? |
For the record, I'm not in any way associated with Mozilla, other than occasional volunteer contributions for Servo. I'll link this thread to the Servo/Firefox people hoping someone more official will answer. |
Apparently we (Firefox) used to do this. I found this: https://bugzilla.mozilla.org/show_bug.cgi?id=989619 I can't speak for my team (devtools) but I bet most people would be fine with this. My coworker also filed this bug a while bug on a (seemingly defunct) different console repo: DeveloperToolsWG/console-object#27 |
OK, so as discussed in #1 (comment) and the related mailing list thread, this issue is kind of the biggest outstanding issue on this repo. And it's essentially blocked on implementer interest. Web developers really want this, as can be seen from previous discussions. My sketch in #1 (comment) shows how this can be done without any custom IDL bindings, which should ease the burden on implementers. But we still need at the very least explicit signals from two implementers that they are willing to do the work. It seems like from #3 (comment) there's some support from Chrome, on the timeline of a few months, and in https://lists.w3.org/Archives/Public/public-whatwg-archive/2016Feb/0007.html it seems like @bzbarsky voiced support if someone can volunteer to do the work in Firefox. I wouldn't say this is enough support to conclusively change the spec yet though... it would be different if someone from Firefox could commit to doing the work. Any thoughts from Safari (@hober?) or Microsoft (@travisleithead?)? |
If this is implementable with only copying webidl, it seems like it could be a "good first bug" for Firefox that @bzbarsky could mentor, maybe? Is there a bug filed? Just changing the spec could also get the ball rolling... |
This is not a "good first bug". It requires some tricky under-the-hood changes to the console implementation in Gecko (due to no longer having an actual Console object), and especially to its interactions with memory management and the garbage collector. It wouldn't be so bad if console only existed on the main thread, but its existence on workers, and the ensuing need to communicate to the main-thread console, make all this very much not a "good first bug". So the real problem on the Gecko end is that the set of people who could quickly (a few days of work) fix this is very limited and they're all busy with other things... |
I don't know the Gecko internals, but would be it possible to make this an implementation detail for now? (like, leave Console object, but auto-bind methods when exposing) |
That would be even harder, with a smaller pool of people who can do it, actually; all that stuff is completely automated right now via the bindings generator and would require some fundamental changes to the generator to introduce that sort of hack. Anyway, my points are: 1) this is not something we're likely to prototype quickly, and hence not likely to invest effort into unless we're pretty sure it should be done. 2) Even once we're sure it should be done it's likely to take a few months to get to it. |
@bzbarsky would "we're pretty sure it should be done" be influenced by changing the spec? I'd prefer to be conservative and not change without implementer support, but I recognize there's a potential chicken-egg problem here, depending on how adventurous implementers are feeling. |
Probably not; it would be influenced by other implementors committing to doing it... |
Is this situation substantially different from, say, |
@foolip I think the difference is largely that developers have been asking for this for a long time, and behaviors in old-Firefox and in Node.js influenced them to expect it. The common case is |
Oh, Node.js, I skimmed past that. Going with statics would make it similar to |
ToT Chromium supports calls to console related methods without console: crbug.com/167911 is fixed. |
Er, with what behavior? Is there still a |
Woah. Browsing https://codereview.chromium.org/1859293002 it looks like they've made major changes which are not at all aligned with other browsers, like moving to a data property instead of a getter/replaceable setter on the prototype. That seems quite bad. I can't tell about |
@domenic Can you talk to whoever is involved and figure out what the story is, please? ;) |
Replaceable in what sense? In Gecko you can set There shouldn't be any getters/setters here, because Console has no attributes, only methods ("operations" in IDL-speak). |
There's the question of what Object.getOwnPropertyDescriptor(window, "console") returns. That is what is changed by the Chrome patch to be incompatible with other browsers. |
This seems like something we'd need implementers to decide on. Per that bug, WebKit has gone with adding an empty object named But how does Gecko feel about the potential compatibility hit? How does Chrome? (@paulirish @ak239) Edge? (@andysterland) If most browsers are interested in pushing through without such a hack, we probably shouldn't spec it, but I don't really know yet. |
Oh, and there's two potential hacks here: (A) Make console's [[Prototype]] a new empty object (The difference is observable because for (A), WebKit seems to have gone with (A). I was originally thinking that (B) would be better, but upon reflection it's probably too weird and could potentially cause compatibility issues. Note that neither (A) nor (B) really fixes the original demo code shown by @JosephPecoraro: console.__proto__.debug = function(format) {
if (window.DEBUG) {
var varargs = Array.prototype.slice.call(arguments);
console.__proto__.info.apply(this, varargs)
}
} I believe that this will still fail, once it reaches the line |
We were aware of the possible issue, but were fine with the trade offs. You are correct that the |
@domenic if the hack is a one-off, it can be prose in the console spec rather than new extended attribute in Web IDL. |
I did a quick search in httparchive (494k pages), only 3 resources that do
|
In Chrome we'd like to fix problem with console.proto as soon as possible and are going to land (A) as temporary solution. |
Hi folks, over the last couple of versions of Firefox, the binding of console.log is no longer giving the file and line numbers in very right hand column of the console. It now says (unknown). Other browsers still work. Is there a way for me to solve this as it is important for my public library http://zimjs.com. I am using:
also tried with no success:
Thank you! |
@danzen that seems unrelated to this issue; I'd suggest filing a bug on the Firefox issue tracker, not commenting on an issue on the console standard. |
@domenic thanks - I think I did that a few weeks ago - I will check on that... sorry did not realize that this was for standards. Cheers for all your work. Just looked and could not find my bug report. So added another: https://bugzilla.mozilla.org/show_bug.cgi?id=1280818#c0 if you are interested! |
* Add namespaces This adds the concept of namespaces, as discussed in whatwg/console#3 (starting especially around whatwg/console#3 (comment)). They can only contain regular operations. The ES binding for namespaces here is written in a fully modern style, and so differs slightly from similar prose for interfaces' ES binding. It is hoped that it can provide a template for eventually updating interfaces' ES binding to modern ES. * Address most code review comments: - Missing some [SecureContext] stuff - Not yet addressed the operation-creation stuff * Stick with "declared on" instead of "declared within" It doesn't read quite right to me, but let's keep it as-is for now and investigate any issues in #153. * Move "creating an operation function" out to #es-operations
Thanks everyone for your help along this long journey! The spec is now updated, including the special prototype object.
|
From the WHATWG console spec: > For historical web-compatibility reasons, the namespace object for > console must have as its [[Prototype]] an empty object, created as > if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. Since in Node.js, the Console constructor has been exposed through require('console'), we need to keep the Console constructor but we cannot actually use `new Console` to construct the global console. This patch changes the prototype chain of the global console object, the console.Console.prototype is not in the global console prototype chain anymore, which means ``` global.console instanceof global.console.Console ``` is no longer true after this patch. This fixes a case in the console Web Platform Test that we commented out. Refs: https://console.spec.whatwg.org/#console-namespace Refs: whatwg/console#3
From the WHATWG console spec: > For historical web-compatibility reasons, the namespace object for > console must have as its [[Prototype]] an empty object, created as > if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. Since in Node.js, the Console constructor has been exposed through require('console'), we need to keep the Console constructor but we cannot actually use `new Console` to construct the global console. This patch changes the prototype chain of the global console object, so the console.Console.prototype is not in the global console prototype chain anymore. ``` const proto = Object.getPrototypeOf(global.console); // Before this patch proto.constructor === global.console.Console // After this patch proto.constructor === Object ``` But, we still maintain that ``` global.console instanceof global.console.Console ``` through a custom Symbol.hasInstance function of Console that tests for a special symbol kIsConsole for backwards compatibility. This fixes a case in the console Web Platform Test that we commented out. Refs: https://console.spec.whatwg.org/#console-namespace Refs: whatwg/console#3
From the WHATWG console spec: > For historical web-compatibility reasons, the namespace object for > console must have as its [[Prototype]] an empty object, created as > if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. Since in Node.js, the Console constructor has been exposed through require('console'), we need to keep the Console constructor but we cannot actually use `new Console` to construct the global console. This patch changes the prototype chain of the global console object, so the console.Console.prototype is not in the global console prototype chain anymore. ``` const proto = Object.getPrototypeOf(global.console); // Before this patch proto.constructor === global.console.Console // After this patch proto.constructor === Object ``` But, we still maintain that ``` global.console instanceof global.console.Console ``` through a custom Symbol.hasInstance function of Console that tests for a special symbol kIsConsole for backwards compatibility. This fixes a case in the console Web Platform Test that we commented out. PR-URL: #23509 Refs: whatwg/console#3 Refs: https://console.spec.whatwg.org/#console-namespace Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
From the WHATWG console spec: > For historical web-compatibility reasons, the namespace object for > console must have as its [[Prototype]] an empty object, created as > if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. Since in Node.js, the Console constructor has been exposed through require('console'), we need to keep the Console constructor but we cannot actually use `new Console` to construct the global console. This patch changes the prototype chain of the global console object, so the console.Console.prototype is not in the global console prototype chain anymore. ``` const proto = Object.getPrototypeOf(global.console); // Before this patch proto.constructor === global.console.Console // After this patch proto.constructor === Object ``` But, we still maintain that ``` global.console instanceof global.console.Console ``` through a custom Symbol.hasInstance function of Console that tests for a special symbol kIsConsole for backwards compatibility. This fixes a case in the console Web Platform Test that we commented out. PR-URL: nodejs#23509 Refs: whatwg/console#3 Refs: https://console.spec.whatwg.org/#console-namespace Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
From the WHATWG console spec: > For historical web-compatibility reasons, the namespace object for > console must have as its [[Prototype]] an empty object, created as > if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. Since in Node.js, the Console constructor has been exposed through require('console'), we need to keep the Console constructor but we cannot actually use `new Console` to construct the global console. This patch changes the prototype chain of the global console object, so the console.Console.prototype is not in the global console prototype chain anymore. ``` const proto = Object.getPrototypeOf(global.console); // Before this patch proto.constructor === global.console.Console // After this patch proto.constructor === Object ``` But, we still maintain that ``` global.console instanceof global.console.Console ``` through a custom Symbol.hasInstance function of Console that tests for a special symbol kIsConsole for backwards compatibility. This fixes a case in the console Web Platform Test that we commented out. PR-URL: #23509 Refs: whatwg/console#3 Refs: https://console.spec.whatwg.org/#console-namespace Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
From the WHATWG console spec: > For historical web-compatibility reasons, the namespace object for > console must have as its [[Prototype]] an empty object, created as > if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. Since in Node.js, the Console constructor has been exposed through require('console'), we need to keep the Console constructor but we cannot actually use `new Console` to construct the global console. This patch changes the prototype chain of the global console object, so the console.Console.prototype is not in the global console prototype chain anymore. ``` const proto = Object.getPrototypeOf(global.console); // Before this patch proto.constructor === global.console.Console // After this patch proto.constructor === Object ``` But, we still maintain that ``` global.console instanceof global.console.Console ``` through a custom Symbol.hasInstance function of Console that tests for a special symbol kIsConsole for backwards compatibility. This fixes a case in the console Web Platform Test that we commented out. PR-URL: nodejs#23509 Refs: whatwg/console#3 Refs: https://console.spec.whatwg.org/#console-namespace Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: John-David Dalton <[email protected]>
Turning ``this`` from ``null`` to ``console`` accorging to whatwg/console#3 to avoid issues under antique engines Thanks again to @zloirock for mentioning this
Turning ``this`` from ``null`` to ``console`` accorging to whatwg/console#3 to avoid issues under antique engines Thanks again to @zloirock for mentioning this
Turning ``this`` from ``null`` to ``console`` accorging to whatwg/console#3 to avoid issues under antique engines Thanks again to @zloirock for mentioning this
Right now assigning a console function to a local variable kind of sucks, since they're expected to be called within the context of
console
. This requires the developer to bind.Except this doesn't work in some versions of IE because the console functions aren't instances of Function!
Which is a lot to type for a pretty simple and common task.
It makes sense to me that this is soemthing worth supporting.
The text was updated successfully, but these errors were encountered: