Closed Bug 1426886 Opened 6 years ago Closed 6 years ago

Timer.jsm setTimeout doesn't check that aCallback is a function

Categories

(Toolkit :: General, defect)

52 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla60
Tracking Status
firefox60 --- fixed

People

(Reporter: WeirdAl, Assigned: WeirdAl)

Details

Attachments

(1 file, 1 obsolete file)

Attached patch Timer.jsm.diff (obsolete) — Splinter Review
I've been getting a really dumb, hard-to-trace error because somewhere in our company code, we passed in a non-function to Timer.jsm's setTimeout.

CONSOLE: error [JavaScript Error: "TypeError: aCallback.apply is not a function" {file: "resource://gre/modules/Timer.jsm" line: 30}]

I realize some want to get rid of it (bug 1357731), but in the meantime can we at least sanity-check our arguments so they don't blow up later?

Patch attached but not tested...
Attachment #8938678 - Flags: review?(dolske)
Attachment #8938678 - Flags: review?(dolske) → review?(mconley)
Comment on attachment 8938678 [details] [diff] [review]
Timer.jsm.diff

Review of attachment 8938678 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks! r=me if we brace the one-liner.

::: toolkit/modules/Timer.jsm
@@ +24,5 @@
>  var gTimerTable = new Map(); // int -> nsITimer
>  
>  function _setTimeoutOrIsInterval(aCallback, aMilliseconds, aIsInterval,
>                                   aTarget, aArgs) {
> +  if (typeof aCallback !== "function")

Could you please brace this one-liner? That seems to be the convention throughout the rest of the file.
Attachment #8938678 - Flags: review?(mconley) → review+
I can - but I think I should also add an automated test somewhere... at the time I filed this bug, I was rather annoyed.
(In reply to Alex Vincent [:WeirdAl] from comment #2)
> I can - but I think I should also add an automated test somewhere... at the
> time I filed this bug, I was rather annoyed.

Yes, that's a very good idea.

toolkit/modules/tests/xpcshell/test_timer.js is the right place.
Comment on attachment 8945985 [details] [diff] [review]
Timer.jsm should validate callback argument is a function

with tests added and the braces corrected as desired
Attachment #8945985 - Flags: review?(mconley)
Attachment #8938678 - Attachment is obsolete: true
Comment on attachment 8945985 [details] [diff] [review]
Timer.jsm should validate callback argument is a function

Review of attachment 8945985 [details] [diff] [review]:
-----------------------------------------------------------------

Looks great! Thanks for the tests!
Attachment #8945985 - Flags: review?(mconley) → review+
Attachment #8945985 - Flags: checkin?(mconley)
Comment on attachment 8945985 [details] [diff] [review]
Timer.jsm should validate callback argument is a function

I forgot, checkin-needed is still preferred.
Attachment #8945985 - Flags: checkin?(mconley)
Keywords: checkin-needed
Pushed by btara@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/00ef102abbc6
Timer.jsm should validate callback argument is a function. r=mconley
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/00ef102abbc6
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla60
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: