From d38ccfc6dcb8643daa4f9e695d47a79cf068f90e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 27 Sep 2018 17:33:10 -0400 Subject: Support zero-copy data in libdeno.send(). (#838) This is a large API refactor of deno.h which replaces deno_send() and deno_set_response() with deno_respond(). It also adds a req_id parameter to the deno_recv_cb. Make writeFile/writeFileSync use it. --- libdeno/libdeno_test.js | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'libdeno/libdeno_test.js') diff --git a/libdeno/libdeno_test.js b/libdeno/libdeno_test.js index e0d1d7252..1b5137f0a 100644 --- a/libdeno/libdeno_test.js +++ b/libdeno/libdeno_test.js @@ -25,18 +25,6 @@ global.TypedArraySnapshots = () => { assert(snapshotted[3] === 7); }; -global.SendSuccess = () => { - libdeno.recv(msg => { - libdeno.print("SendSuccess: ok"); - }); -}; - -global.SendWrongByteLength = () => { - libdeno.recv(msg => { - assert(msg.byteLength === 3); - }); -}; - global.RecvReturnEmpty = () => { const m1 = new Uint8Array("abc".split("").map(c => c.charCodeAt(0))); const m2 = m1.slice(); @@ -128,13 +116,20 @@ global.DoubleGlobalErrorHandlingFails = () => { libdeno.setGlobalErrorHandler((message, source, line, col, error) => {}); }; -global.SendNullAllocPtr = () => { - libdeno.recv(msg => { - assert(msg instanceof Uint8Array); - assert(msg.byteLength === 4); - assert(msg[0] === "a".charCodeAt(0)); - assert(msg[1] === "b".charCodeAt(0)); - assert(msg[2] === "c".charCodeAt(0)); - assert(msg[3] === "d".charCodeAt(0)); - }); +// Allocate this buf at the top level to avoid GC. +const dataBuf = new Uint8Array([3, 4]); + +global.DataBuf = () => { + const a = new Uint8Array([1, 2]); + const b = dataBuf; + // The second parameter of send should modified by the + // privileged side. + const r = libdeno.send(a, b); + assert(r == null); + // b is different. + assert(b[0] === 4); + assert(b[1] === 2); + // Now we modify it again. + b[0] = 9; + b[1] = 8; }; -- cgit v1.2.3