Closed Bug 381189 Opened 17 years ago Closed 7 years ago

[meta] Reduce code duplication in js xpcom by using the import module (XPCOMUtils.jsm)

Categories

(Firefox :: General, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: richwklein, Unassigned)

References

()

Details

(Keywords: meta)

Attachments

(1 file, 1 obsolete file)

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.4pre) Gecko/20070518 Firefox/2.0.0.3 Navigator/9.0a13
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.4pre) Gecko/20070518 Firefox/2.0.0.3 Navigator/9.0a13

This is the Firefox bug to start using the new the new js code sharing system from bug 238324.  This should greatly reduce the amount of code duplication for javascript xpcom module registration.

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
Depends on: 238324
The thunderbird version of this is bug 381190 and the toolkit version is bug 381191.
This patch replaces module registration in nsBookmarkTransactionManager.js with
the new XPCOMUtils.jsm's generateNSGetModule.  File size was reduced from
13895 bytes to 13068 bytes.  I've built with this applied and it does not seem to
have any ill affects.

Asking review from Myk Melez since he was the last to update this file.
Attachment #265297 - Flags: review?(myk)
Attached patch Microsummary Service Patch (obsolete) — Splinter Review
This patch replaces module registration in nsMicrosummaryService.js with
the new XPCOMUtils.jsm's generateNSGetModule.  File size was reduced from
89187 bytes to 87938 bytes.  I've built with this applied and it does not seem to
have any ill affects.

Asking review from thunder since he was the last to update this file.
Attachment #265298 - Flags: review?(thunder)
confirming for bug radar.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment on attachment 265297 [details] [diff] [review]
Bookmark Transaction Manager Patch

Wow, great refactoring!  I'm looking forward to seeing more of this throughout the code.

Overall this is straightforward and looks fine, but I have some style nits.  The primary one is that there's too much inlining of literals, which makes it hard to read the data structures and method calls.

This would be easier to grok (at a slight increase in code size) if the data structures were declared before being used, i.e.:

function bkmkTxnMgrConstructor() {
  return new bookmarkTransactionManager();
},

var bkmkTxnMgrInterfaces = [Ci.nsIBookmarkTransactionManager];

var bkmkTxnMgrFactory = 
  XPCOMUtils.generateFactory(bkmkTxnMgrConstructor, bkmkTxnMgrInterfaces);

var bkmkTxnMgrModule = {
  className:  "Bookmark Transaction Manager",
  cid:        Components.ID("{8be133d0-681d-4f0b-972b-6a68e41afb62}"),
  contractID: "@mozilla.org/bookmarks/transactionmanager;1",
  factory:    bkmkTxnMgrFactory
};

var NSGetModule = XPCOMUtils.generateNSGetModule([bkmkTxnMgrModule]);

A few more nits (mostly reflected in the sample code above):

* Now's a good time to define a Ci helper constant in this file and use it to shorten Components.interfaces.nsIBookmarkTransactionManager to Ci.nsIBookmarkTransactionManager.

* I think it's worth spelling out "Constructor" in the name of the constructor function, although I realize that XPCOMUtils.generateFactory names its first argument "ctor".

* Since XPCOMUtils isn't an XPCOM component, and you aren't calling it through XPCOM, you don't have to include values for unused arguments, so you can leave off the two null values for the postRegister and preUnregister arguments to generateNSGetModule.

* Make sure there's a newline at the end of the file.

FWIW, I'm not sure touching this file last makes me the most appropriate reviewer for it, although changes to the component registration code are certainly within my range.  But since my review consists entirely of style nits, it'd be worth having the module owner take a look at this, so requesting super-review from mconnor.
Attachment #265297 - Flags: superreview?(mconnor)
Attachment #265297 - Flags: review?(myk)
Attachment #265297 - Flags: review-
Comment on attachment 265297 [details] [diff] [review]
Bookmark Transaction Manager Patch

>Index: browser/components/bookmarks/src/nsBookmarkTransactionManager.js

>+    factory: XPCOMUtils.generateFactory(
>+      function bkmkCtor() {
>+        return new bookmarkTransactionManager();
>+      },

Note a patch for the original XPCOMUtils (r=sayrer, sr=bsmedberg) would require you change this first argument to simply be "bookmarkTransactionManager" (the function, not the string).
> Note a patch for the original XPCOMUtils (r=sayrer, sr=bsmedberg) would require
> you change this first argument to simply be "bookmarkTransactionManager" (the
> function, not the string).

What's the bug number for this change?
Per Alex's comment #4 in bug 381190, I'm going to morph this into a tracking bug and file individual bugs for each component.
Keywords: meta
Summary: Reduce code duplication in js xpcom by using the import module (XPCOMUtils.jsm) → [meta] Reduce code duplication in js xpcom by using the import module (XPCOMUtils.jsm)
Depends on: 381226
Depends on: 381227
Depends on: 381254
There has been some discussion that one bug is sufficient for each major area of change.  I can file individual bugs or place all the patches here.  Below is the list of files for Firefox that should be changed:

browser/components/bookmarks/src/nsBookmarkTransactionManager.js
browser/components/feeds/src/FeedConverter.js
browser/components/feeds/src/FeedWriter.js
browser/components/feeds/src/WebContentConverter.js
browser/components/microsummaries/src/nsMicrosummaryService.js
browser/components/safebrowsing/src/nsSafebrowsingApplication.js
browser/components/search/src/nsSearchService.js
browser/components/search/src/nsSearchSuggestion.js
browser/components/sessionstore/src/nsSessionStartup.js
browser/components/sessionstore/src/nsSessionStore.js
browser/components/shell/src/nsSetDefaultBrowser.js
browser/components/sidebar/src/nsSidebar.js
browser/components/nsBrowserContentHandler.js
browser/components/nsBrowserGlue.js
browser/fuel/fuelApplication.js

If anyone else wants to take on some of these files feel free.
Blocks: 381191
Update: bug 381651 is changing XPCOMUtils' API.  See attachment 269013 [details] [diff] [review] in bug 385087 for an example of how to use the new API in a JS component file.
Thanks for the update I've been holding off doing anything on this until the apis stabilize a bit more.
Comment on attachment 265298 [details] [diff] [review]
Microsummary Service Patch

Removed the review request on an old patch.
Attachment #265298 - Attachment is obsolete: true
Attachment #265298 - Flags: review?(thunder)
Attachment #265297 - Flags: superreview?(mconnor)
All the files referenced in comment 9 are using the XPCOMUtils API now, or have been removed. Hence I think this can be marked as WFM.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: