use crate::{intrinsics::Intrinsic, source::Source};
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum JsHelperIntrinsic {
EmptyFunc,
DataView,
}
impl JsHelperIntrinsic {
pub fn deps() -> &'static [&'static Intrinsic] {
&[]
}
pub fn get_global_names() -> impl IntoIterator<Item = &'static str> {
["emptyFunc", "dataView"]
}
pub fn name(&self) -> &'static str {
match self {
Self::EmptyFunc => "emptyFunc",
Self::DataView => "dataView",
}
}
pub fn render(&self, output: &mut Source) {
match self {
Self::EmptyFunc => output.push_str("
const emptyFunc = () => {};
"),
Self::DataView => output.push_str("
let dv = new DataView(new ArrayBuffer());
const dataView = mem => dv.buffer === mem.buffer ? dv : dv = new DataView(mem.buffer);
"),
}
}
}