From e69a84d452c81a0e186d11dfa8b830744bfd6fe0 Mon Sep 17 00:00:00 2001 From: Paul Cuthbertson Date: Wed, 29 Oct 2014 14:12:00 +0000 Subject: [PATCH] Bugfix for using "tables with holes" in pairs() reverted. Better solution found. --- test/scripts/lib.lua | 10 ++++++++++ vm/src/Table.js | 7 +------ vm/src/lib.js | 6 ++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/scripts/lib.lua b/test/scripts/lib.lua index f684c3c..8c2454c 100644 --- a/test/scripts/lib.lua +++ b/test/scripts/lib.lua @@ -244,6 +244,16 @@ assertTrue (r.string, 'pairs() should iterate over string keys') assertTrue (r.half, 'pairs() should iterate over non-integer numberic keys') +t = { nil, nil, 123 } +a = '' + +for i, v in pairs(t) do + a = a..i..':'..v..';' +end + +assertTrue (a == '3:123;', 'pairs() should iterate over numeric table items') + + diff --git a/vm/src/Table.js b/vm/src/Table.js index 98e940d..382c94b 100644 --- a/vm/src/Table.js +++ b/vm/src/Table.js @@ -180,12 +180,7 @@ case 'number': if (positiveIntegerKey) { - if (value === undefined) { - delete this.__shine.numValues[key]; - } else { - this.__shine.numValues[key] = value; - } - + this.__shine.numValues[key] = value; break; } diff --git a/vm/src/lib.js b/vm/src/lib.js index efa4dba..fe304d9 100644 --- a/vm/src/lib.js +++ b/vm/src/lib.js @@ -340,6 +340,7 @@ var found = (index === undefined), numValues = table.__shine.numValues, keys, + key, value, i, l; if (found || (typeof index == 'number' && index > 0 && index == index >> 0)) { @@ -355,8 +356,9 @@ found = true; } - if (found && (i = keys[i]) !== undefined && numValues[i] !== undefined) { - return [i >>= 0, numValues[i]]; + if (found) { + while ((key = keys[i]) !== void 0 && (value = numValues[key]) === void 0) i++; + if (value !== void 0) return [i >>= 0, value]; } } else {