From af95e27d1b2d5f0f39534523778003dfd1fcf417 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 13 Dec 2017 17:17:43 +1100 Subject: src/lzio.js: Don't permit DataView returned from a lua_load reader any more --- src/lzio.js | 15 ++++----------- tests/lstrlib.js | 4 ++-- tests/tests.js | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/lzio.js b/src/lzio.js index efd7909..a00a24b 100644 --- a/src/lzio.js +++ b/src/lzio.js @@ -48,22 +48,15 @@ class ZIO { const EOZ = -1; const luaZ_fill = function(z) { - let size; let buff = z.reader(z.L, z.data); if (buff === null) return EOZ; - if (buff instanceof DataView) { - z.buffer = new Uint8Array(buff.buffer, buff.byteOffset, buff.byteLength); - z.off = 0; - size = buff.byteLength - buff.byteOffset; - } else { - assert(buff instanceof Uint8Array, "Should only load binary of array of bytes"); - z.buffer = buff; - z.off = 0; - size = buff.length; - } + assert(buff instanceof Uint8Array, "Should only load binary of array of bytes"); + let size = buff.length; if (size === 0) return EOZ; + z.buffer = buff; + z.off = 0; z.n = size - 1; return z.buffer[z.off++]; }; diff --git a/tests/lstrlib.js b/tests/lstrlib.js index a55fca1..bdf68d8 100644 --- a/tests/lstrlib.js +++ b/tests/lstrlib.js @@ -442,9 +442,9 @@ test('string.dump', function (t) { lua.lua_call(L, 0, -1); - let dv = lua.lua_todataview(L, -1); + let str = lua.lua_tostring(L, -1); - lua.lua_load(L, function(L, s) { let r = s.dv; s.dv = null; return r; }, {dv: dv}, lua.to_luastring("test"), lua.to_luastring("binary")); + lua.lua_load(L, function(L, s) { let r = s.str; s.str = null; return r; }, {str: str}, lua.to_luastring("test"), lua.to_luastring("binary")); lua.lua_call(L, 0, -1); diff --git a/tests/tests.js b/tests/tests.js index 1bc4fc6..1ad9900 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -11,7 +11,7 @@ const toByteCode = function(luaCode) { return 0; }, b, false) !== 0) throw Error("unable to dump given function"); - return new DataView(Uint8Array.from(b).buffer); + return Uint8Array.from(b); }; const getState = function(luaCode) { -- cgit v1.2.3-70-g09d2