added test and fix for undue hard reference storage

This commit is contained in:
Enrique García 2011-11-01 22:36:43 +01:00
parent 9ee88a6f4f
commit 71c1118039
2 changed files with 13 additions and 1 deletions

View File

@ -18,7 +18,8 @@ local Node = {
} }
function Node:new() function Node:new()
return setmetatable( { callbacks = {}, children = {} }, { __index = Node } ) local node = { callbacks = {}, children = setmetatable({}, {__mode="k"}) }
return setmetatable( node, { __index = Node } )
end end
function Node:findById(id) function Node:findById(id)

View File

@ -45,6 +45,17 @@ describe("Unit", function()
it("throws an error if called without at least one parameter", function() it("throws an error if called without at least one parameter", function()
assert_error(function() beholder:observe() end) assert_error(function() beholder:observe() end)
end) end)
it("does not store hard references to variables", function()
local counter = 0
local x = {}
beholder:observe(x, function() counter = counter + 1 end)
beholder:triggerAll()
x = nil
collectgarbage("collect")
beholder:triggerAll()
assert_equal(1, counter)
end)
end) end)
describe(":stopObserving", function() describe(":stopObserving", function()