Skip to content

Commit

Permalink
�Bugfix for using "tables with holes" in pairs() reverted. Better sol…
Browse files Browse the repository at this point in the history
…ution found.
  • Loading branch information
paulcuth committed Oct 29, 2014
1 parent fc9ffee commit e69a84d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 10 additions & 0 deletions test/scripts/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')





Expand Down
7 changes: 1 addition & 6 deletions vm/src/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions vm/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 {
Expand Down

0 comments on commit e69a84d

Please sign in to comment.