Skip to content

Commit

Permalink
Fix attributes being expanded wrong in macro
Browse files Browse the repository at this point in the history
  • Loading branch information
DelSkayn committed Aug 4, 2023
1 parent 2f6187a commit fc6bebd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 6 additions & 2 deletions core/src/value/array_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,16 @@ impl<'js> IntoJs<'js> for ArrayBuffer<'js> {
}
}

impl Object<'js> {
impl<'js> Object<'js> {
/// Returns wether the object is an instance of ArrayBuffer.
pub fn is_array_buffer(&self) -> bool {
ArrayBuffer::get_raw(&object.0).is_some()
ArrayBuffer::get_raw(&self.0).is_some()
}

/// Interprete as [`ArrayBuffer`]
///
/// # Safety
/// Yous should be sure that the object actually is the required type.
pub unsafe fn ref_array_buffer(&self) -> &ArrayBuffer {
mem::transmute(self)
}
Expand Down
14 changes: 11 additions & 3 deletions core/src/value/typed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,19 @@ impl<'js, T> IntoJs<'js> for TypedArray<'js, T> {

impl<'js> Object<'js> {
fn is_typed_array<T: TypedArrayItem>(&self) -> bool {
let class: Function = self.ctx.globals().get(T::CLASS_NAME)?;
object.is_instance_of(class)
// This should not error unless the global ArrayBuffer object suddenly isn't a Function
// anymore.
let Ok(class) = self.ctx.globals().get::<_, Function>(T::CLASS_NAME) else {
return false;
};
self.is_instance_of(class)
}

unsafe fn ref_typed_array<T: TypedArrayItem>(&self) -> &TypedArray<T> {
/// Interprete as [`TypedArray`]
///
/// # Safety
/// Yous should be sure that the object actually is the required type.
pub unsafe fn ref_typed_array<T: TypedArrayItem>(&self) -> &TypedArray<T> {
mem::transmute(self)
}

Expand Down
4 changes: 2 additions & 2 deletions macro/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl Class {
..
} => {
quote! {
#([#attrs])*
#(#attrs)*
#vis #enum_token #ident #generics { #variants }
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ impl Class {
};

quote! {
#([#attrs])*
#(#attrs)*
#vis #struct_token #ident #generics #fields
}
}
Expand Down

0 comments on commit fc6bebd

Please sign in to comment.