mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -05:00
feat: add DataView constructor (#1491)
This commit is contained in:
parent
756f47dcb9
commit
2a8b117c93
3 changed files with 47 additions and 0 deletions
|
@ -16,6 +16,7 @@ use crate::support::SharedRef;
|
|||
use crate::support::UniquePtr;
|
||||
use crate::support::UniqueRef;
|
||||
use crate::ArrayBuffer;
|
||||
use crate::DataView;
|
||||
use crate::HandleScope;
|
||||
use crate::Isolate;
|
||||
use crate::Local;
|
||||
|
@ -68,6 +69,12 @@ extern "C" {
|
|||
) -> bool;
|
||||
fn v8__BackingStore__DELETE(this: *mut BackingStore);
|
||||
|
||||
fn v8__DataView__New(
|
||||
arraybuffer: *const ArrayBuffer,
|
||||
byte_offset: usize,
|
||||
length: usize,
|
||||
) -> *const DataView;
|
||||
|
||||
fn std__shared_ptr__v8__BackingStore__COPY(
|
||||
ptr: *const SharedPtrBase<BackingStore>,
|
||||
) -> SharedPtrBase<BackingStore>;
|
||||
|
@ -616,3 +623,20 @@ impl ArrayBuffer {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl DataView {
|
||||
/// Returns a new DataView.
|
||||
#[inline(always)]
|
||||
pub fn new<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
arraybuffer: Local<'s, ArrayBuffer>,
|
||||
byte_offset: usize,
|
||||
length: usize,
|
||||
) -> Local<'s, DataView> {
|
||||
unsafe {
|
||||
scope
|
||||
.cast_local(|_| v8__DataView__New(&*arraybuffer, byte_offset, length))
|
||||
}
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1802,6 +1802,13 @@ size_t v8__ArrayBuffer__ByteLength(const v8::ArrayBuffer& self) {
|
|||
return self.ByteLength();
|
||||
}
|
||||
|
||||
const v8::DataView* v8__DataView__New(
|
||||
const v8::ArrayBuffer& ab,
|
||||
size_t offset,
|
||||
size_t length) {
|
||||
return local_to_ptr(v8::DataView::New(ptr_to_local(&ab), offset, length));
|
||||
}
|
||||
|
||||
struct InternalFieldData {
|
||||
uint32_t data;
|
||||
};
|
||||
|
|
|
@ -734,6 +734,22 @@ fn handles_from_isolate() {
|
|||
let _ = v8::Boolean::new(isolate, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_view() {
|
||||
let _setup_guard = setup::parallel_test();
|
||||
let isolate = &mut v8::Isolate::new(Default::default());
|
||||
{
|
||||
let scope = &mut v8::HandleScope::new(isolate);
|
||||
let context = v8::Context::new(scope);
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
|
||||
let ab = v8::ArrayBuffer::new(scope, 42);
|
||||
|
||||
let dv = v8::DataView::new(scope, ab, 0, 42);
|
||||
assert!(dv.is_data_view());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_buffer() {
|
||||
let _setup_guard = setup::parallel_test();
|
||||
|
|
Loading…
Reference in a new issue