summaryrefslogtreecommitdiff
path: root/src/lundump.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-24 15:52:27 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-24 15:52:27 +0200
commitfe15ff909f9edbbc485ae66d54d6415bf0843a6d (patch)
tree86842135b2027eb8ce6ef50647982ec42c1fd7c6 /src/lundump.js
parent31dcd12f5a9cd6a45e8ad9d1213a8a25d88fe885 (diff)
downloadfengari-fe15ff909f9edbbc485ae66d54d6415bf0843a6d.tar.gz
fengari-fe15ff909f9edbbc485ae66d54d6415bf0843a6d.tar.bz2
fengari-fe15ff909f9edbbc485ae66d54d6415bf0843a6d.zip
lun/dump.js use 32bit integers
Diffstat (limited to 'src/lundump.js')
-rw-r--r--src/lundump.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/lundump.js b/src/lundump.js
index 36fd674..b229926 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -13,16 +13,17 @@ const LUAI_MAXSHORTLEN = 40;
class BytecodeParser {
- constructor(L, dataView) {
+ constructor(L, dataView, name) {
this.L = L;
this.intSize = 4;
this.size_tSize = 8;
this.instructionSize = 4;
- this.integerSize = 8;
+ this.integerSize = 4;
this.numberSize = 8;
this.dataView = dataView;
this.offset = 0;
+ this.name = name;
}
peekByte() {
@@ -36,7 +37,7 @@ class BytecodeParser {
}
peekInteger() {
- return this.dataView.getInt32(this.offset, true); // TODO: 64b ?
+ return this.dataView.getInt32(this.offset, true);
}
readInteger() {
@@ -251,6 +252,12 @@ class BytecodeParser {
this.integerSize = this.readByte();
this.numberSize = this.readByte();
+ this.checksize(this.intSize, 4, "int");
+ this.checksize(this.size_tSize, 8, "size_t");
+ this.checksize(this.instructionSize, 4, "instruction");
+ this.checksize(this.integerSize, 4, "integer");
+ this.checksize(this.numberSize, 8, "number");
+
if (this.readInteger() !== 0x5678)
throw new Error("endianness mismatch");
@@ -259,6 +266,18 @@ class BytecodeParser {
}
+ error(why) {
+ const lapi = require('./lapi.js');
+ const ldo = require('./ldo.js');
+ lapi.lua_pushstring(this.L, lua.to_luastring(`${this.name}: ${why} precompiled chunk`, true));
+ ldo.luaD_throw(this.L, lua.thread_status.LUA_ERRSYNTAX);
+ }
+
+ checksize(byte, size, tname) {
+ if (byte !== size)
+ this.error(`${tname} size mismatch in`);
+ }
+
luaU_undump() {
this.checkHeader();