aboutsummaryrefslogtreecommitdiff
path: root/testes/api.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-01-04 13:09:47 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-01-04 13:09:47 -0200
commit4ace93ca6502dd1da38d5c06fa099d229e791ba8 (patch)
tree34f95ef56aecb56ae1db5e8b843b6e9bd2cbae51 /testes/api.lua
parentc6f7181e910b6b2ff1346b5486a31be87b1da5af (diff)
downloadlua-4ace93ca6502dd1da38d5c06fa099d229e791ba8.tar.gz
lua-4ace93ca6502dd1da38d5c06fa099d229e791ba8.tar.bz2
lua-4ace93ca6502dd1da38d5c06fa099d229e791ba8.zip
No more to-be-closed functions
To-be-closed variables must contain objects with '__toclose' metamethods (or nil). Functions were removed for several reasons: * Functions interact badly with sandboxes. If a sandbox raises an error to interrupt a script, a to-be-closed function still can hijack control and continue running arbitrary sandboxed code. * Functions interact badly with coroutines. If a coroutine yields and is never resumed again, its to-be-closed functions will never run. To-be-closed objects, on the other hand, will still be closed, provided they have appropriate finalizers. * If you really need a function, it is easy to create a dummy object to run that function in its '__toclose' metamethod. This comit also adds closing of variables in case of panic.
Diffstat (limited to '')
-rw-r--r--testes/api.lua19
1 files changed, 18 insertions, 1 deletions
diff --git a/testes/api.lua b/testes/api.lua
index 893a36cb..9904dadf 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -396,6 +396,23 @@ do
396 assert(string.find(msg, "stack overflow")) 396 assert(string.find(msg, "stack overflow"))
397 end 397 end
398 398
399 -- exit in panic still close to-be-closed variables
400 assert(T.checkpanic([[
401 pushstring "return {__close = function () Y = 'ho'; end}"
402 newtable
403 loadstring -2
404 call 0 1
405 setmetatable -2
406 toclose -1
407 pushstring "hi"
408 error
409 ]],
410 [[
411 getglobal Y
412 concat 2 # concat original error with global Y
413 ]]) == "hiho")
414
415
399end 416end
400 417
401-- testing deep C stack 418-- testing deep C stack
@@ -1115,7 +1132,7 @@ end)
1115testamem("to-be-closed variables", function() 1132testamem("to-be-closed variables", function()
1116 local flag 1133 local flag
1117 do 1134 do
1118 local *toclose x = function () flag = true end 1135 local *toclose x = setmetatable({}, {__close = function () flag = true end})
1119 flag = false 1136 flag = false
1120 local x = {} 1137 local x = {}
1121 end 1138 end