summaryrefslogtreecommitdiff
path: root/src/ltable.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-22 17:32:28 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-02-22 21:15:40 +0100
commitfc911817a8401d0696407e91501f0ef65f05b711 (patch)
tree828ee9d2d6d02cfc7d0365ca1495f99b3158c5cd /src/ltable.js
parent4b764aa6a84289f04acde43108425c392d2e4806 (diff)
downloadfengari-fc911817a8401d0696407e91501f0ef65f05b711.tar.gz
fengari-fc911817a8401d0696407e91501f0ef65f05b711.tar.bz2
fengari-fc911817a8401d0696407e91501f0ef65f05b711.zip
use luaL_argerror/error instead of throwing
Diffstat (limited to 'src/ltable.js')
-rw-r--r--src/ltable.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/ltable.js b/src/ltable.js
index 14139af..7611b4c 100644
--- a/src/ltable.js
+++ b/src/ltable.js
@@ -8,6 +8,7 @@ const lua = require('./lua.js');
const CT = lua.constant_types;
const nil = require('./ldo.js').nil;
const Table = lobject.Table;
+const TValue = lobject.TValue;
Table.prototype.ordered_intindexes = function() {
@@ -37,9 +38,9 @@ Table.prototype.luaH_getn = function() {
for (let i = 0; i < len; i++) {
let key = indexes[i];
- if (!this.value.get(key).ttisnil() // t[i] is non-nil
- && (i === len - 1 || this.value.get(indexes[i + 1]).ttisinil())) { // t[i+1] is nil or is the last integer indexed element
- return indexes[i];
+ if (!this.__index(this, key).ttisnil() // t[i] is non-nil
+ && (i === len - 1 || this.__index(this, indexes[i + 1]).ttisnil())) { // t[i+1] is nil or is the last integer indexed element
+ return indexes[i] + 1;
}
}
@@ -50,9 +51,13 @@ Table.prototype.luaH_next = function(L, keyI) {
let keyO = L.stack[keyI];
let key = Table.keyValue(keyO);
let indexes = this.ordered_indexes();
+
+ if (indexes.length === 0) return 0;
+
let i = indexes.indexOf(key);
- if (i >= 0 && i < indexes.length - 1) {
+ if ((i >= 0 || key === null) && i < indexes.length - 1) {
+ if (key === null) i = -1;
let nidx = indexes[i+1];
let tnidx = typeof nidx;
@@ -63,7 +68,7 @@ Table.prototype.luaH_next = function(L, keyI) {
else
L.stack[keyI] = indexes[i + 1];
- L.stack[keyI + 1] = this.map.get(indexes[i]);
+ L.stack[keyI + 1] = this.value.get(indexes[i + 1]);
return 1;
}