Bug 216331

Summary: Port BaseAudioContext to the HTML event loop
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Web AudioAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, eric.carlson, ews-watchlist, ggaren, glenn, jer.noble, philipj, rniwa, sam, sergio, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 212611    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2020-09-09 15:40:18 PDT
Port BaseAudioContext to the HTML event loop.
Comment 1 Chris Dumez 2020-09-09 15:41:34 PDT
Created attachment 408377 [details]
Patch
Comment 2 Chris Dumez 2020-09-09 17:51:27 PDT
Created attachment 408389 [details]
Patch
Comment 3 Chris Dumez 2020-09-09 18:43:26 PDT
Created attachment 408392 [details]
Patch
Comment 4 Chris Dumez 2020-09-09 18:46:13 PDT
Created attachment 408394 [details]
Patch
Comment 5 Chris Dumez 2020-09-10 08:49:37 PDT
Created attachment 408449 [details]
Patch
Comment 6 Eric Carlson 2020-09-10 09:16:35 PDT
Comment on attachment 408449 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=408449&action=review

> LayoutTests/webaudio/audiocontext-state-interrupted.html:74
> +    setTimeout(function() {
> +        debug('');
> +        debug('Test 2: resume() while interrupted will cause interruption to end.')
>  
> -    context.onstatechange = secondInterruptionStarted;
> -    if (window.internals)
> -        evalAndLog('internals.beginMediaSessionInterruption("System")');
> +        context.onstatechange = secondInterruptionStarted;
> +        if (window.internals)
> +            evalAndLog('internals.beginMediaSessionInterruption("System")');
> +    }, 0);

It would be good to have a LayoutTests ChangeLog explaining why these changes are necessary.
Comment 7 Chris Dumez 2020-09-10 09:19:22 PDT
(In reply to Eric Carlson from comment #6)
> Comment on attachment 408449 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=408449&action=review
> 
> > LayoutTests/webaudio/audiocontext-state-interrupted.html:74
> > +    setTimeout(function() {
> > +        debug('');
> > +        debug('Test 2: resume() while interrupted will cause interruption to end.')
> >  
> > -    context.onstatechange = secondInterruptionStarted;
> > -    if (window.internals)
> > -        evalAndLog('internals.beginMediaSessionInterruption("System")');
> > +        context.onstatechange = secondInterruptionStarted;
> > +        if (window.internals)
> > +            evalAndLog('internals.beginMediaSessionInterruption("System")');
> > +    }, 0);
> 
> It would be good to have a LayoutTests ChangeLog explaining why these
> changes are necessary.

Yes. Basically the issue is we sometimes move to on test to another based a Promise resolution (e.g. context.resume() / context.suspend() return promises). The promise gets resolved *BEFORE* the statechange event gets fired, as per spec. The setTimeout(0) makes sure any pending statechange event has been fired before we move on to the next text (because the next test may rely on the statechange event and we don't want it to receive the event from the previous test).
Comment 8 Chris Dumez 2020-09-10 09:24:07 PDT
Created attachment 408450 [details]
Patch
Comment 9 EWS 2020-09-10 10:32:46 PDT
Committed r266835: <https://trac.webkit.org/changeset/266835>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408450 [details].
Comment 10 Radar WebKit Bug Importer 2020-09-10 10:33:16 PDT
<rdar://problem/68650688>