mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-28 16:21:04 -05:00
ArrayBuffer: add binding for IsResizableByUserJavaScript
(#1205)
This commit is contained in:
parent
49c77327a6
commit
cb8bcb4f1b
3 changed files with 37 additions and 0 deletions
|
@ -64,6 +64,9 @@ extern "C" {
|
|||
fn v8__BackingStore__Data(this: *const BackingStore) -> *mut c_void;
|
||||
fn v8__BackingStore__ByteLength(this: *const BackingStore) -> usize;
|
||||
fn v8__BackingStore__IsShared(this: *const BackingStore) -> bool;
|
||||
fn v8__BackingStore__IsResizableByUserJavaScript(
|
||||
this: *const BackingStore,
|
||||
) -> bool;
|
||||
fn v8__BackingStore__DELETE(this: *mut BackingStore);
|
||||
|
||||
fn std__shared_ptr__v8__BackingStore__COPY(
|
||||
|
@ -304,6 +307,14 @@ impl BackingStore {
|
|||
pub fn is_shared(&self) -> bool {
|
||||
unsafe { v8__BackingStore__IsShared(self) }
|
||||
}
|
||||
|
||||
/// Indicates whether the backing store was created for a resizable ArrayBuffer
|
||||
/// or a growable SharedArrayBuffer, and thus may be resized by user
|
||||
/// JavaScript code.
|
||||
#[inline(always)]
|
||||
pub fn is_resizable_by_user_javascript(&self) -> bool {
|
||||
unsafe { v8__BackingStore__IsResizableByUserJavaScript(self) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for BackingStore {
|
||||
|
|
|
@ -846,6 +846,10 @@ two_pointers_t v8__ArrayBuffer__GetBackingStore(const v8::ArrayBuffer& self) {
|
|||
return make_pod<two_pointers_t>(ptr_to_local(&self)->GetBackingStore());
|
||||
}
|
||||
|
||||
bool v8__BackingStore__IsResizableByUserJavaScript(const v8::BackingStore& self) {
|
||||
return ptr_to_local(&self)->IsResizableByUserJavaScript();
|
||||
}
|
||||
|
||||
void* v8__ArrayBuffer__Data(const v8::ArrayBuffer& self) {
|
||||
return ptr_to_local(&self)->Data();
|
||||
}
|
||||
|
|
|
@ -7701,6 +7701,28 @@ fn backing_store_data() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backing_store_resizable() {
|
||||
let _setup_guard = setup::parallel_test();
|
||||
|
||||
let v = vec![1, 2, 3, 4, 5];
|
||||
let store_fixed =
|
||||
v8::ArrayBuffer::new_backing_store_from_vec(v).make_shared();
|
||||
assert!(!store_fixed.is_resizable_by_user_javascript());
|
||||
|
||||
let mut isolate = v8::Isolate::new(Default::default());
|
||||
let mut scope = v8::HandleScope::new(&mut isolate);
|
||||
let context = v8::Context::new(&mut scope);
|
||||
let mut scope = v8::ContextScope::new(&mut scope, context);
|
||||
|
||||
let ab_val =
|
||||
eval(&mut scope, "new ArrayBuffer(100, {maxByteLength: 200})").unwrap();
|
||||
assert!(ab_val.is_array_buffer());
|
||||
let ab = v8::Local::<v8::ArrayBuffer>::try_from(ab_val).unwrap();
|
||||
let store_resizable = ab.get_backing_store();
|
||||
assert!(store_resizable.is_resizable_by_user_javascript());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn current_stack_trace() {
|
||||
// Setup isolate
|
||||
|
|
Loading…
Reference in a new issue