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 781219 - tweener: Explicitly check for undefined properties
tweener: Explicitly check for undefined properties
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
1.48.x
Other All
: Normal minor
: ---
Assigned To: Debarshi Ray
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2017-04-12 14:11 UTC by Debarshi Ray
Modified: 2017-05-21 20:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tweener: Explicitly check if obj.time and obj.delay are defined (1.27 KB, patch)
2017-04-12 14:12 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-04-12 14:11:10 UTC
With SpiderMonkey 38 and the gjs-1.48.x, I see these in gnome-documents:

  JS WARNING: [resource:///org/gnome/gjs/modules/tweener/tweener.js 514]:
    reference to undefined property obj.delay

  JS WARNING: [resource:///org/gnome/gjs/modules/tweener/tweener.js 538]:
    reference to undefined property properties[istr].arrayIndex

The first one is easily fixed; but the second is more involved - that code has a real world example of the difference between 'let' and var'. :)
Comment 1 Debarshi Ray 2017-04-12 14:12:03 UTC
Created attachment 349734 [details] [review]
tweener: Explicitly check if obj.time and obj.delay are defined
Comment 2 Philip Chimento 2017-04-12 15:44:35 UTC
Review of attachment 349734 [details] [review]:

Since undefined, NaN and 0 are all falsy values, you could do "var time = obj.time || 0;" which would be more readable. On the other hand, that would also silently accept obj.time === "" where it might have thrown an exception before. Either way is +1 from me.
Comment 3 Philip Chimento 2017-04-12 15:47:37 UTC
Thanks for the patch. Can you help me understand the problem you see with the second instance? I see "properties" is defined in an awkward place.
Comment 4 Debarshi Ray 2017-04-13 06:43:11 UTC
(In reply to Philip Chimento from comment #2)
> Review of attachment 349734 [details] [review] [review]:
> 
> Since undefined, NaN and 0 are all falsy values, you could do "var time =
> obj.time || 0;" which would be more readable.

Ok, I will change it to 'obj.time || 0'.
Comment 5 Debarshi Ray 2017-04-13 06:47:31 UTC
(In reply to Philip Chimento from comment #3)
> Can you help me understand the problem you see with
> the second instance? I see "properties" is defined in an awkward place.

I should mention that I only got the second WARNING once I fixed the first.

In the second instance it is complaining about properties[istr].arrayIndex. I haven't tracked it down yet, so I don't know why. Even though 'properties' is awkwardly defined, it is correctly conditioned on 'isCaller', so that's not the issue. Although it might be nicer to use 'let' and define 'properties' in the outer block.

As I said, it is a bit more involved than the first WARNING. :)
Comment 6 Philip Chimento 2017-04-17 03:37:14 UTC
Comment on attachment 349734 [details] [review]
tweener: Explicitly check if obj.time and obj.delay are defined

I committed the patch with the modification.

Attachment 349734 [details] pushed as 3e63b34 - tweener: Explicitly check if obj.time and obj.delay are defined
Comment 7 Philip Chimento 2017-04-17 03:40:13 UTC
Can the second warning be solved with just a well-placed properties[istr].arrayIndex || someDefaultValue?
Comment 8 Philip Chimento 2017-04-20 05:42:43 UTC
Pushed the first patch to gnome-3-24.
Comment 9 Philip Chimento 2017-05-21 20:42:29 UTC
I'll add a simple `|| 0` to the offending line of code. I don't think it matters, actually as far as I can tell arrayIndex is not even used by the Tweener code.