summaryrefslogtreecommitdiff
path: root/server/src/vm
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-16 17:45:15 +0800
committersumneko <sumneko@hotmail.com>2019-04-16 17:45:15 +0800
commit4dc47156c80ef19b8649c603a8f9f1f5e0e66ba8 (patch)
treec7838e0e4982e182fc7879b3665c2302d6862a6d /server/src/vm
parent2c185dc55131dd7ccd490e53b5f44c48461687fe (diff)
downloadlua-language-server-4dc47156c80ef19b8649c603a8f9f1f5e0e66ba8.zip
修正一个泄露:全局函数的返回值需要标记为全局
Diffstat (limited to 'server/src/vm')
-rw-r--r--server/src/vm/function.lua18
-rw-r--r--server/src/vm/value.lua7
2 files changed, 25 insertions, 0 deletions
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index 9453defa..9dcc1f02 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -118,6 +118,9 @@ function mt:setReturn(index, value)
if value then
self.returns[index] = value
end
+ if self._global then
+ value:markGlobal()
+ end
end
function mt:mergeReturn(index, value)
@@ -136,6 +139,9 @@ function mt:mergeReturn(index, value)
self.returns[index] = value
end
end
+ if self._global then
+ value:markGlobal()
+ end
end
function mt:getReturn(index)
@@ -308,6 +314,18 @@ function mt:kill()
listMgr.clear(self.id)
end
+function mt:markGlobal()
+ if self._global then
+ return
+ end
+ self._global = true
+ if self.returns then
+ self.returns:eachValue(function (_, v)
+ v:markGlobal()
+ end)
+ end
+end
+
local function create(source)
if not source then
error('Function need source')
diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua
index c93fda90..2a1c14d1 100644
--- a/server/src/vm/value.lua
+++ b/server/src/vm/value.lua
@@ -446,6 +446,9 @@ end
function mt:setFunction(func)
self._func = func.id
+ if self._global then
+ func:markGlobal()
+ end
end
function mt:getFunction()
@@ -502,6 +505,10 @@ function mt:markGlobal()
self:rawEach(function (index, value)
value:markGlobal()
end)
+ local func = self:getFunction()
+ if func then
+ func:markGlobal()
+ end
end
function mt:isGlobal()