File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ use crate::jsapi::JSPropertySpec;
1919use crate :: jsapi:: JSPropertySpec_Kind ;
2020use crate :: jsapi:: JSPropertySpec_Name ;
2121use crate :: jsapi:: JS ;
22+ use crate :: jsapi:: JS :: Scalar :: Type ;
2223use crate :: jsgc:: RootKind ;
2324use crate :: jsid:: VoidId ;
2425use crate :: jsval:: UndefinedValue ;
@@ -574,3 +575,19 @@ impl<T> mozilla::Range<T> {
574575 }
575576 }
576577}
578+
579+ impl Type {
580+ /// Returns byte size of Type (if possible to determine)
581+ ///
582+ /// <https://searchfox.org/mozilla-central/rev/396a6123691f7ab3ffb449dcbe95304af6f9df3c/js/public/ScalarType.h#66>
583+ pub const fn byte_size ( & self ) -> Option < usize > {
584+ match self {
585+ Type :: Int8 | Type :: Uint8 | Type :: Uint8Clamped => Some ( 1 ) ,
586+ Type :: Int16 | Type :: Uint16 | Type :: Float16 => Some ( 2 ) ,
587+ Type :: Int32 | Type :: Uint32 | Type :: Float32 => Some ( 4 ) ,
588+ Type :: Int64 | Type :: Float64 | Type :: BigInt64 | Type :: BigUint64 => Some ( 8 ) ,
589+ Type :: Simd128 => Some ( 16 ) ,
590+ Type :: MaxTypedArrayViewType => None ,
591+ }
592+ }
593+ }
You can’t perform that action at this time.
0 commit comments