diff --git a/crates/webidl/src/util.rs b/crates/webidl/src/util.rs index 412e45d7c66..629b94e8cdf 100644 --- a/crates/webidl/src/util.rs +++ b/crates/webidl/src/util.rs @@ -433,7 +433,10 @@ impl<'src> FirstPassRecord<'src> { ); signatures.push((signature, idl_args.clone())); } - idl_args.push(arg.ty.to_idl_type(self)); + + let idl_type = arg.ty.to_idl_type(self); + let idl_type = maybe_adjust(idl_type, id); + idl_args.push(idl_type); } signatures.push((signature, idl_args)); } @@ -707,3 +710,21 @@ pub fn public() -> syn::Visibility { pub_token: Default::default(), }) } + +/// When generating our web_sys APIs we default to setting slice references that +/// get passed to JS as mutable in case they get mutated in JS. +/// +/// In certain cases we know for sure that the slice will not get mutated - for +/// example when working with the WebGlRenderingContext APIs. +/// +/// Here we implement a whitelist for those cases. This whitelist is currently +/// maintained by hand. +fn maybe_adjust<'a> (idl_type: IdlType<'a>, id: &'a OperationId) -> IdlType<'a> { + match id { + OperationId::Operation(Some(op)) => { + // TODO: `match op` and return an adjusted idl_type if necessary + idl_type + } + _ => idl_type + } +}