| Index: Source/modules/battery/BatteryManager.cpp
|
| diff --git a/Source/modules/battery/BatteryManager.cpp b/Source/modules/battery/BatteryManager.cpp
|
| index 0c259e34bf141842bc7d48d900c164f0e6cbba2b..4c92f17a9701ce65c865b36a1b92f686c390a887 100644
|
| --- a/Source/modules/battery/BatteryManager.cpp
|
| +++ b/Source/modules/battery/BatteryManager.cpp
|
| @@ -30,30 +30,24 @@ BatteryManager::BatteryManager(ExecutionContext* context)
|
| : ActiveDOMObject(context)
|
| , PlatformEventController(toDocument(context)->page())
|
| , m_batteryStatus(BatteryStatus::create())
|
| - , m_state(NotStarted)
|
| {
|
| }
|
|
|
| ScriptPromise BatteryManager::startRequest(ScriptState* scriptState)
|
| {
|
| - if (m_state == Pending)
|
| - return m_resolver->promise();
|
| -
|
| - m_resolver = ScriptPromiseResolver::create(scriptState);
|
| - ScriptPromise promise = m_resolver->promise();
|
| -
|
| - // If the context is in a stopped state already, do not start updating.
|
| - if (m_state == Resolved || !executionContext() || executionContext()->activeDOMObjectsAreStopped()) {
|
| - // FIXME: Consider returning the same promise in this case. See crbug.com/385025.
|
| - m_state = Resolved;
|
| - m_resolver->resolve(this);
|
| - } else if (m_state == NotStarted) {
|
| - m_state = Pending;
|
| - m_hasEventListener = true;
|
| - startUpdating();
|
| + if (!m_batteryProperty) {
|
| + m_batteryProperty = new BatteryProperty(scriptState->executionContext(), this, BatteryProperty::Ready);
|
| +
|
| + // If the context is in a stopped state already, do not start updating.
|
| + if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) {
|
| + m_batteryProperty->resolve(this);
|
| + } else {
|
| + m_hasEventListener = true;
|
| + startUpdating();
|
| + }
|
| }
|
|
|
| - return promise;
|
| + return m_batteryProperty->promise(scriptState->world());
|
| }
|
|
|
| bool BatteryManager::charging()
|
| @@ -78,15 +72,13 @@ double BatteryManager::level()
|
|
|
| void BatteryManager::didUpdateData()
|
| {
|
| - ASSERT(m_state != NotStarted);
|
| + ASSERT(m_batteryProperty);
|
|
|
| BatteryStatus* oldStatus = m_batteryStatus;
|
| m_batteryStatus = BatteryDispatcher::instance().latestData();
|
|
|
| - if (m_state == Pending) {
|
| - ASSERT(m_resolver);
|
| - m_state = Resolved;
|
| - m_resolver->resolve(this);
|
| + if (m_batteryProperty->state() == ScriptPromisePropertyBase::Pending) {
|
| + m_batteryProperty->resolve(this);
|
| return;
|
| }
|
|
|
| @@ -137,7 +129,7 @@ void BatteryManager::resume()
|
| void BatteryManager::stop()
|
| {
|
| m_hasEventListener = false;
|
| - m_state = NotStarted;
|
| + m_batteryProperty.clear();
|
| stopUpdating();
|
| }
|
|
|
| @@ -145,12 +137,12 @@ bool BatteryManager::hasPendingActivity() const
|
| {
|
| // Prevent V8 from garbage collecting the wrapper object if there are
|
| // event listeners attached to it.
|
| - return m_state == Resolved && hasEventListeners();
|
| + return hasEventListeners();
|
| }
|
|
|
| DEFINE_TRACE(BatteryManager)
|
| {
|
| - visitor->trace(m_resolver);
|
| + visitor->trace(m_batteryProperty);
|
| visitor->trace(m_batteryStatus);
|
| PlatformEventController::trace(visitor);
|
| RefCountedGarbageCollectedEventTargetWithInlineData<BatteryManager>::trace(visitor);
|
|
|