mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
feat: Add v8::TypedArray::length (#1166)
This commit is contained in:
parent
b7cfc588fd
commit
5f037a1c9c
3 changed files with 22 additions and 0 deletions
|
@ -464,6 +464,9 @@ uint32_t v8__ScriptCompiler__CachedDataVersionTag() {
|
|||
return v8::ScriptCompiler::CachedDataVersionTag();
|
||||
}
|
||||
|
||||
size_t v8__TypedArray__Length(const v8::TypedArray* self) {
|
||||
return ptr_to_local(self)->Length();
|
||||
}
|
||||
size_t v8__TypedArray__kMaxLength() { return v8::TypedArray::kMaxLength; }
|
||||
|
||||
bool v8__Data__EQ(const v8::Data& self, const v8::Data& other) {
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::TypedArray;
|
|||
|
||||
extern "C" {
|
||||
fn v8__TypedArray__kMaxLength() -> size_t;
|
||||
fn v8__TypedArray__Length(this: *const TypedArray) -> size_t;
|
||||
}
|
||||
|
||||
impl TypedArray {
|
||||
|
@ -17,6 +18,13 @@ impl TypedArray {
|
|||
pub fn max_length() -> usize {
|
||||
unsafe { v8__TypedArray__kMaxLength() }
|
||||
}
|
||||
|
||||
/// Number of elements in this typed array
|
||||
/// (e.g. for Int16Array, |ByteLength|/2).
|
||||
#[inline(always)]
|
||||
pub fn length(&self) -> usize {
|
||||
unsafe { v8__TypedArray__Length(self) }
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! typed_array {
|
||||
|
|
|
@ -4268,36 +4268,47 @@ fn typed_array_constructors() {
|
|||
|
||||
let t = v8::Uint8Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_uint8_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Uint8ClampedArray::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_uint8_clamped_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Int8Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_int8_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Uint16Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_uint16_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Int16Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_int16_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Uint32Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_uint32_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Int32Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_int32_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Float32Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_float32_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::Float64Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_float64_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::BigUint64Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_big_uint64_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
let t = v8::BigInt64Array::new(scope, ab, 0, 0).unwrap();
|
||||
assert!(t.is_big_int64_array());
|
||||
assert_eq!(t.length(), 0);
|
||||
|
||||
// TypedArray::max_length() ought to be >= 2^30 < 2^32 in 64 bits
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
|
|
Loading…
Reference in a new issue