From 992f99784537c2f8b819c48cdca2a8c2a20092d4 Mon Sep 17 00:00:00 2001 From: David Rajchenbach-Teller Date: Mon, 26 Aug 2013 10:33:49 -0400 Subject: [PATCH] Bug 874425 - Ensure that we never return an negative duration. r=froydnj --- toolkit/components/osfile/modules/osfile_async_front.jsm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/toolkit/components/osfile/modules/osfile_async_front.jsm b/toolkit/components/osfile/modules/osfile_async_front.jsm index de55eeddf993..d86f1432777f 100644 --- a/toolkit/components/osfile/modules/osfile_async_front.jsm +++ b/toolkit/components/osfile/modules/osfile_async_front.jsm @@ -160,6 +160,11 @@ let Scheduler = { if (!("durationMs" in data)) { return data.ok; } + // Bug 874425 demonstrates that two successive calls to Date.now() + // can actually produce an interval with negative duration. + // We assume that this is due to an operation that is so short + // that Date.now() is not monotonic, so we round this up to 0. + let durationMs = Math.max(0, data.durationMs); // Accumulate (or initialize) outExecutionDuration if (typeof options.outExecutionDuration == "number") { options.outExecutionDuration += data.durationMs;