Skip to content

Commit

Permalink
Filter interface fixes by type name
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Aug 29, 2023
1 parent 7e4f73e commit ea0fab1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/web-sys/src/features/gen_CanvasPattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ extern "C" {
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `CanvasPattern`, `SvgMatrix`*"]
pub fn set_transform_with_default_dom_matrix_2d_init(this: &CanvasPattern, matrix: &SvgMatrix);
pub fn set_transform(this: &CanvasPattern, matrix: &SvgMatrix);
}
16 changes: 14 additions & 2 deletions crates/webidl/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ pub(crate) static IMMUTABLE_SLICE_WHITELIST: Lazy<BTreeSet<&'static str>> = Lazy
])
});

pub(crate) static FIXED_INTERFACES: Lazy<BTreeMap<&'static str, &'static str>> = Lazy::new(|| {
BTreeMap::from_iter(vec![
pub(crate) static FIXED_INTERFACES: Lazy<
BTreeMap<&'static str, BTreeMap<&'static str, &'static str>>,
> = Lazy::new(|| {
let image_bitmap = BTreeMap::from_iter([
("create_image_bitmap_with_html_image_element_and_i32_and_a_sy_and_a_sw_and_a_sh", "create_image_bitmap_with_html_image_element_and_a_sx_and_a_sy_and_a_sw_and_a_sh"),
("create_image_bitmap_with_svg_image_element_and_i32_and_a_sy_and_a_sw_and_a_sh", "create_image_bitmap_with_svg_image_element_and_a_sx_and_a_sy_and_a_sw_and_a_sh"),
("create_image_bitmap_with_html_canvas_element_and_i32_and_a_sy_and_a_sw_and_a_sh", "create_image_bitmap_with_html_canvas_element_and_a_sx_and_a_sy_and_a_sw_and_a_sh"),
Expand All @@ -117,7 +119,17 @@ pub(crate) static FIXED_INTERFACES: Lazy<BTreeMap<&'static str, &'static str>> =
("create_image_bitmap_with_video_frame_and_i32_and_a_sy_and_a_sw_and_a_sh_and_a_options", "create_image_bitmap_with_video_frame_and_a_sx_and_a_sy_and_a_sw_and_a_sh_and_a_options"),
("create_image_bitmap_with_blob_and_i32_and_a_sy_and_a_sw_and_a_sh_and_a_options", "create_image_bitmap_with_blob_and_a_sx_and_a_sy_and_a_sw_and_a_sh_and_a_options"),
("create_image_bitmap_with_image_data_and_i32_and_a_sy_and_a_sw_and_a_sh_and_a_options", "create_image_bitmap_with_image_data_and_a_sx_and_a_sy_and_a_sw_and_a_sh_and_a_options"),
]);

let canvas_rendering_context = BTreeMap::from_iter([
("set_transform", "set_transform_with_default_dom_matrix_2d_init"),
("set_transform_with_a_and_b_and_c_and_d_and_e_and_f", "set_transform"),
]);

BTreeMap::from_iter([
("Window", image_bitmap.clone()),
("WorkerGlobalScope", image_bitmap),
("CanvasRenderingContext2d", canvas_rendering_context.clone()),
("OffscreenCanvasRenderingContext2d", canvas_rendering_context),
])
});
9 changes: 5 additions & 4 deletions crates/webidl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ impl<'src> FirstPassRecord<'src> {
}
}

for x in self.create_imports(None, id, data, false, &HashSet::new()) {
for x in self.create_imports(None, None, id, data, false, &HashSet::new()) {
functions.push(Function {
name: x.name,
js_name: x.js_name,
Expand Down Expand Up @@ -588,7 +588,7 @@ impl<'src> FirstPassRecord<'src> {
}

for (id, op_data) in data.operations.iter() {
self.member_operation(&mut methods, data, id, op_data, unstable_types);
self.member_operation(&name.to_string(), &mut methods, data, id, op_data, unstable_types);
}

for mixin_data in self.all_mixins(&js_name) {
Expand All @@ -614,7 +614,7 @@ impl<'src> FirstPassRecord<'src> {
}

for (id, op_data) in mixin_data.operations.iter() {
self.member_operation(&mut methods, data, id, op_data, unstable_types);
self.member_operation(&name.to_string(), &mut methods, data, id, op_data, unstable_types);
}
}

Expand Down Expand Up @@ -702,6 +702,7 @@ impl<'src> FirstPassRecord<'src> {

fn member_operation(
&self,
type_name: &str,
methods: &mut Vec<InterfaceMethod>,
data: &InterfaceData<'src>,
id: &OperationId<'src>,
Expand All @@ -711,7 +712,7 @@ impl<'src> FirstPassRecord<'src> {
let attrs = data.definition_attributes;
let unstable = data.stability.is_unstable();

for method in self.create_imports(attrs, id, op_data, unstable, unstable_types) {
for method in self.create_imports(Some(type_name), attrs, id, op_data, unstable, unstable_types) {
methods.push(method);
}
}
Expand Down
10 changes: 8 additions & 2 deletions crates/webidl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub enum TypePosition {
impl<'src> FirstPassRecord<'src> {
pub fn create_imports(
&self,
type_name: Option<&str>,
container_attrs: Option<&ExtendedAttributeList<'src>>,
id: &OperationId<'src>,
data: &OperationData<'src>,
Expand Down Expand Up @@ -500,8 +501,13 @@ impl<'src> FirstPassRecord<'src> {
}

for interface in &mut ret {
if let Some(fixed) = FIXED_INTERFACES.get(&interface.name.to_string().as_ref()) {
interface.name = rust_ident(fixed);
if let Some(type_name) = type_name {
if let Some(map) = FIXED_INTERFACES.get(type_name) {
if let Some(fixed) = map.get(&interface.name.to_string().as_ref())
{
interface.name = rust_ident(fixed);
}
}
}
}

Expand Down

0 comments on commit ea0fab1

Please sign in to comment.