File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -2033,15 +2033,21 @@ end
20332033-- context = getContext( [ requiredContextNames=any ] )
20342034function _G.getContext(ctxName)
20352035 for level = 3, 1/0 do -- Assume the caller is a webgen function, so start at level 3.
2036- local ctx = getfenv(level) -- We shouldn't reach an invalid level because pretty much the whole program runs in a context.
2036+ if not debug.getinfo(level, "") then break end
2037+
2038+ -- Note: We shouldn't reach an invalid level because pretty much the
2039+ -- whole program runs in a 'none' context. However, if a level is a
2040+ -- tail call then getfenv() will raise an error.
2041+ local ok, ctx = pcall(getfenv, level)
2042+ if not ok then ctx = nil end
20372043
20382044 if isContext(ctx) then
20392045 if ctxName then _assertContext(ctx, ctxName, nil, 2) end
20402046 return ctx
20412047 end
20422048 end
20432049
2044- error("Internal error: There is no context.", 2) -- We should never get here as getfenv() should raise an error first.
2050+ error("Internal error: There is no context.", 2)
20452051end
20462052
20472053function _G.isContext(v)
You can’t perform that action at this time.
0 commit comments