summaryrefslogtreecommitdiff
path: root/libdeno/binding.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-09-19 08:24:34 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-09-24 22:16:23 -0400
commit234d5ea780d8621866da87097c78ec10167cbdc5 (patch)
treed9617f8ad9743c9193751c4490cfa3bc5cf2184f /libdeno/binding.cc
parentf42849744bbdd665008fdd7fd9a395659a23c802 (diff)
libdeno.send(): Use GetContents instead of Externalize
Fixes #744.
Diffstat (limited to 'libdeno/binding.cc')
-rw-r--r--libdeno/binding.cc22
1 files changed, 4 insertions, 18 deletions
diff --git a/libdeno/binding.cc b/libdeno/binding.cc
index 6d88af360..bc155b6db 100644
--- a/libdeno/binding.cc
+++ b/libdeno/binding.cc
@@ -168,25 +168,18 @@ static v8::Local<v8::Uint8Array> ImportBuf(v8::Isolate* isolate, deno_buf buf) {
}
}
-static deno_buf ExportBuf(v8::Isolate* isolate,
- v8::Local<v8::ArrayBufferView> view) {
+static deno_buf GetContents(v8::Isolate* isolate,
+ v8::Local<v8::ArrayBufferView> view) {
auto ab = view->Buffer();
- auto contents = ab->Externalize();
-
+ auto contents = ab->GetContents();
deno_buf buf;
buf.alloc_ptr = reinterpret_cast<uint8_t*>(contents.Data());
buf.alloc_len = contents.ByteLength();
buf.data_ptr = buf.alloc_ptr + view->ByteOffset();
buf.data_len = view->ByteLength();
-
- // Prevent JS from modifying buffer contents after exporting.
- ab->Neuter();
-
return buf;
}
-static void FreeBuf(deno_buf buf) { free(buf.alloc_ptr); }
-
// Sets the recv callback.
void Recv(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
@@ -218,20 +211,13 @@ void Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(args.Length(), 1);
v8::Local<v8::Value> ab_v = args[0];
CHECK(ab_v->IsArrayBufferView());
- auto buf = ExportBuf(isolate, v8::Local<v8::ArrayBufferView>::Cast(ab_v));
+ auto buf = GetContents(isolate, v8::Local<v8::ArrayBufferView>::Cast(ab_v));
DCHECK_EQ(d->currentArgs, nullptr);
d->currentArgs = &args;
d->cb(d, buf);
- // Buffer is only valid until the end of the callback.
- // TODO(piscisaureus):
- // It's possible that data in the buffer is needed after the callback
- // returns, e.g. when the handler offloads work to a thread pool, therefore
- // make the callback responsible for releasing the buffer.
- FreeBuf(buf);
-
d->currentArgs = nullptr;
}