Closed Bug 927035 Opened 11 years ago Closed 11 years ago

Don't use Date.now() as an ID

Categories

(DevTools :: Console, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 28

People

(Reporter: Dolske, Assigned: lpy)

Details

(Whiteboard: [good first bug][lang=js][mentor=benvie][qa-])

Attachments

(1 file, 2 obsolete files)

We've fixed a number of bugs (bug 925771, bug 586153, bug 578589) that were a result of using Date.now() as an identifier. The problem is that Date.now() can return the same value if called again in a sufficiently short period of time. [In the past Windows was the worst, as the result only changed ~60Hz].

I just noticed this is being used in devtools:

browser/devtools/webconsole/hudservice.js

300 function WebConsole(aTarget, aIframeWindow, aChromeWindow)
301 {
302   this.iframeWindow = aIframeWindow;
303   this.chromeWindow = aChromeWindow;
304   this.hudId = "hud_" + Date.now();

Looks like this is a module, so should be trivial to change it to use a simple static counter. (Alternatively, something like nsIUUIDGenerator would be adequate overkill.)
Component: Developer Tools → Developer Tools: Console
Whiteboard: [good first bug][lang=js][mentor=benvie]
Priority: -- → P3
Attached patch bug927035.patch (obsolete) — Splinter Review
replace it with nsIUUIDGenerator
Assignee: nobody → pylaurent1314
Attachment #8336656 - Flags: review?(bbenvie)
Can we please use a static counter? |hudId = "hud_" + (++gHudId)| where gHudId is a global variable. nsIUUIDGenerator is overkill for webconsole's needs.
Attached patch bug927035.patch (obsolete) — Splinter Review
Thank you msucan.
Attachment #8336656 - Attachment is obsolete: true
Attachment #8336656 - Flags: review?(bbenvie)
Attachment #8336786 - Flags: review?(bbenvie)
Comment on attachment 8336786 [details] [diff] [review]
bug927035.patch

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

Looks good, just one small nit.

::: browser/devtools/webconsole/hudservice.js
@@ +302,5 @@
>  function WebConsole(aTarget, aIframeWindow, aChromeWindow)
>  {
>    this.iframeWindow = aIframeWindow;
>    this.chromeWindow = aChromeWindow;
> +  this.hudId = "hud_" + (++gHudId);

Nit: No need to parenthesize this.
Attachment #8336786 - Flags: review?(bbenvie) → review+
Attached patch bug927035.patchSplinter Review
Attachment #8336786 - Attachment is obsolete: true
Attachment #8338153 - Flags: review+
Keywords: checkin-needed
https://hg.mozilla.org/integration/fx-team/rev/0aeb98afb35d
Keywords: checkin-needed
Whiteboard: [good first bug][lang=js][mentor=benvie] → [good first bug][lang=js][mentor=benvie][fixed-in-fx-team]
https://hg.mozilla.org/mozilla-central/rev/0aeb98afb35d
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Whiteboard: [good first bug][lang=js][mentor=benvie][fixed-in-fx-team] → [good first bug][lang=js][mentor=benvie]
Target Milestone: --- → Firefox 28
Whiteboard: [good first bug][lang=js][mentor=benvie] → [good first bug][lang=js][mentor=benvie][qa-]
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: