diff --git a/mozjs/src/jsglue.cpp b/mozjs/src/jsglue.cpp index 2d23b0a34a1..14f84506d42 100644 --- a/mozjs/src/jsglue.cpp +++ b/mozjs/src/jsglue.cpp @@ -937,6 +937,8 @@ JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int16, int16_t) JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint16, uint16_t) JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Int32, int32_t) JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(BigInt64, int64_t) +JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(BigUint64, uint64_t) JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float) JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double) diff --git a/mozjs/src/typedarray.rs b/mozjs/src/typedarray.rs index c87d9a7774a..72620f9718e 100644 --- a/mozjs/src/typedarray.rs +++ b/mozjs/src/typedarray.rs @@ -9,6 +9,8 @@ use crate::conversions::ConversionResult; use crate::conversions::FromJSValConvertible; use crate::conversions::ToJSValConvertible; +use crate::glue::GetBigInt64ArrayLengthAndData; +use crate::glue::GetBigUint64ArrayLengthAndData; use crate::glue::GetFloat32ArrayLengthAndData; use crate::glue::GetFloat64ArrayLengthAndData; use crate::glue::GetInt16ArrayLengthAndData; @@ -26,6 +28,8 @@ use crate::jsapi::JSContext; use crate::jsapi::JSObject; use crate::jsapi::JSTracer; use crate::jsapi::JS_GetArrayBufferViewType; +use crate::jsapi::JS_GetBigInt64ArrayData; +use crate::jsapi::JS_GetBigUint64ArrayData; use crate::jsapi::JS_GetFloat32ArrayData; use crate::jsapi::JS_GetFloat64ArrayData; use crate::jsapi::JS_GetInt16ArrayData; @@ -36,6 +40,8 @@ use crate::jsapi::JS_GetUint16ArrayData; use crate::jsapi::JS_GetUint32ArrayData; use crate::jsapi::JS_GetUint8ArrayData; use crate::jsapi::JS_GetUint8ClampedArrayData; +use crate::jsapi::JS_NewBigInt64Array; +use crate::jsapi::JS_NewBigUint64Array; use crate::jsapi::JS_NewFloat32Array; use crate::jsapi::JS_NewFloat64Array; use crate::jsapi::JS_NewInt16Array; @@ -49,6 +55,8 @@ use crate::jsapi::NewArrayBuffer; use crate::jsapi::Type; use crate::jsapi::UnwrapArrayBuffer; use crate::jsapi::UnwrapArrayBufferView; +use crate::jsapi::UnwrapBigInt64Array; +use crate::jsapi::UnwrapBigUint64Array; use crate::jsapi::UnwrapFloat32Array; use crate::jsapi::UnwrapFloat64Array; use crate::jsapi::UnwrapInt16Array; @@ -354,6 +362,14 @@ typed_array_element!( JS_NewUint32Array, JS_GetUint32ArrayData ); +typed_array_element!( + BigUint64, + u64, + UnwrapBigUint64Array, + GetBigUint64ArrayLengthAndData, + JS_NewBigUint64Array, + JS_GetBigUint64ArrayData +); typed_array_element!( Int8, i8, @@ -378,6 +394,14 @@ typed_array_element!( JS_NewInt32Array, JS_GetInt32ArrayData ); +typed_array_element!( + BigInt64, + i64, + UnwrapBigInt64Array, + GetBigInt64ArrayLengthAndData, + JS_NewBigInt64Array, + JS_GetBigInt64ArrayData +); typed_array_element!( Float32, f32, @@ -433,6 +457,8 @@ array_alias!(Uint16Array, HeapUint16Array, Uint16); array_alias!(Int16Array, HeapInt16Array, Int16); array_alias!(Uint32Array, HeapUint32Array, Uint32); array_alias!(Int32Array, HeapInt32Array, Int32); +array_alias!(BigUint64Array, HeapBigUint64Array, BigUint64); +array_alias!(BigInt64Array, HeapBigInt64Array, BigInt64); array_alias!(Float32Array, HeapFloat32Array, Float32); array_alias!(Float64Array, HeapFloat64Array, Float64); array_alias!(ArrayBuffer, HeapArrayBuffer, ArrayBufferU8); diff --git a/mozjs/tests/typedarray.rs b/mozjs/tests/typedarray.rs index f334c547723..5cf94642728 100644 --- a/mozjs/tests/typedarray.rs +++ b/mozjs/tests/typedarray.rs @@ -9,7 +9,7 @@ use mozjs::jsval::UndefinedValue; use mozjs::rooted; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; use mozjs::typedarray; -use mozjs::typedarray::{CreateWith, Uint32Array}; +use mozjs::typedarray::{BigInt64Array, CreateWith, Float32Array, Uint32Array}; #[test] fn typedarray() { @@ -42,7 +42,7 @@ fn typedarray() { assert!(rval.is_object()); typedarray!(in(context) let array: Uint8Array = rval.to_object()); - assert_eq!(array.unwrap().as_slice(), &[0, 2, 4][..]); + assert_eq!(array.unwrap().as_slice(), &[0, 2, 4]); typedarray!(in(context) let array: Uint8Array = rval.to_object()); assert_eq!(array.unwrap().len(), 3); @@ -62,11 +62,11 @@ fn typedarray() { ); typedarray!(in(context) let array: Uint32Array = rval.get()); - assert_eq!(array.unwrap().as_slice(), &[1, 3, 5][..]); + assert_eq!(array.unwrap().as_slice(), &[1, 3, 5]); typedarray!(in(context) let mut array: Uint32Array = rval.get()); array.as_mut().unwrap().update(&[2, 4, 6]); - assert_eq!(array.unwrap().as_slice(), &[2, 4, 6][..]); + assert_eq!(array.unwrap().as_slice(), &[2, 4, 6]); rooted!(in(context) let rval = ptr::null_mut::()); typedarray!(in(context) let array: Uint8Array = rval.get()); @@ -87,5 +87,35 @@ fn typedarray() { typedarray!(in(context) let view: ArrayBufferView = rval.get()); assert_eq!(view.unwrap().is_shared(), false); + + rooted!(in(context) let mut rval = ptr::null_mut::()); + assert!(Float32Array::create( + context, + CreateWith::Slice(&[0.25, 0.5, 1.0, 2.0, 4.0]), + rval.handle_mut() + ) + .is_ok()); + + typedarray!(in(context) let array: Float32Array = rval.get()); + assert_eq!(array.unwrap().as_slice(), &[0.25, 0.5, 1.0, 2.0, 4.0]); + + typedarray!(in(context) let mut array: Float32Array = rval.get()); + array.as_mut().unwrap().update(&[0.5, 1.0, 2.0]); + assert_eq!(array.unwrap().as_slice(), &[0.5, 1.0, 2.0, 2.0, 4.0]); + + rooted!(in(context) let mut rval = ptr::null_mut::()); + assert!(BigInt64Array::create( + context, + CreateWith::Slice(&[-6, -1, 0, 2, 5]), + rval.handle_mut() + ) + .is_ok()); + + typedarray!(in(context) let array: BigInt64Array = rval.get()); + assert_eq!(array.unwrap().as_slice(), &[-6, -1, 0, 2, 5]); + + typedarray!(in(context) let mut array: BigInt64Array = rval.get()); + array.as_mut().unwrap().update(&[-12, -2, -1]); + assert_eq!(array.unwrap().as_slice(), &[-12, -2, -1, 2, 5]); } }