Closed
Bug 636159
Opened 15 years ago
Closed 15 years ago
window.console doesn't return real functions.
Categories
(DevTools :: General, defect)
Tracking
(Not tracked)
RESOLVED
WORKSFORME
People
(Reporter: casrawnsley+mozilla, Unassigned)
Details
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b11) Gecko/20100101 Firefox/4.0b11
Build Identifier: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b11) Gecko/20100101 Firefox/4.0b11
I would like to replace the window.console functions with my own but still be able to call the native ones as well. I'm finding that in order to this cross browser that the window.console methods would need .call or .apply.
Reproducible: Always
Steps to Reproduce:
With the Web Console open run the following:
var _c = {log: window.console.log};
window.console.log = function () {
_c.log.apply(window.console, arguments);
};
window.console.log(window);
Actual Results:
_c.log.apply is not a function
Expected Results:
[object Window]
This is on Firefox 4.0b11.
Typing "window.console.log" on the Web Console returns:
(function CA_log() {self.notifyObservers(id, "log", arguments);})
rather than what I would expect:
function log() {[native code]}
Comment 1•15 years ago
|
||
I'm getting (on a nightly build):
[16:13:30.890] var _c = {log: window.console.log};
window.console.log = function () {
_c.log.apply(window.console, arguments);
};
window.console.log(window);
[16:13:30.904] [object XrayWrapper [object Window]]
[16:13:30.909] undefined
So you end up passing a wrapped window object into apply. What happens when you do this in an actual content document?
| Reporter | ||
Comment 2•15 years ago
|
||
With the latest nightly, I get the same output that you describe. The latest nightly is much more in line with my perception of how window.console should be defined.
That being said, it would seem that returning a wrapped object with “XrayWrapper” (which judging from the name, is what enables Firefox to have that nice object inspection in the Web Console?) is incorrect. Shall I file another bug report?
Comment 3•15 years ago
|
||
no, the XrayWrapper is a security mechanism wrapping the underlying function object. It's to prevent content from gaining access to higher-privileged JavaScript.
I think the issue i that we're not exposing apply (or call) on the console API.
mrbkap, would adding apply and call fix that here?
Comment 4•15 years ago
|
||
sorry, disregard my suggestion in c#3. I was looking at:
http://mxr.mozilla.org/mozilla-central/source/dom/base/ConsoleAPI.js?force=1#92
but that's not what we're doing with bind there.
In the comment on line 88 ("this allows things like console.bind to work"), should we expect console.log.apply() and call to work as well?
| Reporter | ||
Comment 5•15 years ago
|
||
Rob, that appears to be the case in the latest nightly.
OS: Mac OS X → Windows 7
Comment 6•15 years ago
|
||
(In reply to comment #5)
> Rob, that appears to be the case in the latest nightly.
You mean this is working correctly for you?
Hardware: x86_64 → All
Comment 7•15 years ago
|
||
nuts, I changed the platform flag accidentally. Meant to ask, you're using the 64 bit windows version? That's not really a supported platform for us right now. There could be bugs!
Hardware: All → x86_64
| Reporter | ||
Comment 8•15 years ago
|
||
(In reply to comment #6)
> You mean this is working correctly for you?
(In reply to comment #7)
> Meant to ask, you're using the 64 bit windows version?
I realise now that I should have tested against the latest nightly before filing a report. My original report was based off of Firefox 4b11 for Mac OS X which was running in 64 bit mode.
As far as I can tell, .apply and .call now function as intended, however, returning XrayWrapper is unexpected behaviour IMO. I shall mark as fixed (as I probably should have done a few comments ago, sorry!)
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
OS: Windows 7 → Windows XP
Resolution: --- → FIXED
| Reporter | ||
Updated•15 years ago
|
OS: Windows XP → Mac OS X
Updated•15 years ago
|
Resolution: FIXED → WORKSFORME
Updated•7 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•