diff --git a/src/binding.cc b/src/binding.cc index ca8aee43..94899756 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -993,6 +993,14 @@ v8::SharedArrayBuffer* v8__SharedArrayBuffer__New(v8::Isolate* isolate, return local_to_ptr(v8::SharedArrayBuffer::New(isolate, byte_length)); } +v8::SharedArrayBuffer* v8__SharedArrayBuffer__New__DEPRECATED( + v8::Isolate* isolate, void* data_ptr, size_t data_length) { + auto ab = + v8::SharedArrayBuffer::New(isolate, data_ptr, data_length, + v8::ArrayBufferCreationMode::kExternalized); + return local_to_ptr(ab); +} + size_t v8__SharedArrayBuffer__ByteLength(v8::SharedArrayBuffer& self) { return self.ByteLength(); } diff --git a/src/shared_array_buffer.rs b/src/shared_array_buffer.rs index 0ca6a1f5..a8ae6b12 100644 --- a/src/shared_array_buffer.rs +++ b/src/shared_array_buffer.rs @@ -10,6 +10,11 @@ extern "C" { isolate: *mut Isolate, byte_length: usize, ) -> *mut SharedArrayBuffer; + fn v8__SharedArrayBuffer__New__DEPRECATED( + isolate: *mut Isolate, + data_ptr: *mut std::ffi::c_void, + data_length: usize, + ) -> *mut SharedArrayBuffer; fn v8__SharedArrayBuffer__ByteLength( self_: *const SharedArrayBuffer, ) -> usize; @@ -32,6 +37,29 @@ impl SharedArrayBuffer { } } + /// DEPRECATED + /// Use the version that takes a BackingStore. + /// See http://crbug.com/v8/9908. + /// + /// + /// Create a new SharedArrayBuffer over an existing memory block. The created + /// array buffer is immediately in externalized state unless otherwise + /// specified. The memory block will not be reclaimed when a created + /// SharedArrayBuffer is garbage-collected. + #[allow(non_snake_case)] + pub unsafe fn new_DEPRECATED<'sc>( + scope: &mut impl ToLocal<'sc>, + data_ptr: *mut std::ffi::c_void, + data_length: usize, + ) -> Local<'sc, SharedArrayBuffer> { + Local::from_raw(v8__SharedArrayBuffer__New__DEPRECATED( + scope.isolate(), + data_ptr, + data_length, + )) + .unwrap() + } + /// Data length in bytes. pub fn byte_length(&self) -> usize { unsafe { v8__SharedArrayBuffer__ByteLength(self) }