@@ -87,7 +87,7 @@ void SpeechSynthesis::setPlatformSynthesizer(Ref<PlatformSpeechSynthesizer>&& sy
8787 m_voiceList = std::nullopt ;
8888 m_utteranceQueue.clear ();
8989 // Finish current utterance.
90- speakingErrorOccurred ();
90+ speakingErrorOccurred (SpeechSynthesisErrorCode::Canceled );
9191 m_isPaused = false ;
9292 m_speechSynthesisClient = nullptr ;
9393}
@@ -193,7 +193,7 @@ void SpeechSynthesis::cancel()
193193 speechSynthesisClient->cancel ();
194194 // If we wait for cancel to callback speakingErrorOccurred, then m_currentSpeechUtterance will be null
195195 // and the event won't be processed. Instead we process the error immediately.
196- speakingErrorOccurred ();
196+ speakingErrorOccurred (SpeechSynthesisErrorCode::Canceled );
197197 m_currentSpeechUtterance = nullptr ;
198198 } else if (RefPtr platformSpeechSynthesizer = m_platformSpeechSynthesizer)
199199 platformSpeechSynthesizer->cancel ();
@@ -229,18 +229,18 @@ void SpeechSynthesis::resumeSynthesis()
229229 }
230230}
231231
232- void SpeechSynthesis::handleSpeakingCompleted (SpeechSynthesisUtterance& utterance, bool errorOccurred )
232+ void SpeechSynthesis::handleSpeakingCompleted (SpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error )
233233{
234234 ASSERT (m_currentSpeechUtterance);
235235 Ref<SpeechSynthesisUtterance> protect (utterance);
236236
237237 m_currentSpeechUtterance = nullptr ;
238238
239- if (errorOccurred )
240- utterance.errorEventOccurred (eventNames ().errorEvent , SpeechSynthesisErrorCode::Canceled );
239+ if (error )
240+ utterance.errorEventOccurred (eventNames ().errorEvent , *error );
241241 else
242242 utterance.eventOccurred (eventNames ().endEvent , 0 , 0 , String ());
243-
243+
244244 if (m_utteranceQueue.size ()) {
245245 Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst ();
246246 ASSERT (&utterance == firstUtterance.ptr ());
@@ -299,11 +299,11 @@ void SpeechSynthesis::didResumeSpeaking()
299299 didResumeSpeaking (protectedCurrentSpeechUtterance ()->platformUtterance ());
300300}
301301
302- void SpeechSynthesis::speakingErrorOccurred ()
302+ void SpeechSynthesis::speakingErrorOccurred (std::optional<SpeechSynthesisErrorCode> error )
303303{
304304 if (!m_currentSpeechUtterance)
305305 return ;
306- speakingErrorOccurred (protectedCurrentSpeechUtterance ()->platformUtterance ());
306+ speakingErrorOccurred (protectedCurrentSpeechUtterance ()->platformUtterance (), error );
307307}
308308
309309void SpeechSynthesis::boundaryEventOccurred (bool wordBoundary, unsigned charIndex, unsigned charLength)
@@ -341,13 +341,13 @@ void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& uttera
341341void SpeechSynthesis::didFinishSpeaking (PlatformSpeechSynthesisUtterance& utterance)
342342{
343343 if (utterance.client ())
344- handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), false );
344+ handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), std:: nullopt );
345345}
346346
347- void SpeechSynthesis::speakingErrorOccurred (PlatformSpeechSynthesisUtterance& utterance)
347+ void SpeechSynthesis::speakingErrorOccurred (PlatformSpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error )
348348{
349349 if (utterance.client ())
350- handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), true );
350+ handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), error );
351351}
352352
353353RefPtr<SpeechSynthesisUtterance> SpeechSynthesis::protectedCurrentSpeechUtterance ()
0 commit comments