Closed Bug 1050104 Opened 10 years ago Closed 10 years ago

It is not possible to override console.log (or set any expandos on console) in a worker because self.console returns a new object each time

Categories

(Core :: DOM: Workers, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: jujjyl, Assigned: ehsan.akhgari)

Details

Attachments

(2 files, 1 obsolete file)

If one replaces the console.log function in a worker to e.g. post the messages back to main thread instead of printing to console, this assignment is ignored and the worker will keep calling to the original browser-implemented console.log function instead of calling the user-defined function.

See the attached code for a test case. See also https://bugzilla.mozilla.org/show_bug.cgi?id=1049091 where this was first reported.
It's possible to replace the entire object: console = { log: function(msg) { .. } }
Thanks, that works. Is there a reason why overriding just a single function is not supported, or was that just accidental?
I suspect it's a bug because on main-thread it works.
Flags: needinfo?(bzbarsky)
Andrea, did you read bug 1049091 comment 11?  This is totally a bug, and a memory hog if something uses console in workers.
Flags: needinfo?(bzbarsky) → needinfo?(amarchesini)
Summary: It is not possible to override console.log in a worker. → It is not possible to override console.log (or set any expandos on console) in a worker because self.console returns a new object each time
Attachment #8469585 - Flags: review?(amarchesini)
Assignee: nobody → ehsan
Comment on attachment 8469585 [details] [diff] [review]
Do not return a new console object every time self.console is called on workers; r=baku

Why can't you just make the return type Console* and return mConsole?
I can!
Attachment #8469585 - Attachment is obsolete: true
Attachment #8469585 - Flags: review?(amarchesini)
Attachment #8469628 - Flags: review?(amarchesini)
Comment on attachment 8469628 [details] [diff] [review]
Do not return a new console object every time self.console is called on workers; r=baku

Review of attachment 8469628 [details] [diff] [review]:
-----------------------------------------------------------------

good!
Attachment #8469628 - Flags: review?(amarchesini) → review+
Flags: needinfo?(amarchesini)
Perhaps because WorkerGlobalScope doesn't CC the mConsole member?
Ah, of course, the cycle collector needs to know about mConsole!

https://hg.mozilla.org/integration/mozilla-inbound/rev/cf471a3f661b
https://hg.mozilla.org/mozilla-central/rev/cf471a3f661b
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: