aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-16 16:32:32 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-16 16:37:38 +1000
commit4c7732b08043dc63ff195b0bc646cc184cefde41 (patch)
tree23ecc843e084f35832f67a1aba5ad1272b2c92e6 /src
parent4da6637af3dca403995b61e47159605fa272b0a9 (diff)
downloadfengari-4c7732b08043dc63ff195b0bc646cc184cefde41.tar.gz
fengari-4c7732b08043dc63ff195b0bc646cc184cefde41.tar.bz2
fengari-4c7732b08043dc63ff195b0bc646cc184cefde41.zip
src/lfunc.js: Fix luaF_findupval, it needs to insert the upvalue into correct place in linked list, not the start
Diffstat (limited to 'src')
-rw-r--r--src/lfunc.js34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/lfunc.js b/src/lfunc.js
index 7e324da..663f614 100644
--- a/src/lfunc.js
+++ b/src/lfunc.js
@@ -54,28 +54,26 @@ const luaF_newLclosure = function(L, n) {
const luaF_findupval = function(L, level) {
- let pp = L.openupval;
- let p = pp;
- while (pp !== null && pp.v >= level) {
- p = pp;
+ let prevp;
+ let p = L.openupval;
+ while (p !== null && p.v >= level) {
assert(p.isopen());
- if (p.v === level)
- return p;
-
- pp = p.open_next;
+ if (p.v === level) /* found a corresponding upvalue? */
+ return p; /* return it */
+ prevp = p;
+ p = p.open_next;
}
-
+ /* not found: create a new upvalue */
let uv = new UpVal();
-
- if (p) { /* The openupval list is not empty */
- uv.open_next = p; /* link it to list of open upvalues */
- }
-
- L.openupval = uv;
-
+ /* link it to list of open upvalues */
+ uv.open_next = p;
+ if (prevp)
+ prevp.open_next = uv;
+ else
+ L.openupval = uv;
+ /* current value lives in the stack */
uv.L = L;
- uv.v = level; /* current value lives in the stack */
-
+ uv.v = level;
return uv;
};