Skip to content

Commit

Permalink
Add WasmMemoryObject::buffer method (denoland#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Nov 23, 2022
1 parent dd5fa70 commit 3a05ab4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,11 @@ void v8__WasmStreaming__SetUrl(WasmStreamingSharedPtr* self, const char* url,
self->inner->SetUrl(url, len);
}

const v8::ArrayBuffer* v8__WasmMemoryObject__Buffer(
const v8::WasmMemoryObject& self) {
return local_to_ptr(ptr_to_local(&self)->Buffer());
}

using HeapSnapshotCallback = bool (*)(void*, const char*, size_t);

void v8__HeapProfiler__TakeHeapSnapshot(v8::Isolate* isolate,
Expand Down
14 changes: 14 additions & 0 deletions src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use crate::scope::HandleScope;
use crate::support::char;
use crate::support::Opaque;
use crate::support::UnitType;
use crate::ArrayBuffer;
use crate::Isolate;
use crate::Local;
use crate::Value;
use crate::WasmMemoryObject;
use crate::WasmModuleObject;
use std::ptr::null;
use std::ptr::null_mut;
Expand Down Expand Up @@ -173,6 +175,14 @@ impl Drop for CompiledWasmModule {
}
}

impl WasmMemoryObject {
/// Returns underlying ArrayBuffer.
#[inline(always)]
pub fn buffer(&self) -> Local<ArrayBuffer> {
unsafe { Local::from_raw(v8__WasmMemoryObject__Buffer(self)) }.unwrap()
}
}

pub(crate) fn trampoline<F>() -> extern "C" fn(*const FunctionCallbackInfo)
where
F: UnitType + Fn(&mut HandleScope, Local<Value>, WasmStreaming),
Expand Down Expand Up @@ -241,4 +251,8 @@ extern "C" {
length: *mut usize,
) -> *const char;
fn v8__CompiledWasmModule__DELETE(this: *mut InternalCompiledWasmModule);

fn v8__WasmMemoryObject__Buffer(
this: *const WasmMemoryObject,
) -> *mut ArrayBuffer;
}

0 comments on commit 3a05ab4

Please sign in to comment.