Commit 76ba6a74 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Include pending promise resolution in BatteryManager::HasPendingActivity.

This prevents the resolver from being prematurely collected.

Bug: 852751
Change-Id: I9516c9cdb84133291008cb045108e41baa956272
Reviewed-on: https://chromium-review.googlesource.com/1106543
Commit-Queue: Raphael Kubo da Costa (CET) <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568784}
parent b2b9dee1
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/gc.js"></script>
<script>
promise_test(async () => {
let batteryManagerPromise = navigator.getBattery();
gc();
await batteryManagerPromise;
}, "navigator.getBattery() should resolve even in the face of GC");
</script>
...@@ -113,8 +113,10 @@ void BatteryManager::ContextDestroyed(ExecutionContext*) { ...@@ -113,8 +113,10 @@ void BatteryManager::ContextDestroyed(ExecutionContext*) {
bool BatteryManager::HasPendingActivity() const { bool BatteryManager::HasPendingActivity() const {
// Prevent V8 from garbage collecting the wrapper object if there are // Prevent V8 from garbage collecting the wrapper object if there are
// event listeners attached to it. // event listeners or pending promises attached to it.
return GetExecutionContext() && HasEventListeners(); return HasEventListeners() ||
(battery_property_ &&
battery_property_->GetState() == ScriptPromisePropertyBase::kPending);
} }
void BatteryManager::Trace(blink::Visitor* visitor) { void BatteryManager::Trace(blink::Visitor* visitor) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment