diff --git a/crates/webidl/src/first_pass.rs b/crates/webidl/src/first_pass.rs index eeee69ab..02ab48e0 100644 --- a/crates/webidl/src/first_pass.rs +++ b/crates/webidl/src/first_pass.rs @@ -22,7 +22,6 @@ use weedle::{DictionaryDefinition, PartialDictionaryDefinition}; use super::Result; use util; use util::camel_case_ident; -use std::cell::RefCell; /// Collection of constructs that may use partial. #[derive(Default)] @@ -38,7 +37,7 @@ pub(crate) struct FirstPassRecord<'src> { pub(crate) dictionaries: BTreeMap<&'src str, DictionaryData<'src>>, pub(crate) callbacks: BTreeSet<&'src str>, pub(crate) callback_interfaces: BTreeMap<&'src str, CallbackInterfaceData<'src>>, - pub(crate) immutable_f32_whitelist: RefCell> + pub(crate) immutable_f32_whitelist: BTreeSet<&'static str> } /// We need to collect interface data during the first pass, to be used later. diff --git a/crates/webidl/src/lib.rs b/crates/webidl/src/lib.rs index 2e11b128..637070c0 100644 --- a/crates/webidl/src/lib.rs +++ b/crates/webidl/src/lib.rs @@ -82,6 +82,8 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>) -> Result let mut first_pass_record: FirstPassRecord = Default::default(); first_pass_record.builtin_idents = builtin_idents(); + first_pass_record.immutable_f32_whitelist = immutable_f32_whitelist(); + definitions.first_pass(&mut first_pass_record, ())?; let mut program = Default::default(); let mut submodules = Vec::new(); @@ -179,6 +181,26 @@ fn builtin_idents() -> BTreeSet { ) } +fn immutable_f32_whitelist() -> BTreeSet<&'static str> { + BTreeSet::from_iter( + vec![ + // WebGlRenderingContext + "uniform1fv", + "uniform2fv", + "uniform3fv", + "uniform4fv", + "uniformMatrix2fv", + "uniformMatrix3fv", + "uniformMatrix4fv", + "vertexAttrib1fv", + "vertexAttrib2fv", + "vertexAttrib3fv", + "vertexAttrib4fv", + // TODO: Add another type's functions here. Leave a comment header with the type name + ] + ) +} + /// Run codegen on the AST to generate rust code. fn compile_ast(mut ast: Program) -> String { // Iteratively prune all entries from the AST which reference undefined diff --git a/crates/webidl/src/util.rs b/crates/webidl/src/util.rs index 6e32767c..f0e89624 100644 --- a/crates/webidl/src/util.rs +++ b/crates/webidl/src/util.rs @@ -13,9 +13,6 @@ use weedle::literal::{ConstValue, FloatLit, IntegerLit}; use first_pass::{FirstPassRecord, OperationData, OperationId, Signature}; use idl_type::{IdlType, ToIdlType}; -use std::collections::BTreeSet; -use std::cell::Ref; - /// For variadic operations an overload with a `js_sys::Array` argument is generated alongside with /// `operation_name_0`, `operation_name_1`, `operation_name_2`, ..., `operation_name_n` overloads /// which have the count of arguments for passing values to the variadic argument @@ -651,7 +648,7 @@ impl<'src> FirstPassRecord<'src> { _ => return idl_type }; - if self.immutable_f32_whitelist().contains(op) { + if self.immutable_f32_whitelist.contains(op) { flag_slices_immutable(&mut idl_type) } @@ -660,29 +657,7 @@ impl<'src> FirstPassRecord<'src> { idl_type } - fn immutable_f32_whitelist(&self) -> Ref> { - if self.immutable_f32_whitelist.borrow().len() == 0 { - *self.immutable_f32_whitelist.borrow_mut() = vec![ - // WebGlRenderingContext - "uniform1fv", - "uniform2fv", - "uniform3fv", - "uniform4fv", - "uniformMatrix2fv", - "uniformMatrix3fv", - "uniformMatrix4fv", - "vertexAttrib1fv", - "vertexAttrib2fv", - "vertexAttrib3fv", - "vertexAttrib4fv", - // TODO: Add another type's functions here. Leave a comment header with the type name - ] - .into_iter() - .collect(); - } - self.immutable_f32_whitelist.borrow() - } } /// Search for an attribute by name in some webidl object's attributes.