diff --git a/js/public/SliceBudget.h b/js/public/SliceBudget.h index 2dfbdacc73e5..c45fdf020853 100644 --- a/js/public/SliceBudget.h +++ b/js/public/SliceBudget.h @@ -38,7 +38,7 @@ struct JS_PUBLIC_API(SliceBudget) static const intptr_t CounterReset = 1000; - static const int64_t Unlimited = 0; + static const int64_t Unlimited = -1; /* Use to create an unlimited budget. */ SliceBudget(); @@ -59,7 +59,7 @@ struct JS_PUBLIC_API(SliceBudget) } bool isOverBudget() { - if (counter >= 0) + if (counter > 0) return false; return checkOverBudget(); } diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 116b33e0455b..d4d98806a4a5 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -1457,7 +1457,7 @@ GCRuntime::setParameter(JSGCParamKey key, uint32_t value) setMaxMallocBytes(value); break; case JSGC_SLICE_TIME_BUDGET: - sliceBudget = value; + sliceBudget = value ? value : SliceBudget::Unlimited; break; case JSGC_MARK_STACK_LIMIT: setMarkStackLimit(value); @@ -2937,9 +2937,10 @@ SliceBudget::SliceBudget() SliceBudget::SliceBudget(TimeBudget time) { - if (time.budget == Unlimited) { + if (time.budget < 0) { reset(); } else { + // Note: TimeBudget(0) is equivalent to WorkBudget(CounterReset). deadline = PRMJ_Now() + time.budget * PRMJ_USEC_PER_MSEC; counter = CounterReset; } @@ -2947,14 +2948,18 @@ SliceBudget::SliceBudget(TimeBudget time) SliceBudget::SliceBudget(WorkBudget work) { - deadline = 0; - counter = work.budget; + if (work.budget < 0) { + reset(); + } else { + deadline = 0; + counter = work.budget; + } } bool SliceBudget::checkOverBudget() { - bool over = PRMJ_Now() > deadline; + bool over = PRMJ_Now() >= deadline; if (!over) counter = CounterReset; return over;