Bug 911216 - Part 23: Use mozilla::TimeStamp::Now() instead of PRMJ_Now() for Promise timestamps. r=efaust

This commit is contained in:
Till Schneidereit 2016-06-10 11:11:05 +02:00
Родитель 5fd496f69a
Коммит 0f6f35176e
2 изменённых файлов: 18 добавлений и 13 удалений

Просмотреть файл

@ -8,11 +8,11 @@
#include "builtin/Promise.h" #include "builtin/Promise.h"
#include "mozilla/Atomics.h" #include "mozilla/Atomics.h"
#include "mozilla/TimeStamp.h"
#include "jscntxt.h" #include "jscntxt.h"
#include "gc/Heap.h" #include "gc/Heap.h"
#include "js/Date.h"
#include "js/Debug.h" #include "js/Debug.h"
#include "vm/SelfHosting.h" #include "vm/SelfHosting.h"
@ -41,10 +41,12 @@ static const JSPropertySpec promise_static_properties[] = {
JS_PS_END JS_PS_END
}; };
static Value static double
Now() MillisecondsSinceStartup()
{ {
return JS::TimeValue(JS::TimeClip(static_cast<double>(PRMJ_Now()) / PRMJ_USEC_PER_MSEC)); auto now = mozilla::TimeStamp::Now();
bool ignored;
return (now - mozilla::TimeStamp::ProcessCreation(ignored)).ToMilliseconds();
} }
static bool static bool
@ -137,7 +139,8 @@ PromiseObject::create(JSContext* cx, HandleObject executor, HandleObject proto /
return nullptr; return nullptr;
} }
promise->setFixedSlot(PROMISE_ALLOCATION_SITE_SLOT, ObjectOrNullValue(stack)); promise->setFixedSlot(PROMISE_ALLOCATION_SITE_SLOT, ObjectOrNullValue(stack));
promise->setFixedSlot(PROMISE_ALLOCATION_TIME_SLOT, Now()); promise->setFixedSlot(PROMISE_ALLOCATION_TIME_SLOT,
DoubleValue(MillisecondsSinceStartup()));
} }
RootedValue promiseVal(cx, ObjectValue(*promise)); RootedValue promiseVal(cx, ObjectValue(*promise));
@ -211,6 +214,12 @@ namespace {
mozilla::Atomic<uint64_t> gIDGenerator(0); mozilla::Atomic<uint64_t> gIDGenerator(0);
} // namespace } // namespace
double
PromiseObject::lifetime()
{
return MillisecondsSinceStartup() - allocationTime();
}
uint64_t uint64_t
PromiseObject::getID() PromiseObject::getID()
{ {
@ -410,7 +419,8 @@ PromiseObject::reject(JSContext* cx, HandleValue rejectionValue)
return Call(cx, funVal, UndefinedHandleValue, args, &dummy); return Call(cx, funVal, UndefinedHandleValue, args, &dummy);
} }
void PromiseObject::onSettled(JSContext* cx) void
PromiseObject::onSettled(JSContext* cx)
{ {
Rooted<PromiseObject*> promise(cx, this); Rooted<PromiseObject*> promise(cx, this);
RootedObject stack(cx); RootedObject stack(cx);
@ -421,7 +431,7 @@ void PromiseObject::onSettled(JSContext* cx)
} }
} }
promise->setFixedSlot(PROMISE_RESOLUTION_SITE_SLOT, ObjectOrNullValue(stack)); promise->setFixedSlot(PROMISE_RESOLUTION_SITE_SLOT, ObjectOrNullValue(stack));
promise->setFixedSlot(PROMISE_RESOLUTION_TIME_SLOT, Now()); promise->setFixedSlot(PROMISE_RESOLUTION_TIME_SLOT, DoubleValue(MillisecondsSinceStartup()));
if (promise->state() == JS::PromiseState::Rejected && if (promise->state() == JS::PromiseState::Rejected &&
promise->getFixedSlot(PROMISE_IS_HANDLED_SLOT).toInt32() != promise->getFixedSlot(PROMISE_IS_HANDLED_SLOT).toInt32() !=

Просмотреть файл

@ -8,9 +8,7 @@
#define builtin_Promise_h #define builtin_Promise_h
#include "builtin/SelfHostingDefines.h" #include "builtin/SelfHostingDefines.h"
#include "js/Date.h"
#include "vm/NativeObject.h" #include "vm/NativeObject.h"
#include "vm/Time.h"
namespace js { namespace js {
@ -52,10 +50,7 @@ class PromiseObject : public NativeObject
JSObject* resolutionSite() { JSObject* resolutionSite() {
return getFixedSlot(PROMISE_RESOLUTION_SITE_SLOT).toObjectOrNull(); return getFixedSlot(PROMISE_RESOLUTION_SITE_SLOT).toObjectOrNull();
} }
double lifetime() { double lifetime();
double now = JS::TimeClip(static_cast<double>(PRMJ_Now()) / PRMJ_USEC_PER_MSEC).toDouble();
return now - allocationTime();
}
double timeToResolution() { double timeToResolution() {
MOZ_ASSERT(state() != JS::PromiseState::Pending); MOZ_ASSERT(state() != JS::PromiseState::Pending);
return resolutionTime() - allocationTime(); return resolutionTime() - allocationTime();