GNOME Bugzilla – Bug 646919
environment: improve Object.toString for delegate objects
Last modified: 2011-04-26 12:20:30 UTC
If a JS object has an 'actor' property pointing to a ClutterActor, include the actor's toString() output in the delegate's toString() output. Eg: js>>> Main.panel [object Object delegate for 0xff6080 StBoxLayout.menu-bar "panel" ("Activities")]
Created attachment 185314 [details] [review] environment: improve Object.toString for delegate objects
Review of attachment 185314 [details] [review]: Looks good. ::: js/ui/environment.js @@ +92,3 @@ + Object.prototype.toString = function() { + let base = origToString.call(this); + if ('actor' in this && this.actor instanceof Clutter.Actor) Is there any advantage in using "'actor' in this" rather than "this.actor"?
While playing with this, I noticed (not for the first time) that "foo.constructor.name" returns "Object" for all JS objects in gnome-shell. It turns out that this is because the original value of Foo.prototype has some sort of magic attached to it, which gets lost when we overwrite it with our own prototype. So we could fix this if instead of doing Foo.prototype = { ... }; we did the equivalent of: Lang.copyProperties({ ... }, Foo.prototype); though we'd want to make it prettier. (And then we could change toString to use this.constructor.name, rather than "Object" everywhere.)
(In reply to comment #2) > Is there any advantage in using "'actor' in this" rather than "this.actor"? It won't cause a warning/error if we/gjs/spidermonkey ever implement a "warn/error if anyone tries to read an undefined property" mode, which we clearly need given some of the bugfixes of the last few weeks.
Good point.
Attachment 185314 [details] pushed as 07a0960 - environment: improve Object.toString for delegate objects