aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lbaselib.js2
-rw-r--r--src/ldo.js4
-rw-r--r--src/lfunc.js17
-rw-r--r--src/lstate.js1
-rw-r--r--src/lundump.js4
-rw-r--r--src/lvm.js1
6 files changed, 16 insertions, 13 deletions
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 5e3fff6..d1d930a 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -297,7 +297,7 @@ const luaB_load = function(L) {
let status;
if (s !== null) { /* loading a string? */
let chunkname = lauxlib.luaL_optstring(L, 2, s);
- status = lauxlib.luaL_loadbufferx(L, s, chunkname, mode);
+ status = lauxlib.luaL_loadbufferx(L, s, s.length, chunkname, mode);
} else { /* loading from a reader function */
let chunkname = lauxlib.luaL_optstring(L, 2, lua.to_luastring("=(load)", true));
lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
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/lfunc.js b/src/lfunc.js
index cf2cfe0..7b2c557 100644
--- a/src/lfunc.js
+++ b/src/lfunc.js
@@ -8,7 +8,7 @@ const CT = defs.constant_types;
class Proto {
- constructor(L) {
+ constructor() {
this.k = []; // constants used by the function
this.p = []; // functions defined inside the function
this.code = []; // opcodes
@@ -54,10 +54,10 @@ const luaF_newLclosure = function(L, n) {
const findupval = function(L, level) {
let pp = L.openupval;
-
- while(pp !== null && pp.v >= level) {
- let p = pp;
-
+ let p = pp;
+ while (pp !== null && pp.v >= level) {
+ p = pp;
+ assert(p.isopen());
if (p.v === level)
return p;
@@ -66,11 +66,14 @@ const findupval = function(L, level) {
let uv = new UpVal();
- uv.open_next = pp;
+ if (p) { /* The openupval list is not empty */
+ uv.open_next = p; /* link it to list of open upvalues */
+ }
+
L.openupval = uv;
uv.L = L;
- uv.v = level;
+ uv.v = level; /* current value lives in the stack */
return uv;
};
diff --git a/src/lstate.js b/src/lstate.js
index 4fd2951..fee308c 100644
--- a/src/lstate.js
+++ b/src/lstate.js
@@ -168,7 +168,6 @@ const lua_newstate = function() {
};
const close_state = function(L) {
- let g = L.l_G;
lfunc.luaF_close(L, L.stack); /* close all upvalues for this thread */
};
diff --git a/src/lundump.js b/src/lundump.js
index 541adbb..1c0d4c7 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;
diff --git a/src/lvm.js b/src/lvm.js
index 41b17c8..9145b88 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -516,7 +516,6 @@ const luaV_execute = function(L) {
let oci = nci.previous;
let nfunc = nci.func;
let nfuncOff = nci.funcOff;
- let ofunc = oci.func;
let ofuncOff = oci.funcOff;
let lim = nci.l_base + nfunc.value.p.numparams;
if (cl.p.p.length > 0) lfunc.luaF_close(L, oci.l_base);