Add ArrayBuffer.prototype.byteLength to js-sys

This commit is contained in:
Camille TJHOA 2018-08-06 15:27:47 +00:00 committed by Alex Crichton
parent 0bdb31d41e
commit aeca24c7ab
2 changed files with 16 additions and 0 deletions

View File

@ -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.
///

View File

@ -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));