Closed Bug 1249055 Opened 8 years ago Closed 8 years ago

Calling alarms.getAll() throws an exception: TypeError: alarms.map is not a function

Categories

(WebExtensions :: Untriaged, defect)

defect
Not set
normal

Tracking

(firefox47 fixed)

RESOLVED FIXED
mozilla47
Iteration:
47.3 - Mar 7
Tracking Status
firefox47 --- fixed

People

(Reporter: bsilverberg, Assigned: bsilverberg)

References

Details

Attachments

(1 file)

JavaScript error: chrome://extensions/content/ext-alarms.js, line 130: TypeError: alarms.map is not a function

This is because `alarms` [1] is a Set not an Array.

[1] https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ext-alarms.js#130
Assignee: nobody → bob.silverberg
Status: NEW → ASSIGNED
Flags: blocking-webextensions+
Note that I also changed a bit of the boilerplate in the other tests in `test_ext_alarms.html` to match my chosen syntax for the new test, which I think is a bit cleaner.
Blocks: 1190320
Comment on attachment 8720390 [details]
MozReview Request: Bug 1249055 - Calling alarms.getAll() throws an exception, r?kmag

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/35287/diff/1-2/
I fixed another bug that was in `get()` and added coverage for get(), getAll() and clearAll(). I think there is room for improvement in the test. In particular, I feel like the test depends on the different methods being called in sequence, but I'm not sure that the way the test is written guarantees that will happen.

This is now ready for an initial review, Kris.
Comment on attachment 8720390 [details]
MozReview Request: Bug 1249055 - Calling alarms.getAll() throws an exception, r?kmag

https://reviewboard.mozilla.org/r/35287/#review32015

::: toolkit/components/extensions/ext-alarms.js:130
(Diff revision 2)
> -        let result = alarms.map(alarm => alarm.data);
> +        let result = Array.from(alarms).map(alarm => alarm.data);

`Array.from(alarms, alarm => alarm.data)`

::: toolkit/components/extensions/test/mochitest/test_ext_alarms.html:115
(Diff revision 2)
> +    suffixes.map(suffix => {

Please use `.forEach` or a for-of loop rather than `.map`. Same below.

::: toolkit/components/extensions/test/mochitest/test_ext_alarms.html:116
(Diff revision 2)
> +      chrome.alarms.create(ALARM_NAME + suffix, {when: Date.now() + suffix});

0-3 milliseconds is not a lot. Some of these are going to fire before you check them when we switch to OOP extensions.

::: toolkit/components/extensions/test/mochitest/test_ext_alarms.html:117
(Diff revision 2)
> +      return suffix;

This isn't used.

::: toolkit/components/extensions/test/mochitest/test_ext_alarms.html:136
(Diff revision 2)
> +      browser.test.assertEq("undefined", typeof alarm, "non-existent alarm should be undefined");

Please compare against `undefined` rather than using `typeof`

::: toolkit/components/extensions/test/mochitest/test_ext_alarms.html:140
(Diff revision 2)
> +    chrome.alarms.clearAll(wasCleared => {

We should also test `.clear()` here. I know it's tested above, but it seems strange for it to be the only API method not tested in this task.

::: toolkit/components/extensions/test/mochitest/test_ext_alarms.html:145
(Diff revision 2)
> +      browser.test.sendMessage("clearAll");

This should be sent from the `getAll` callback.
Attachment #8720390 - Flags: review?(kmaglione+bmo)
Comment on attachment 8720390 [details]
MozReview Request: Bug 1249055 - Calling alarms.getAll() throws an exception, r?kmag

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/35287/diff/2-3/
Attachment #8720390 - Flags: review?(kmaglione+bmo)
Comment on attachment 8720390 [details]
MozReview Request: Bug 1249055 - Calling alarms.getAll() throws an exception, r?kmag

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/35287/diff/3-4/
https://reviewboard.mozilla.org/r/35287/#review32015

> This should be sent from the `getAll` callback.

I nested the various tests in a way that I believe will ensure that they get executed in the correct order. I wonder if it would be better to do this with `then()` instead of all this nesting. What do you think?
https://reviewboard.mozilla.org/r/35287/#review32015

> I nested the various tests in a way that I believe will ensure that they get executed in the correct order. I wonder if it would be better to do this with `then()` instead of all this nesting. What do you think?

I tried to rewrite it using `then()` but I think the alarms API isn't written in a way that allows that. It seems to insist that I pass a callback into methods like `get()` and `clear()`.
https://reviewboard.mozilla.org/r/35287/#review32015

> I tried to rewrite it using `then()` but I think the alarms API isn't written in a way that allows that. It seems to insist that I pass a callback into methods like `get()` and `clear()`.

Yeah, that's going to be a problem until they're updated to use schema bindings.
https://reviewboard.mozilla.org/r/35287/#review32015

> Yeah, that's going to be a problem until they're updated to use schema bindings.

I've started working on some of the other missing coverage, but it's going to depend on this patch because of the bug fixes. Do you think we can land this soon, or would you prefer that I just keep adding more coverage to this patch?
This is ready to land. I thought I gave it an r+, but mozreview...
Comment on attachment 8720390 [details]
MozReview Request: Bug 1249055 - Calling alarms.getAll() throws an exception, r?kmag

https://reviewboard.mozilla.org/r/35287/#review32235
Attachment #8720390 - Flags: review?(kmaglione+bmo) → review+
Thanks Kris! Pushing to try and I'll mark it for checkin once try is happy.
Keywords: checkin-needed
Iteration: --- → 47.3 - Mar 7
https://hg.mozilla.org/mozilla-central/rev/38e5c1ca1eda
https://hg.mozilla.org/mozilla-central/rev/9cf43731a811
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla47
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: