Closed Bug 1034599 Opened 9 years ago Closed 6 years ago

Convert remaining Promise.defer() uses to PromiseUtils.defer() or to an inline helper


(Toolkit :: Async Tooling, defect, P1)




56.1 - Jun 26
Performance Impact high
Tracking Status
firefox56 --- fixed


(Reporter: Irving, Assigned: florian)



(Whiteboard: [photon-performance])


(3 files)

Promise.jsm provides a non-standard way of constructing new Promises, using the Promise.defer() static method.

Because ES6 standardized "new Promise(function(resolve, reject){..})" as the way of constructing Promises, we should officially deprecate Promise.defer().
The first step is addressing the dev-doc-needed from bug 941757 on MDN:

We may at the same time add deprecation notes to the existing documentation.

After this is done, we should find all the "defer" calls in mozilla-central and either:
- Convert to them "new Promise" directly, or
- Replace "Promise.defer" calls with a local helper (that only calls "new Promise"),
  and file a bug against the component for the final conversion to "new Promise".

When there are no more mozilla-central calls, we can add a deprecation warning to the API itself to get add-ons converted as well.

All this work is required for migration to DOM Promises when ready.
David, can we use the defer defined in Promise-backend.js or is there any problem in that approach?
Oops sorry for comment 2
Well, we can't call it, because it is going to disappear, but the same implementation should work.
Depends on: 1362882
Summary: Deprecate Promise.jsm Promise.defer() constructor → Convert remaining Promise.defer() uses to PromiseUtils.defer() or to an inline helper
Blocks: 1368456
Blocks: photon-perf-upforgrabs
No longer blocks: 1368456
Whiteboard: [qf][photon]
Blocks: 1368456
Whiteboard: [qf][photon] → [qf] [photon-performance] [triage]
Flags: qe-verify-
Priority: -- → P2
Whiteboard: [qf] [photon-performance] [triage] → [qf] [photon-performance]
Whiteboard: [qf] [photon-performance] → [qf:p1] [photon-performance]
Here is the output of my script from bug 1362882, listing the Promise.defer calls it didn't dare replacing, and explaining why.
Assignee: nobody → florian
Iteration: --- → 56.1 - Jun 26
Priority: P2 → P1
Attached patch PatchSplinter Review
This handles only the Firefox code. Test, mobile and devtools code will be for follow-up (and I'm not volunteering to fix them).
This is mostly done by hand, although I sometimes used some help from the bug 1362882 script (when converting to new Promise() after tweaking a bit the original file to let the script pass).
Attachment #8880184 - Flags: review?(paolo.mozmail)
Attached patch Patch (diff -w)Splinter Review
Diff -w version of attachment 8880184 [details] [diff] [review] for easier review.
Comment on attachment 8880184 [details] [diff] [review]

Review of attachment 8880184 [details] [diff] [review]:

::: toolkit/components/jsdownloads/src/DownloadCore.jsm
@@ +840,5 @@
>        return Promise.resolve();
>      }
> +    if (!this._promiseRemovePartialData) {
> +      this._promiseRemovePartialData = (async () => {

Whoa, today I learned about async () => {}
Attachment #8880184 - Flags: review?(paolo.mozmail) → review+
Pushed by
Convert remaining Promise.defer() uses to PromiseUtils.defer() or new Promise(), r=mconley.
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
Performance Impact: --- → P1
Whiteboard: [qf:p1] [photon-performance] → [photon-performance]
You need to log in before you can comment on or make changes to this bug.