aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorSimon Wülker <simon.wuelker@arcor.de>2024-11-16 00:15:32 +0100
committerGitHub <noreply@github.com>2024-11-15 23:15:32 +0000
commitee63174d6ff0b3b7d9b255fc47c72a82ae63bc09 (patch)
tree13f4053f52df17073fec1abb3704b1f9b7a3db43 /components/script/dom
parent7ae0459360dad977d24fe81fbb322c92308f6c88 (diff)
downloadservo-ee63174d6ff0b3b7d9b255fc47c72a82ae63bc09.tar.gz
servo-ee63174d6ff0b3b7d9b255fc47c72a82ae63bc09.zip
subtlecrypto: Don't throw exceptions twice when converting to Algorithm object (#34239)
* Don't throw exceptions twice when converting to Algorithm object Removes match statements like ```rust let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle()) else { return Err(Error::Syntax); }; ``` These don't cause issues if `Algorithm::new` returns `Ok(ConversionResult::Failure`, but in the case of `Err(())` the implementation already called `throw_type_error` and we must not throw an additional Syntax error, otherwise we'll crash. Luckily, this case is already handled elsewhere by the `value_from_js_object` macro. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Test that calling subtlecrypto methods with empty algorithm objects throws a TypeError The WebCryptoAPI spec does not tell us which error to throw exactly, but according to https://webidl.spec.whatwg.org/ it should be a TypeError. This previously crashed servo. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/subtlecrypto.rs32
1 files changed, 7 insertions, 25 deletions
diff --git a/components/script/dom/subtlecrypto.rs b/components/script/dom/subtlecrypto.rs
index efb3009a831..26c415b04c7 100644
--- a/components/script/dom/subtlecrypto.rs
+++ b/components/script/dom/subtlecrypto.rs
@@ -1126,10 +1126,7 @@ fn normalize_algorithm_for_get_key_length(
match algorithm {
AlgorithmIdentifier::Object(obj) => {
rooted!(in(*cx) let value = ObjectValue(obj.get()));
- let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle())
- else {
- return Err(Error::Syntax);
- };
+ let algorithm = value_from_js_object!(Algorithm, cx, value);
let name = algorithm.name.str();
let normalized_algorithm = if name.eq_ignore_ascii_case(ALG_AES_CBC) ||
@@ -1162,10 +1159,7 @@ fn normalize_algorithm_for_digest(
let name = match algorithm {
AlgorithmIdentifier::Object(obj) => {
rooted!(in(*cx) let value = ObjectValue(obj.get()));
- let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle())
- else {
- return Err(Error::Syntax);
- };
+ let algorithm = value_from_js_object!(Algorithm, cx, value);
algorithm.name.str().to_uppercase()
},
@@ -1191,10 +1185,7 @@ fn normalize_algorithm_for_import_key(
let name = match algorithm {
AlgorithmIdentifier::Object(obj) => {
rooted!(in(*cx) let value = ObjectValue(obj.get()));
- let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle())
- else {
- return Err(Error::Syntax);
- };
+ let algorithm = value_from_js_object!(Algorithm, cx, value);
let name = algorithm.name.str().to_uppercase();
if name == ALG_HMAC {
@@ -1230,9 +1221,7 @@ fn normalize_algorithm_for_derive_bits(
};
rooted!(in(*cx) let value = ObjectValue(obj.get()));
- let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle()) else {
- return Err(Error::Syntax);
- };
+ let algorithm = value_from_js_object!(Algorithm, cx, value);
let normalized_algorithm = if algorithm.name.str().eq_ignore_ascii_case(ALG_PBKDF2) {
let params = value_from_js_object!(Pbkdf2Params, cx, value);
@@ -1260,9 +1249,7 @@ fn normalize_algorithm_for_encrypt_or_decrypt(
};
rooted!(in(*cx) let value = ObjectValue(obj.get()));
- let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle()) else {
- return Err(Error::Syntax);
- };
+ let algorithm = value_from_js_object!(Algorithm, cx, value);
let name = algorithm.name.str();
let normalized_algorithm = if name.eq_ignore_ascii_case(ALG_AES_CBC) {
@@ -1287,10 +1274,7 @@ fn normalize_algorithm_for_sign_or_verify(
let name = match algorithm {
AlgorithmIdentifier::Object(obj) => {
rooted!(in(*cx) let value = ObjectValue(obj.get()));
- let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle())
- else {
- return Err(Error::Syntax);
- };
+ let algorithm = value_from_js_object!(Algorithm, cx, value);
algorithm.name.str().to_uppercase()
},
@@ -1316,9 +1300,7 @@ fn normalize_algorithm_for_generate_key(
};
rooted!(in(*cx) let value = ObjectValue(obj.get()));
- let Ok(ConversionResult::Success(algorithm)) = Algorithm::new(cx, value.handle()) else {
- return Err(Error::Syntax);
- };
+ let algorithm = value_from_js_object!(Algorithm, cx, value);
let name = algorithm.name.str();
let normalized_algorithm =