diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-11 23:07:52 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-11 23:07:52 +1000 |
commit | 68fe72a336c7e732164e2eacfdc8c86a25939957 (patch) | |
tree | 2312dd7375063d30966f5cb721d1db93999c8954 /src/ltable.js | |
parent | 992c58899b32c919d3c5c1c60c14c7c073c5d54c (diff) | |
download | fengari-68fe72a336c7e732164e2eacfdc8c86a25939957.tar.gz fengari-68fe72a336c7e732164e2eacfdc8c86a25939957.tar.bz2 fengari-68fe72a336c7e732164e2eacfdc8c86a25939957.zip |
src/ltable.js: Iterate past dead keys
Diffstat (limited to 'src/ltable.js')
-rw-r--r-- | src/ltable.js | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/ltable.js b/src/ltable.js index 0619efe..5eae939 100644 --- a/src/ltable.js +++ b/src/ltable.js @@ -150,9 +150,10 @@ const luaH_getn = function(t) { const luaH_next = function(L, table, keyI) { let keyO = L.stack[keyI]; - let iterresult; + let iterator; + /* Iterate until we find the current key */ if (keyO.type === CT.LUA_TNIL) { - iterresult = table.strong.keys().next(); + iterator = table.strong.keys(); } else { let hash = table_hash(keyO); @@ -160,18 +161,21 @@ const luaH_next = function(L, table, keyI) { /* item not in table */ return ldebug.luaG_runerror(L, defs.to_luastring("invalid key to 'next'")) - let indexes = table.strong.keys(); - while (1) { - let e = indexes.next(); + iterator = table.strong.keys(); + do { + let e = iterator.next(); if (e.done) throw "unreachable"; - else if (e.value == hash) - break; - } - iterresult = indexes.next(); + } while(e.value !== hash); } - if (iterresult.done) - return false; + /* Now iterator is positioned at current key. + * Iterate until either out of keys, or until finding a non-dead key */ + let iterresult + do { + iterresult = indexes.next(); + if (iterresult.done) + return false; + } while(iterresult.value.ttisdeadkey()); let entry = table.strong.get(iterresult.value); L.stack[keyI] = new lobject.TValue(entry.key.type, entry.key.value); |