diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-06-13 19:38:22 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-06-14 14:19:17 +0200 |
commit | 4ac67cf3435b3e15f95fadc20c98e37abf706ea4 (patch) | |
tree | 651b18c568e6ca8130d3d37de60a6a44e12e855b /deno2/deno.cc | |
parent | f97216609d1705a21ddbe6ca3efb04817f026fc3 (diff) |
Demo protobufs in deno2.
Adds deno_set_response() to allow stack allocated responses.
Diffstat (limited to 'deno2/deno.cc')
-rw-r--r-- | deno2/deno.cc | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/deno2/deno.cc b/deno2/deno.cc index 27dfefb8e..d59f49065 100644 --- a/deno2/deno.cc +++ b/deno2/deno.cc @@ -154,15 +154,12 @@ void Pub(const v8::FunctionCallbackInfo<v8::Value>& args) { const_cast<const char*>(reinterpret_cast<char*>(contents.Data())); deno_buf buf{data, contents.ByteLength()}; - auto retbuf = d->cb(d, channel, buf); - if (retbuf.data) { - // TODO(ry) Support zero-copy. - auto ab = v8::ArrayBuffer::New(d->isolate, retbuf.len); - memcpy(ab->GetContents().Data(), retbuf.data, retbuf.len); - args.GetReturnValue().Set(handle_scope.Escape(ab)); - } else { - args.GetReturnValue().Set(v8::Null(d->isolate)); - } + assert(d->currentArgs == nullptr); + d->currentArgs = &args; + + d->cb(d, channel, buf); + + d->currentArgs = nullptr; } bool Execute(v8::Local<v8::Context> context, const char* js_filename, @@ -334,6 +331,13 @@ bool deno_pub(Deno* d, const char* channel, deno_buf buf) { return true; } +void deno_set_response(Deno* d, deno_buf buf) { + // TODO(ry) Support zero-copy. + auto ab = v8::ArrayBuffer::New(d->isolate, buf.len); + memcpy(ab->GetContents().Data(), buf.data, buf.len); + d->currentArgs->GetReturnValue().Set(ab); +} + void deno_delete(Deno* d) { d->isolate->Dispose(); delete d; |