diff options
-rw-r--r-- | src/lfunc.js | 17 | ||||
-rw-r--r-- | tests/test-suite/calls.js | 10 |
2 files changed, 20 insertions, 7 deletions
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/tests/test-suite/calls.js b/tests/test-suite/calls.js index 2c1dc7a..08e72cc 100644 --- a/tests/test-suite/calls.js +++ b/tests/test-suite/calls.js @@ -389,6 +389,16 @@ test("[test-suite] calls: test for generic load", function (t) { end a = assert(load(read1(x), "modname", "t", _G)) + assert(a() == "\0" and _G.x == 33) + assert(debug.getinfo(a).source == "modname") + -- cannot read text in binary mode + -- cannotload("attempt to load a text chunk", load(read1(x), "modname", "b", {})) + -- cannotload("attempt to load a text chunk", load(x, "modname", "b")) + + a = assert(load(function () return nil end)) + a() -- empty chunk + + assert(not load(function () return true end)) `, L; t.plan(1); |