mirror of
https://github.com/servo/servo.git
synced 2025-07-05 14:33:38 +01:00
fix intermittent Option::unwrap in timers
not allow to fire timers installed during another timer call
This commit is contained in:
parent
a8cbc28643
commit
d891e75d9d
4 changed files with 55 additions and 8 deletions
|
@ -23,7 +23,7 @@ use std::rc::Rc;
|
|||
use util::mem::HeapSizeOf;
|
||||
use util::str::DOMString;
|
||||
|
||||
#[derive(JSTraceable, PartialEq, Eq, Copy, Clone, HeapSizeOf, Hash, PartialOrd, Ord)]
|
||||
#[derive(JSTraceable, PartialEq, Eq, Copy, Clone, HeapSizeOf, Hash, PartialOrd, Ord, Debug)]
|
||||
pub struct TimerHandle(i32);
|
||||
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
|
@ -253,16 +253,22 @@ impl ActiveTimers {
|
|||
// Since the event id was the expected one, at least one timer should be due.
|
||||
assert!(base_time >= self.timers.borrow().last().unwrap().next_call);
|
||||
|
||||
// select timers to run to prevent firing timers
|
||||
// that were installed during fire of another timer
|
||||
let mut timers_to_run: Vec<Timer> = Vec::new();
|
||||
|
||||
loop {
|
||||
let timer = {
|
||||
let mut timers = self.timers.borrow_mut();
|
||||
let mut timers = self.timers.borrow_mut();
|
||||
|
||||
if timers.is_empty() || timers.last().unwrap().next_call > base_time {
|
||||
break;
|
||||
}
|
||||
if timers.is_empty() || timers.last().unwrap().next_call > base_time {
|
||||
break;
|
||||
}
|
||||
|
||||
timers_to_run.push(timers.pop().unwrap());
|
||||
}
|
||||
|
||||
for timer in timers_to_run {
|
||||
|
||||
timers.pop().unwrap()
|
||||
};
|
||||
let callback = timer.callback.clone();
|
||||
|
||||
// prep for step 6 in nested set_timeout_or_interval calls
|
||||
|
|
|
@ -5661,6 +5661,12 @@
|
|||
"url": "/_mozilla/mozilla/textcontent.html"
|
||||
}
|
||||
],
|
||||
"mozilla/timer_eventInvalidation.html": [
|
||||
{
|
||||
"path": "mozilla/timer_eventInvalidation.html",
|
||||
"url": "/_mozilla/mozilla/timer_eventInvalidation.html"
|
||||
}
|
||||
],
|
||||
"mozilla/title.html": [
|
||||
{
|
||||
"path": "mozilla/title.html",
|
||||
|
|
21
tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation.html
Normal file
21
tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
async_test(function(test) {
|
||||
// couldn't reproduce this behaviour without iframe
|
||||
var iframe = document.createElement('iframe');
|
||||
window.addEventListener('test_done', function() {
|
||||
// if event invalidation is not properly implemented
|
||||
// servo will crash during a short period of time
|
||||
setTimeout(() => test.done(), 50);
|
||||
}, false);
|
||||
iframe.src = 'timer_eventInvalidation_test.html';
|
||||
document.body.appendChild(iframe);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,14 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
var e = new Event('test_done');
|
||||
window.parent.dispatchEvent(e);
|
||||
}, 0);
|
||||
}, 0);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue