mirror of
https://github.com/kikito/lua-sandbox.git
synced 2024-12-18 03:04:20 +00:00
naming & refactoring
This commit is contained in:
parent
3a90dc3319
commit
c1e5b44938
10
sandbox.lua
10
sandbox.lua
@ -65,14 +65,14 @@ local function run(f, options)
|
|||||||
-- I would love to be able to make step greater than 1
|
-- I would love to be able to make step greater than 1
|
||||||
-- (say, 500000) but any value > 1 seems to choke with a simple while true do end
|
-- (say, 500000) but any value > 1 seems to choke with a simple while true do end
|
||||||
-- After ~100 iterations, they stop calling timeout. So I need to use step = 1 and
|
-- After ~100 iterations, they stop calling timeout. So I need to use step = 1 and
|
||||||
-- count the steps separatedly
|
-- instructions_count the steps separatedly
|
||||||
local step = 1
|
local step = 1
|
||||||
local count = 0
|
local instructions_count = 0
|
||||||
local timeout = function(str)
|
local timeout = function(str)
|
||||||
count = count + 1
|
instructions_count = instructions_count + 1
|
||||||
if count >= limit then
|
if instructions_count >= limit then
|
||||||
cleanup()
|
cleanup()
|
||||||
error('Timeout')
|
error('Quota exceeded: ' .. tostring(instructions_count) .. '/' .. tostring(limit) .. ' instructions')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
debug.sethook(timeout, "", step)
|
debug.sethook(timeout, "", step)
|
||||||
|
@ -40,13 +40,19 @@ describe('sandbox', function()
|
|||||||
|
|
||||||
|
|
||||||
describe('when handling infinite loops', function()
|
describe('when handling infinite loops', function()
|
||||||
|
|
||||||
it('throws an error with infinite loops', function()
|
it('throws an error with infinite loops', function()
|
||||||
assert.has_error(function() sandbox("while true do end") end)
|
assert.has_error(function() sandbox("while true do end") end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('restores string.rep even after a while true', function()
|
||||||
|
assert.has_error(function() sandbox("while true do end") end)
|
||||||
|
assert.equal('hellohello', string.rep('hello', 2))
|
||||||
|
end)
|
||||||
|
|
||||||
it('#focus accepts a limit param', function()
|
it('#focus accepts a limit param', function()
|
||||||
--assert.no_has_error(function() sandbox("for i=1,10000 do end") end)
|
assert.no_has_error(function() sandbox("for i=1,100 do end") end)
|
||||||
assert.has_error(function() sandbox("for i=1,10000 do end", {limit = 50}) end)
|
assert.has_error(function() sandbox("for i=1,100 do end", {limit = 50}) end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user