Skip to content

Commit

Permalink
Add maybe adjust function
Browse files Browse the repository at this point in the history
  • Loading branch information
chinedufn committed Jan 14, 2019
1 parent 666c1e4 commit 177ef22
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/webidl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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
}
}

0 comments on commit 177ef22

Please sign in to comment.