Truly independent web browser
LibWeb: Reject an out-of-range SpeechRecognitionPhrase boost
Shannon Booth096b359b1997
diff --git a/Libraries/LibWeb/Bindings/Rust/src/speech/speech_recognition_phrase.rs b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_recognition_phrase.rsindex 2d5663eddb7..63869d39fe1 100644--- a/Libraries/LibWeb/Bindings/Rust/src/speech/speech_recognition_phrase.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_recognition_phrase.rs@@ -10,7 +10,7 @@ use ak::Utf16String;use libjs_rust::api::Trace;use crate::bindings::interface::Wrappable;-use crate::bindings::{CallContext, WebIdlResult};+use crate::bindings::{CallContext, Exception, WebIdlResult};#[derive(Trace)]#[gc(crate = libjs_rust)]@@ -28,6 +28,18 @@ impl Wrappable for SpeechRecognitionPhrase {}impl SpeechRecognitionPhrase {// https://wicg.github.io/speech-api/#dom-speechrecognitionphrase-speechrecognitionphrasepub(crate) fn construct(_: &mut CallContext, phrase: Utf16String, boost: f32) -> WebIdlResult<Self> {+ // 1. If boost is smaller than 0.0 or greater than 10.0, throw a SyntaxError and abort these steps.+ if !(0.0..=10.0).contains(&boost) {+ return Err(Exception::Dom(+ "SyntaxError",+ Utf16String::from_ascii(b"SpeechRecognitionPhrase boost must be between 0 and 10"),+ ));+ }++ // 2. Let phr be a new object of type SpeechRecognitionPhrase.+ // 3. Set phr.[[phrase]] to be the value of phrase.+ // 4. Set phr.[[boost]] to be the value of boost.+ // 5. Return phr.Ok(Self { phrase, boost })}diff --git a/Tests/LibWeb/Text/expected/Speech/SpeechRecognitionPhrase-boost-range.txt b/Tests/LibWeb/Text/expected/Speech/SpeechRecognitionPhrase-boost-range.txtnew file mode 100644index 00000000000..8065c6b0ca5--- /dev/null+++ b/Tests/LibWeb/Text/expected/Speech/SpeechRecognitionPhrase-boost-range.txt@@ -0,0 +1,8 @@+boost=-1: SyntaxError+boost=-0.0001: SyntaxError+boost=0: 0+boost=1: 1+boost=10: 10+boost=10.0001: SyntaxError+boost=11: SyntaxError+default: 1diff --git a/Tests/LibWeb/Text/input/Speech/SpeechRecognitionPhrase-boost-range.html b/Tests/LibWeb/Text/input/Speech/SpeechRecognitionPhrase-boost-range.htmlnew file mode 100644index 00000000000..9dfc0505334--- /dev/null+++ b/Tests/LibWeb/Text/input/Speech/SpeechRecognitionPhrase-boost-range.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const boost of [-1, -0.0001, 0, 1, 10, 10.0001, 11]) {+ try {+ const phrase = new SpeechRecognitionPhrase("hello", boost);+ println(`boost=${boost}: ${phrase.boost}`);+ } catch (e) {+ println(`boost=${boost}: ${e.name}`);+ }+ }+ println(`default: ${new SpeechRecognitionPhrase("hello").boost}`);+ });+</script>