After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 646919 - environment: improve Object.toString for delegate objects
environment: improve Object.toString for delegate objects
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on:
Blocks:
 
 
Reported: 2011-04-06 14:42 UTC by Dan Winship
Modified: 2011-04-26 12:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
environment: improve Object.toString for delegate objects (1.26 KB, patch)
2011-04-06 14:43 UTC, Dan Winship
committed Details | Review

Description Dan Winship 2011-04-06 14:42:16 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")]
Comment 1 Dan Winship 2011-04-06 14:43:30 UTC
Created attachment 185314 [details] [review]
environment: improve Object.toString for delegate objects
Comment 2 Florian Müllner 2011-04-06 14:50:01 UTC
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"?
Comment 3 Dan Winship 2011-04-06 14:52:30 UTC
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.)
Comment 4 Dan Winship 2011-04-06 14:57:32 UTC
(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.
Comment 5 Florian Müllner 2011-04-06 14:59:59 UTC
Good point.
Comment 6 Dan Winship 2011-04-26 12:20:28 UTC
Attachment 185314 [details] pushed as 07a0960 - environment: improve Object.toString for delegate objects