Closed
Bug 665410
Opened 15 years ago
Closed 14 years ago
waitFor's internal boolean comparison breaks Javascript truth for objects
Categories
(Testing Graveyard :: Mozmill, defect)
Testing Graveyard
Mozmill
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: gmealer, Assigned: whimboo)
Details
(Whiteboard: [mozmill-2.0+])
Attachments
(1 file)
This line is currently in utils.waitFor():
https://github.com/mozautomation/mozmill/blob/hotfix-1.5/mozmill/mozmill/extension/resource/modules/utils.js#L459
while((self.result != true) && (self.counter < timeout)) {
thread.processNextEvent(true);
}
(This is also in the mozmill 2.0 default branch.)
The first boolean comparison breaks truth for objects. Obj != true is always true, even though any object is true in Javascript.
Should be:
while((!self.result) && (self.counter < timeout)) {
thread.processNextEvent(true);
}
Same goes for any other comparisons in that module (as well as assert/expect's ok) that are supposed to simply honor JS truth. We should never be comparing explicitly against a boolean, pretty much ever.
| Assignee | ||
Comment 1•14 years ago
|
||
So this is somewhat invalid because the callback for waitFor always has to return a boolean value. So we should probably add a check if that's the case. Or as Geo suggests we really fallback and assume it could even be an object.
OS: Mac OS X → All
Hardware: x86 → All
Whiteboard: [mozmill-2.0?]
| Reporter | ||
Comment 2•14 years ago
|
||
The only thing technically forcing a boolean return is the line I highlighted. In languages that support implicit truth (of which JS is one) our functions should also support implicit truth.
http://programmers.stackexchange.com/a/136933 explains my position on this pretty well.
IMO, you should make the fix suggested, then update the docs to indicate that waitFor exits when the callback returns "a true value."
We're just going to enforce that we get back a boolean from the test callback.
Whiteboard: [mozmill-2.0?] → [mozmill-2.0+]
| Reporter | ||
Comment 4•14 years ago
|
||
(In reply to Clint Talbert ( :ctalbert ) from comment #3)
> We're just going to enforce that we get back a boolean from the test
> callback.
Out of curiosity, what's the rationale? The fix to allow JS-native truth handling is simple and explictly outlined above.
(In reply to Geo Mealer [:geo] from comment #4)
> (In reply to Clint Talbert ( :ctalbert ) from comment #3)
> > We're just going to enforce that we get back a boolean from the test
> > callback.
>
> Out of curiosity, what's the rationale? The fix to allow JS-native truth
> handling is simple and explictly outlined above.
Because the callbacks are not supposed to be sending us an object. They are supposed to return a boolean value. If they are sending us an object, something is wrong with the test and the callback and they should be informed.
| Reporter | ||
Comment 6•14 years ago
|
||
OK, thanks. Appreciate the followup comment.
| Assignee | ||
Comment 7•14 years ago
|
||
Pointer to Github pull-request
| Assignee | ||
Comment 8•14 years ago
|
||
Comment on attachment 626238 [details]
Patch v1
Fixes the problem by checking the type of the callback return value. Also adds Mutt tests.
Attachment #626238 -
Attachment description: Pointer to Github pull request: https://github.com/mozautomation/mozmill/pull/35 → Patch v1
Attachment #626238 -
Flags: review?(ctalbert)
| Assignee | ||
Updated•14 years ago
|
Assignee: nobody → hskupin
Status: NEW → ASSIGNED
Comment on attachment 626238 [details]
Patch v1
Looks good. thanks!
Attachment #626238 -
Flags: review?(ctalbert) → review+
| Assignee | ||
Comment 10•14 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Updated•10 years ago
|
Product: Testing → Testing Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•