diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-09-27 17:33:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-27 17:33:10 -0400 |
commit | d38ccfc6dcb8643daa4f9e695d47a79cf068f90e (patch) | |
tree | d36ad2934e8550242d50e866f4ad2b6c303646b7 /libdeno/libdeno_test.js | |
parent | bf93ca54dd85686c7b93a6189913e48e10de8dcf (diff) |
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.
Diffstat (limited to 'libdeno/libdeno_test.js')
-rw-r--r-- | libdeno/libdeno_test.js | 37 |
1 files changed, 16 insertions, 21 deletions
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; }; |