Closed Bug 430305 Opened 16 years ago Closed 16 years ago

nsITimerCallback should be declared as [function]

Categories

(Core :: XPCOM, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED

People

(Reporter: BenB, Assigned: BenB)

References

Details

Attachments

(1 file, 3 obsolete files)

nsITimerCallback is just a callback, as the same says, with only one function.
XPConnect has a nice feature to make usage of these from JavaScript much more comfortable: If you add "function" to the interface definition, the JS caller can just pass a normal JS function object instead of an object of this interface, and XPConnect will wrap it and call the JS function when the first method of the interface (in this case "notify") is called.

Actual result:
 Interface:
[scriptable, uuid(a796816d-7d47-4348-9ab8-c7aeb3216a7d)]
interface nsITimerCallback : nsISupports

 Usage:
function ttRunAsyncTimerCallback(func)
{
    assert(typeof func == "function", "please pass a JS function");
    this._func = func;
}
ttRunAsyncTimerCallback.prototype =
{
    _func : null,
    notify : function(timer)
    {
        this._func();
    },
    QueryInterface : function(iid)
    {
        if (iid.equals(CI.nsITimerCallback) ||
            iid.equals(CI.nsISupports))
            return this;
       throw Components.results.NS_NOINTERFACE;
    }
}

...
    var func = function() {...};
    var timer = Cc["@mozilla.org/timer;1"].createInstance(CI.nsITimer);
    timer.initWithCallback(new ttRunAsyncTimerCallback(func), sec * 1000,
        CI.nsITimer.TYPE_ONE_SHOT);

Expected result:
 Interface:
[function, scriptable, uuid(a796816d-7d47-4348-9ab8-c7aeb3216a7d)]
interface nsITimerCallback : nsISupports

 Usage:
    var func = function() {...};
    var timer = Cc["@mozilla.org/timer;1"].createInstance(CI.nsITimer);
    timer.initWithCallback(func, sec * 1000, CI.nsITimer.TYPE_ONE_SHOT);
Attached patch Fix (obsolete) — Splinter Review
Assignee: nobody → ben.bucksch
Status: NEW → ASSIGNED
Attachment #317052 - Flags: review?
Comment on attachment 317052 [details] [diff] [review]
Fix

Tested, works
Attachment #317052 - Attachment description: Fix (untested) → Fix
Attachment #317052 - Flags: review? → review?(shaver)
Comment on attachment 317052 [details] [diff] [review]
Fix

Put the tests in this bug, pls (make-check style preferred).
Attached file Test, for JS function (obsolete) —
Attachment #317091 - Attachment mime type: application/javascript → text/plain
Attachment #317092 - Attachment mime type: application/javascript → text/plain
Blocks: tomtom
Revving IID is not necessary:
[23:05:19] <bz> weirdal: see logs if they exist?  bsmedberg, timeless, and I all agree that this should be fine
Attached patch Fix and testsSplinter Review
All in one patch
Attachment #317052 - Attachment is obsolete: true
Attachment #317091 - Attachment is obsolete: true
Attachment #317092 - Attachment is obsolete: true
Attachment #317208 - Flags: review?
Attachment #317052 - Flags: review?(shaver)
Attachment #317208 - Flags: review? → review?(shaver)
Comment on attachment 317208 [details] [diff] [review]
Fix and tests

r+sr+a=shaver for this thoroughly-analyzed (additive) API fix, presuming that it passes the test suites.  (I'd have put both those test cases in the same file, but whatever!)
Attachment #317208 - Flags: superreview+
Attachment #317208 - Flags: review?(shaver)
Attachment #317208 - Flags: review+
Attachment #317208 - Flags: approval1.9+
Thanks for the review and approval!
Checked in on trunk.
FIXED.
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: