Add maybe adjust function

This commit is contained in:
Chinedu Francis Nwafili 2019-01-14 17:45:43 -05:00
parent 666c1e4584
commit 177ef22673
No known key found for this signature in database
GPG Key ID: 4BF2F74EA7B46D27

View File

@ -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
}
}