@@ -167,7 +167,7 @@ void SpeechSynthesis::cancel()
167167 m_speechSynthesisClient->cancel ();
168168 // If we wait for cancel to callback speakingErrorOccurred, then m_currentSpeechUtterance will be null
169169 // and the event won't be processed. Instead we process the error immediately.
170- speakingErrorOccurred ();
170+ speakingErrorOccurred (SpeechSynthesisErrorCode::Canceled );
171171 m_currentSpeechUtterance = nullptr ;
172172 } else if (m_platformSpeechSynthesizer) {
173173 m_platformSpeechSynthesizer->cancel ();
@@ -207,17 +207,17 @@ void SpeechSynthesis::fireErrorEvent(const AtomString& type, SpeechSynthesisUtte
207207 utterance.dispatchEvent (SpeechSynthesisErrorEvent::create (type, { { &utterance, 0 , 0 , static_cast <float >((MonotonicTime::now () - utterance.startTime ()).seconds ()), { } }, errorCode }));
208208}
209209
210- void SpeechSynthesis::handleSpeakingCompleted (SpeechSynthesisUtterance& utterance, bool errorOccurred )
210+ void SpeechSynthesis::handleSpeakingCompleted (SpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error )
211211{
212212 ASSERT (m_currentSpeechUtterance);
213213 Ref<SpeechSynthesisUtterance> protect (utterance);
214214
215215 m_currentSpeechUtterance = nullptr ;
216216
217- if (errorOccurred)
218- fireErrorEvent (eventNames ().errorEvent , utterance, SpeechSynthesisErrorCode::Canceled);
219- else
217+ if (!error)
220218 fireEvent (eventNames ().endEvent , utterance, 0 , 0 , String ());
219+ else
220+ fireErrorEvent (eventNames ().errorEvent , utterance, *error);
221221
222222 if (m_utteranceQueue.size ()) {
223223 Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst ();
@@ -276,11 +276,11 @@ void SpeechSynthesis::didResumeSpeaking()
276276 didResumeSpeaking (*m_currentSpeechUtterance->platformUtterance ());
277277}
278278
279- void SpeechSynthesis::speakingErrorOccurred ()
279+ void SpeechSynthesis::speakingErrorOccurred (std::optional<SpeechSynthesisErrorCode> error )
280280{
281281 if (!m_currentSpeechUtterance)
282282 return ;
283- speakingErrorOccurred (*m_currentSpeechUtterance->platformUtterance ());
283+ speakingErrorOccurred (*m_currentSpeechUtterance->platformUtterance (), error );
284284}
285285
286286void SpeechSynthesis::boundaryEventOccurred (bool wordBoundary, unsigned charIndex, unsigned charLength)
@@ -318,13 +318,13 @@ void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& uttera
318318void SpeechSynthesis::didFinishSpeaking (PlatformSpeechSynthesisUtterance& utterance)
319319{
320320 if (utterance.client ())
321- handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), false );
321+ handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), std:: nullopt );
322322}
323323
324- void SpeechSynthesis::speakingErrorOccurred (PlatformSpeechSynthesisUtterance& utterance)
324+ void SpeechSynthesis::speakingErrorOccurred (PlatformSpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error )
325325{
326326 if (utterance.client ())
327- handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), true );
327+ handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), error );
328328}
329329
330330} // namespace WebCore
0 commit comments