0
0
Fork 0
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:
Bert Belder 2019-11-18 15:02:54 -08:00
parent 37a656014b
commit 7df96332ad
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
4 changed files with 51 additions and 0 deletions

View file

@ -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
View 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
View 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();
}
}

View file

@ -9,6 +9,7 @@
extern crate lazy_static;
extern crate libc;
pub mod array_buffer;
pub mod inspector;
pub mod isolate;
pub mod locker;