aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-29 15:42:49 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-29 15:51:01 +1000
commita5e267bf7df32e3ff6add67b7985c587fe8e3fb1 (patch)
tree5b7bacee053260221081b9c342edebae4f255ff5
parent6d1484d41f5b5d561d21d6e497bd1ec437973464 (diff)
downloadfengari-a5e267bf7df32e3ff6add67b7985c587fe8e3fb1.tar.gz
fengari-a5e267bf7df32e3ff6add67b7985c587fe8e3fb1.tar.bz2
fengari-a5e267bf7df32e3ff6add67b7985c587fe8e3fb1.zip
src/lapi.js: Clean up upvaluejoin
- Remember to decrement in upvaluejoin - Last arg to getupvalref was an out arg
-rw-r--r--src/lapi.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lapi.js b/src/lapi.js
index b08f342..f326198 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -1070,7 +1070,7 @@ const lua_len = function(L, idx) {
assert(L.top <= L.ci.top, "stack overflow");
};
-const getupvalref = function(L, fidx, n, pf) {
+const getupvalref = function(L, fidx, n) {
let fi = index2addr(L, fidx);
assert(fi.ttisLclosure(), "Lua function expected");
let f = fi.value;
@@ -1086,7 +1086,7 @@ const lua_upvalueid = function(L, fidx, n) {
let fi = index2addr(L, fidx);
switch (fi.ttype()) {
case CT.LUA_TLCL: { /* lua closure */
- return getupvalref(L, fidx, n, null).upval;
+ return getupvalref(L, fidx, n).upval;
}
case CT.LUA_TCCL: { /* C closure */
let f = fi.value;
@@ -1103,10 +1103,12 @@ const lua_upvalueid = function(L, fidx, n) {
const lua_upvaluejoin = function(L, fidx1, n1, fidx2, n2) {
let ref1 = getupvalref(L, fidx1, n1);
let ref2 = getupvalref(L, fidx2, n2);
- let up1 = ref1.upvalOff;
+ let up1 = ref1.upval;
let up2 = ref2.upval;
let f1 = ref1.closure;
- f1.upvals[up1] = up2;
+ assert(up1.refcount > 0);
+ up1.refcount--;
+ f1.upvals[ref1.upvalOff] = up2;
up2.refcount++;
};