@@ -83,7 +83,7 @@ void SpeechSynthesis::setPlatformSynthesizer(Ref<PlatformSpeechSynthesizer>&& sy
8383 m_voiceList = std::nullopt ;
8484 m_utteranceQueue.clear ();
8585 // Finish current utterance.
86- speakingErrorOccurred ();
86+ speakingErrorOccurred (SpeechSynthesisErrorCode::Canceled );
8787 m_isPaused = false ;
8888 m_speechSynthesisClient = nullptr ;
8989}
@@ -174,7 +174,7 @@ void SpeechSynthesis::cancel()
174174 m_speechSynthesisClient->cancel ();
175175 // If we wait for cancel to callback speakingErrorOccurred, then m_currentSpeechUtterance will be null
176176 // and the event won't be processed. Instead we process the error immediately.
177- speakingErrorOccurred ();
177+ speakingErrorOccurred (SpeechSynthesisErrorCode::Canceled );
178178 m_currentSpeechUtterance = nullptr ;
179179 } else if (m_platformSpeechSynthesizer)
180180 m_platformSpeechSynthesizer->cancel ();
@@ -202,18 +202,18 @@ void SpeechSynthesis::resumeSynthesis()
202202 }
203203}
204204
205- void SpeechSynthesis::handleSpeakingCompleted (SpeechSynthesisUtterance& utterance, bool errorOccurred )
205+ void SpeechSynthesis::handleSpeakingCompleted (SpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error )
206206{
207207 ASSERT (m_currentSpeechUtterance);
208208 Ref<SpeechSynthesisUtterance> protect (utterance);
209209
210210 m_currentSpeechUtterance = nullptr ;
211211
212- if (errorOccurred )
213- utterance.errorEventOccurred (eventNames ().errorEvent , SpeechSynthesisErrorCode::Canceled );
212+ if (error )
213+ utterance.errorEventOccurred (eventNames ().errorEvent , *error );
214214 else
215215 utterance.eventOccurred (eventNames ().endEvent , 0 , 0 , String ());
216-
216+
217217 if (m_utteranceQueue.size ()) {
218218 Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst ();
219219 ASSERT (&utterance == firstUtterance.ptr ());
@@ -272,11 +272,11 @@ void SpeechSynthesis::didResumeSpeaking()
272272 didResumeSpeaking (*protectedCurrentSpeechUtterance ()->platformUtterance ());
273273}
274274
275- void SpeechSynthesis::speakingErrorOccurred ()
275+ void SpeechSynthesis::speakingErrorOccurred (std::optional<SpeechSynthesisErrorCode> error )
276276{
277277 if (!m_currentSpeechUtterance)
278278 return ;
279- speakingErrorOccurred (*protectedCurrentSpeechUtterance ()->platformUtterance ());
279+ speakingErrorOccurred (*protectedCurrentSpeechUtterance ()->platformUtterance (), error );
280280}
281281
282282void SpeechSynthesis::boundaryEventOccurred (bool wordBoundary, unsigned charIndex, unsigned charLength)
@@ -314,13 +314,13 @@ void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& uttera
314314void SpeechSynthesis::didFinishSpeaking (PlatformSpeechSynthesisUtterance& utterance)
315315{
316316 if (utterance.client ())
317- handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), false );
317+ handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), std:: nullopt );
318318}
319319
320- void SpeechSynthesis::speakingErrorOccurred (PlatformSpeechSynthesisUtterance& utterance)
320+ void SpeechSynthesis::speakingErrorOccurred (PlatformSpeechSynthesisUtterance& utterance, std::optional<SpeechSynthesisErrorCode> error )
321321{
322322 if (utterance.client ())
323- handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), true );
323+ handleSpeakingCompleted (static_cast <SpeechSynthesisUtterance&>(*utterance.client ()), error );
324324}
325325
326326RefPtr<SpeechSynthesisUtterance> SpeechSynthesis::protectedCurrentSpeechUtterance ()
0 commit comments