calendar/resources/content/publish.js relies on asyncOpen taking context as second argument which is defunct since bug 1520868
Categories
(Calendar :: General, enhancement)
Tracking
(Not tracked)
People
(Reporter: mkmelin, Assigned: pmorris)
References
Details
Attachments
(1 file, 5 obsolete files)
|
3.52 KB,
patch
|
mkmelin
:
review+
|
Details | Diff | Splinter Review |
publish.js needs to be updated to not rely in passing a context as second argument to asyncOpen. That version no longer exists since bug 1520868.
https://searchfox.org/comm-central/source/calendar/resources/content/publish.js#175
175: channel.asyncOpen(publishingListener, aProgressDialog);
| Reporter | ||
Comment 1•6 years ago
|
||
Paul, can you give this a shot?
I looked briefly, but this code is fairly messed up, and could do with some serious reworking IMHO. The interaction between this and publishDialog.{js,xul} is quite odd passing globals around it seems. Don't know why the linter doesn't complain about the undeclared |self| either (the declaration of which must be coming from some other file - ouch!)
| Reporter | ||
Comment 2•6 years ago
|
||
The minimal fix would need to figure out how the error handling will get to the progressdialog object, since that object can no longer be receive via asyncOpen. I.e. change to channel.asyncOpen(publishingListener), and find out how to get the progress dialog in this new scenario.
| Assignee | ||
Comment 3•6 years ago
•
|
||
Hey Magnus, Yeah, I'll give it a go, thanks for the explanations. Took a quick look and the 'self' here is likely window.self.
| Reporter | ||
Comment 4•6 years ago
|
||
Ah - of course.
| Assignee | ||
Comment 5•6 years ago
|
||
There may be more to do here, but this solves the asyncOpen issue. Now that there's no context argument, we can provide access to the dialog window by binding it to the callback in the listener object (that gets passed to asyncOpen).
I tested this by publishing a calendar using a bogus URL, and when the request failed, I saw the progress bar stopped indicating progress (as expected). I also used a temporary console.log to see that "onStopUpload" was indeed fired.
| Assignee | ||
Comment 6•6 years ago
|
||
Hmm, I see there are 11 uses of asyncOpen in the calendar code, all passing a second context argument. So maybe a more general solution is in order?
| Reporter | ||
Comment 7•6 years ago
|
||
I think searchfox hasn't had the time to reindex yet. Bug 1528681 removed a lot.
| Assignee | ||
Updated•6 years ago
|
| Reporter | ||
Comment 8•6 years ago
|
||
| Assignee | ||
Comment 9•6 years ago
|
||
as this is used only once, I'd move the implementation there
Okay, I've moved it inline, and switched to capturing the dialog argument via a closure rather than with "bind". (Bind is easier to understand with a separate/named function, and I generally like using bind rather than closures because that's more explicit. But inline with a closure is not bad here.)
maybe clearer to have this be a constructor for an object, instead of some kind of factory?
Okay, I've changed this to a constructor function that uses 'new'. (I tend to prefer factory functions which are more explicit and straightforward to understand than the implicitness of JS's 'new' operator.)
please don't use the aStyle, and do not mix with that style
Ah, yes, good call on not mixing. I've dropped the aStyle throughout this patch. Thanks for additional info on IRC.
| Reporter | ||
Comment 10•6 years ago
|
||
| Assignee | ||
Comment 11•6 years ago
|
||
Ah, I see, thanks. Yeah, that works. (I'm still getting used to this JS class syntax business.)
Redone with class syntax and rebased. (Merge conflict was due to changes in bug 1531307.) Still works when I tested it: "onStopUnload" is called and the progress indicator stops indicating progress.
| Reporter | ||
Comment 12•6 years ago
|
||
Comment 13•6 years ago
|
||
(In reply to Magnus Melin [:mkmelin] from comment #12)
Comment on attachment 9049543 [details] [diff] [review]
publish-async-open-2.patchReview of attachment 9049543 [details] [diff] [review]:
::: calendar/resources/content/publish.js
@@ +197,5 @@
- */
+class PublishingListener {- constructor(progressDialog) {
this.progressDialog = progressDialog;this.QueryInterface = ChromeUtils.generateQI([Ci.nsIStreamListener]);why not this one as a method?
You can't assign prototype methods from the result of a function call in es6 classes, and you don't want to run generateQI on each get. I created this helper: https://searchfox.org/comm-central/source/calendar/base/modules/calUtils.jsm#152 but assigning it in the constructor might actually be less bulky than I thought.
The best thing you can do is this:
class foo {
}
foo.prototype.QueryInterface = ChromeUtils.generateQI([Ci.nsIStreamListener]);
but then you put the QI after the class, which isn't great from a readability standpoint.
| Assignee | ||
Comment 14•6 years ago
|
||
(In reply to Magnus Melin [:mkmelin] from comment #12)
Comment on attachment 9049543 [details] [diff] [review]
publish-async-open-2.patchReview of attachment 9049543 [details] [diff] [review]:
::: calendar/resources/content/publish.js
@@ +197,5 @@
- */
+class PublishingListener {- constructor(progressDialog) {
this.progressDialog = progressDialog;this.QueryInterface = ChromeUtils.generateQI([Ci.nsIStreamListener]);why not this one as a method?
I didn't want to call .generateQI on each access/use of QueryInterface as making it a method would need to do. Better to call it once (per instantiation) in the constructor.
As Philipp mentions, better to put it on the prototype, so it's only ever calculated/fetched once, but you can't do that using ES6 class syntax. (The class syntax sugar is a bit of a "leaky abstraction" here...) You have to do this after the class declaration:
foo.prototype.QueryInterface = ChromeUtils.generateQI([Ci.nsIStreamListener]);
I could see doing that, and adding a comment in the class to alert readers. But since we have a helper function for this (that Philipp references), I think I'll use that.
| Assignee | ||
Comment 15•6 years ago
|
||
This patch uses the helper function to generate the QueryInterface method. Still works as before when tested: "onStopUnload" is called and the progress indicator stops indicating progress.
One benefit of the helper function is that it is lazy, deferring the call to generateQI until it's needed. Although, that probably doesn't matter in this case (where assigning it in the constructor wouldn't be that much different since the object is a "use once and throw away" object), we might as well use the helper for consistency's sake.
| Assignee | ||
Comment 16•6 years ago
|
||
The previous patch accidentally still had "context" parameters for onStopRequest and friends. The context parameters had been removed from that interface, and are no longer there in this patch.
| Assignee | ||
Comment 17•6 years ago
|
||
sigh The previous patch unintentionally removed the 3rd (unused) argument "errorMsg" from "onStopRequest". Now it's back, and this is really ready for review this time. (Need to check the diffs more thoroughly before uploading patches.)
Updated•6 years ago
|
| Reporter | ||
Comment 18•6 years ago
|
||
Comment 19•6 years ago
|
||
Pushed by mozilla@jorgk.com:
https://hg.mozilla.org/comm-central/rev/02fa6334f4ed
asyncOpen() no longer takes 'context' as second argument, pass it as property on the listener object. r=mkmelin
Comment 20•6 years ago
|
||
First bug, haha, at least under the new circumstances ;-)
Please provide a meaningful commit message, copying the bug summary is mostly not a good idea.
Comment 21•6 years ago
|
||
Without having read the whole bug, after M-C discontinued the context parameter and before this patch, what wasn't working? IOW, does it need the parameter or could it just have been dropped? There is no test for this functionality?
In hindsight, maybe a Calendar peer should have reviewed this?
| Reporter | ||
Comment 22•6 years ago
|
||
(In reply to Paul Morris [:pmorris] from comment #17)
sigh The previous patch unintentionally removed the 3rd (unused) argument
"errorMsg" from "onStopRequest". Now it's back, and this is really ready
for review this time.
Heh, that errorMsg arg should actually have been removed now following bug 1525319
-onStopRequest(request, status, errorMsg) {
+onStopRequest(request, status) {
| Reporter | ||
Comment 23•6 years ago
|
||
(In reply to Jorg K (GMT+1) from comment #21)
Without having read the whole bug, after M-C discontinued the context
parameter and before this patch, what wasn't working?
Originally when this bug was filed, you would not have got an error message for publishing failure.
It seems that part was actually "fixed" through https://hg.mozilla.org/comm-central/rev/0022c92d1421
Or well, that fix is wrong and would not work here.
In hindsight, maybe a Calendar peer should have reviewed this?
Theoretically yes, but I think they have their hands full with other changes than adapting to breakage.
Comment 24•6 years ago
|
||
Comment 25•6 years ago
|
||
Thanks, Magnus. Looking at the changes closer, yes, we need the dialog in onStopRequest(), so I agree with passing it this way now that the context parameter has disappeared. I assume there is no test for the publishing functionality.
| Assignee | ||
Comment 26•6 years ago
|
||
Thanks Jorg, for the push and the follow-up! Good to land my first one under new circumstances. :) Will write a better commit message next time. I just did a search and did not find a test for publishing functionality.
Description
•