From 7ef345bee73f6cc843b0d82866d036a3ac5829ca Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 5 May 2017 15:24:00 +0200 Subject: Binary chunk can be a lua string (string.dump) --- src/ldo.js | 4 +++- src/lundump.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ldo.js b/src/ldo.js index 9ef8b66..13bd15c 100644 --- a/src/ldo.js +++ b/src/ldo.js @@ -574,7 +574,9 @@ const f_parser = function(L, p) { let c = p.z.getc(); /* read first character */ if (c === defs.LUA_SIGNATURE.charCodeAt(0)) { checkmode(L, p.mode, defs.to_luastring("binary", true)); - cl = new BytecodeParser(L, p.z.buffer, p.name).luaU_undump(); + let buff = p.z.buffer; + if (Array.isArray(buff)) buff = new DataView(new Uint8Array(p.z.buffer).buffer); /* Lua string holding binary (string.dump) */ + cl = new BytecodeParser(L, buff, p.name).luaU_undump(); } else { checkmode(L, p.mode, defs.to_luastring("text", true)); cl = lparser.luaY_parser(L, p.z, p.buff, p.dyd, p.name, c); diff --git a/src/lundump.js b/src/lundump.js index 5d158bd..26405d6 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -8,11 +8,11 @@ const lfunc = require('./lfunc.js'); const lobject = require('./lobject.js'); const lopcodes = require('./lopcodes.js'); -const LUAI_MAXSHORTLEN = 40; - class BytecodeParser { constructor(L, dataView, name) { + assert(dataView instanceof DataView, "BytecodeParser only operates on a dataView") + this.L = L; this.intSize = 4; this.size_tSize = 8; -- cgit v1.2.3-70-g09d2