From d90edd169aae1e16c1ef8b7bd4b2e0d93dda8ba2 Mon Sep 17 00:00:00 2001 From: Samson <16504129+sagudev@users.noreply.github.com> Date: Mon, 19 Aug 2024 21:42:01 +0200 Subject: [PATCH] Impl byte_size on Scalar::Type (#499) Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- mozjs-sys/src/jsimpls.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mozjs-sys/src/jsimpls.rs b/mozjs-sys/src/jsimpls.rs index 21ea1748db..2eb11d37e4 100644 --- a/mozjs-sys/src/jsimpls.rs +++ b/mozjs-sys/src/jsimpls.rs @@ -19,6 +19,7 @@ use crate::jsapi::JSPropertySpec; use crate::jsapi::JSPropertySpec_Kind; use crate::jsapi::JSPropertySpec_Name; use crate::jsapi::JS; +use crate::jsapi::JS::Scalar::Type; use crate::jsgc::RootKind; use crate::jsid::VoidId; use crate::jsval::UndefinedValue; @@ -574,3 +575,19 @@ impl mozilla::Range { } } } + +impl Type { + /// Returns byte size of Type (if possible to determine) + /// + /// + pub const fn byte_size(&self) -> Option { + match self { + Type::Int8 | Type::Uint8 | Type::Uint8Clamped => Some(1), + Type::Int16 | Type::Uint16 | Type::Float16 => Some(2), + Type::Int32 | Type::Uint32 | Type::Float32 => Some(4), + Type::Int64 | Type::Float64 | Type::BigInt64 | Type::BigUint64 => Some(8), + Type::Simd128 => Some(16), + Type::MaxTypedArrayViewType => None, + } + } +}