Fixed issue: #96
This commit is contained in:
@@ -119,8 +119,12 @@ public class WeakTable implements Metatable {
|
|||||||
if ( key != null && value != null ) {
|
if ( key != null && value != null ) {
|
||||||
return new LuaTable.NormalEntry(key, value);
|
return new LuaTable.NormalEntry(key, value);
|
||||||
} else {
|
} else {
|
||||||
|
if ( key == null ) {
|
||||||
this.key = null;
|
this.key = null;
|
||||||
|
}
|
||||||
|
if ( value == null ) {
|
||||||
this.value = null;
|
this.value = null;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,23 @@ abstract public class WeakTableTest extends TableTest {
|
|||||||
assertEquals(LuaValue.NIL, t.get(1));
|
assertEquals(LuaValue.NIL, t.get(1));
|
||||||
assertFalse("strings should not be in weak references", t.get("string").isnil());
|
assertFalse("strings should not be in weak references", t.get("string").isnil());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testWeakValueRehashAfterGcDoesNotDropStrongKeyOrThrow() {
|
||||||
|
LuaTable t = new_Table();
|
||||||
|
|
||||||
|
for ( int i = 0; i < 100; i++ ) {
|
||||||
|
t.set("dead-" + i, new LuaTable());
|
||||||
|
}
|
||||||
|
|
||||||
|
collectGarbage();
|
||||||
|
|
||||||
|
for ( int i = 0; i < 100; i++ ) {
|
||||||
|
assertEquals(LuaValue.NIL, t.get("dead-" + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
t.set("survivor", LuaValue.valueOf("ok"));
|
||||||
|
assertEquals(LuaValue.valueOf("ok"), t.get("survivor"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class WeakKeyTableTest extends WeakTableTest {
|
public static class WeakKeyTableTest extends WeakTableTest {
|
||||||
|
|||||||
Reference in New Issue
Block a user