mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
Merge pull request #23 from mpeterv/fix-weak-tables
Do not allow collecting weak tables while they are being inspected
This commit is contained in:
commit
efa8b85ab1
@ -114,14 +114,14 @@ local maxIdsMetaTable = {
|
|||||||
|
|
||||||
local idsMetaTable = {
|
local idsMetaTable = {
|
||||||
__index = function (self, typeName)
|
__index = function (self, typeName)
|
||||||
local col = setmetatable({}, {__mode = "kv"})
|
local col = {}
|
||||||
rawset(self, typeName, col)
|
rawset(self, typeName, col)
|
||||||
return col
|
return col
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local function countTableAppearances(t, tableAppearances)
|
local function countTableAppearances(t, tableAppearances)
|
||||||
tableAppearances = tableAppearances or setmetatable({}, {__mode = "k"})
|
tableAppearances = tableAppearances or {}
|
||||||
|
|
||||||
if type(t) == 'table' then
|
if type(t) == 'table' then
|
||||||
if not tableAppearances[t] then
|
if not tableAppearances[t] then
|
||||||
|
@ -350,6 +350,31 @@ describe( 'inspect', function()
|
|||||||
]]), inspect(bar))
|
]]), inspect(bar))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('does not allow collecting weak tables while they are being inspected', function()
|
||||||
|
collectgarbage('stop')
|
||||||
|
finally(function() collectgarbage('restart') end)
|
||||||
|
local shimMetatable = {
|
||||||
|
__mode = 'v',
|
||||||
|
__index = function() return {} end,
|
||||||
|
__tostring = function() collectgarbage() return 'shim' end
|
||||||
|
}
|
||||||
|
local function shim() return setmetatable({}, shimMetatable) end
|
||||||
|
local t = shim()
|
||||||
|
t.key = shim()
|
||||||
|
assert.equals(unindent([[
|
||||||
|
{ -- shim
|
||||||
|
key = { -- shim
|
||||||
|
<metatable> = <1>{
|
||||||
|
__index = <function 1>,
|
||||||
|
__mode = "v",
|
||||||
|
__tostring = <function 2>
|
||||||
|
}
|
||||||
|
},
|
||||||
|
<metatable> = <table 1>
|
||||||
|
}
|
||||||
|
]]), inspect(t))
|
||||||
|
end)
|
||||||
|
|
||||||
describe('When a table is its own metatable', function()
|
describe('When a table is its own metatable', function()
|
||||||
it('accepts a table that is its own metatable without stack overflowing', function()
|
it('accepts a table that is its own metatable without stack overflowing', function()
|
||||||
local x = {}
|
local x = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user