diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 908062d3..c637eb41 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -361,6 +361,16 @@ extern "C" { #[wasm_bindgen(constructor)] pub fn new(length: u32) -> ArrayBuffer; + /// The byteLength property of an object which is an instance of type ArrayBuffer + /// it's an accessor property whose set accessor function is undefined, + /// meaning that you can only read this property. + /// The value is established when the array is constructed and cannot be changed. + /// This property returns 0 if this ArrayBuffer has been detached. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength + #[wasm_bindgen(method, getter, js_name = byteLength)] + pub fn byte_length(this: &ArrayBuffer) -> u32; + /// The `isView()` method returns true if arg is one of the `ArrayBuffer` /// views, such as typed array objects or a DataView; false otherwise. /// diff --git a/crates/js-sys/tests/wasm/ArrayBuffer.rs b/crates/js-sys/tests/wasm/ArrayBuffer.rs index 904221ff..ddfcdeef 100644 --- a/crates/js-sys/tests/wasm/ArrayBuffer.rs +++ b/crates/js-sys/tests/wasm/ArrayBuffer.rs @@ -9,6 +9,12 @@ fn new() { assert!(y.is_object()); } +#[wasm_bindgen_test] +fn byte_length() { + let buf = ArrayBuffer::new(42); + assert_eq!(buf.byte_length(), 42); +} + #[wasm_bindgen_test] fn is_view() { let x = Uint8Array::new(&JsValue::from(42));