mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-11 16:42:32 -05:00
Add binding for ArrayBuffer::Allocator::NewDefaultAllocator (#13)
This commit is contained in:
parent
37a656014b
commit
7df96332ad
4 changed files with 51 additions and 0 deletions
1
BUILD.gn
1
BUILD.gn
|
@ -3,6 +3,7 @@ import("//third_party/v8/gni/v8.gni")
|
|||
|
||||
v8_static_library("rusty_v8") {
|
||||
sources = [
|
||||
"src/array_buffer.cc",
|
||||
"src/inspector/channel.cc",
|
||||
"src/inspector/client.cc",
|
||||
"src/isolate.cc",
|
||||
|
|
13
src/array_buffer.cc
Normal file
13
src/array_buffer.cc
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "v8.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" {
|
||||
ArrayBuffer::Allocator* v8__ArrayBuffer__Allocator__NewDefaultAllocator() {
|
||||
return ArrayBuffer::Allocator::NewDefaultAllocator();
|
||||
}
|
||||
|
||||
void v8__ArrayBuffer__Allocator__DELETE(ArrayBuffer::Allocator& self) {
|
||||
delete &self;
|
||||
}
|
||||
} // extern "C"
|
36
src/array_buffer.rs
Normal file
36
src/array_buffer.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use crate::support::Delete;
|
||||
use crate::support::Opaque;
|
||||
use crate::support::UniquePtr;
|
||||
|
||||
extern "C" {
|
||||
fn v8__ArrayBuffer__Allocator__NewDefaultAllocator() -> *mut Allocator;
|
||||
fn v8__ArrayBuffer__Allocator__DELETE(this: &'static mut Allocator);
|
||||
}
|
||||
|
||||
// TODO: allow the user to implement their own Allocator.
|
||||
#[repr(C)]
|
||||
pub struct Allocator(Opaque);
|
||||
|
||||
impl Allocator {
|
||||
pub fn new_default_allocator() -> UniquePtr<Allocator> {
|
||||
unsafe {
|
||||
UniquePtr::from_raw(v8__ArrayBuffer__Allocator__NewDefaultAllocator())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Delete for Allocator {
|
||||
fn delete(&'static mut self) {
|
||||
unsafe { v8__ArrayBuffer__Allocator__DELETE(self) };
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_default_allocator() {
|
||||
Allocator::new_default_allocator();
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
extern crate lazy_static;
|
||||
extern crate libc;
|
||||
|
||||
pub mod array_buffer;
|
||||
pub mod inspector;
|
||||
pub mod isolate;
|
||||
pub mod locker;
|
||||
|
|
Loading…
Reference in a new issue