summaryrefslogtreecommitdiff
path: root/src/binding.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-07-23 14:11:41 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-07-24 12:29:54 -0400
commitb79ce93010d0cc80a9345f646e562326de4588e5 (patch)
tree3117c6b795b593bd369880ea36be18533c766a73 /src/binding.cc
parentb87e6d560477354e8c1b3c69e9836cd92eaf9984 (diff)
Allow deno_buf with null alloc_ptr to be memcpy'd
This is a temporary hack to allow for easier restructuring of the serialization code as we move Flatbuffer stuff from C++ to Rust.
Diffstat (limited to 'src/binding.cc')
-rw-r--r--src/binding.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/binding.cc b/src/binding.cc
index 60325df1e..7b5da2d7f 100644
--- a/src/binding.cc
+++ b/src/binding.cc
@@ -120,12 +120,21 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
static v8::Local<v8::Uint8Array> ImportBuf(v8::Isolate* isolate, deno_buf buf) {
- auto ab = v8::ArrayBuffer::New(
- isolate, reinterpret_cast<void*>(buf.alloc_ptr), buf.alloc_len,
- v8::ArrayBufferCreationMode::kInternalized);
- auto view =
- v8::Uint8Array::New(ab, buf.data_ptr - buf.alloc_ptr, buf.data_len);
- return view;
+ if (buf.alloc_ptr == nullptr) {
+ // If alloc_ptr isn't set, we memcpy.
+ // This is currently used for flatbuffers created in Rust.
+ auto ab = v8::ArrayBuffer::New(isolate, buf.data_len);
+ memcpy(ab->GetContents().Data(), buf.data_ptr, buf.data_len);
+ auto view = v8::Uint8Array::New(ab, 0, buf.data_len);
+ return view;
+ } else {
+ auto ab = v8::ArrayBuffer::New(
+ isolate, reinterpret_cast<void*>(buf.alloc_ptr), buf.alloc_len,
+ v8::ArrayBufferCreationMode::kInternalized);
+ auto view =
+ v8::Uint8Array::New(ab, buf.data_ptr - buf.alloc_ptr, buf.data_len);
+ return view;
+ }
}
static deno_buf ExportBuf(v8::Isolate* isolate,