mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-22 04:40:01 +00:00
feat: add get_backing_store to ArrayBufferView (#1342)
This commit is contained in:
parent
efca1408f6
commit
da5ca4f2d1
@ -4,8 +4,10 @@ use std::ffi::c_void;
|
||||
use crate::support::int;
|
||||
use crate::ArrayBuffer;
|
||||
use crate::ArrayBufferView;
|
||||
use crate::BackingStore;
|
||||
use crate::HandleScope;
|
||||
use crate::Local;
|
||||
use crate::SharedRef;
|
||||
|
||||
extern "C" {
|
||||
fn v8__ArrayBufferView__Buffer(
|
||||
@ -33,6 +35,16 @@ impl ArrayBufferView {
|
||||
unsafe { scope.cast_local(|_| v8__ArrayBufferView__Buffer(self)) }
|
||||
}
|
||||
|
||||
/// Get a shared pointer to the backing store of this array buffer. This
|
||||
/// pointer coordinates the lifetime management of the internal storage
|
||||
/// with any live ArrayBuffers on the heap, even across isolates. The embedder
|
||||
/// should not attempt to manage lifetime of the storage through other means.
|
||||
#[inline(always)]
|
||||
pub fn get_backing_store(&self) -> Option<SharedRef<BackingStore>> {
|
||||
let buffer = unsafe { v8__ArrayBufferView__Buffer(self) };
|
||||
unsafe { buffer.as_ref().map(|buffer| buffer.get_backing_store()) }
|
||||
}
|
||||
|
||||
/// Returns the underlying storage for this `ArrayBufferView`, including the built-in `byte_offset`.
|
||||
/// This is a more efficient way of calling `buffer(scope)->data()`, and may be called without a
|
||||
/// scope.
|
||||
|
@ -5094,6 +5094,10 @@ fn array_buffer_view() {
|
||||
assert!(maybe_ab.is_some());
|
||||
let ab = maybe_ab.unwrap();
|
||||
assert_eq!(ab.byte_length(), 6);
|
||||
assert_eq!(
|
||||
result.get_backing_store().unwrap().data(),
|
||||
ab.get_backing_store().data()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user