mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
Remove RefCell
This commit is contained in:
parent
ed28ce9db2
commit
acd69e97ee
@ -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<BTreeSet<&'static str>>
|
||||
pub(crate) immutable_f32_whitelist: BTreeSet<&'static str>
|
||||
}
|
||||
|
||||
/// We need to collect interface data during the first pass, to be used later.
|
||||
|
@ -82,6 +82,8 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>) -> Result<Program>
|
||||
|
||||
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<Ident> {
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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<BTreeSet<&'static str>> {
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user