mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-21 20:27:13 +01:00
Include a guard in the object iteration helper to avoid leaking in case of exception.
This commit is contained in:
parent
641fa973e0
commit
5fa97e17d9
@ -512,15 +512,17 @@ public:
|
|||||||
template<class F>
|
template<class F>
|
||||||
void Foreach(F&& func) const
|
void Foreach(F&& func) const
|
||||||
{
|
{
|
||||||
|
const StackGuard sg(vm);
|
||||||
sq_pushobject(vm,obj);
|
sq_pushobject(vm,obj);
|
||||||
sq_pushnull(vm);
|
sq_pushnull(vm);
|
||||||
while(SQ_SUCCEEDED(sq_next(vm,-2)))
|
while(SQ_SUCCEEDED(sq_next(vm,-2)))
|
||||||
{
|
{
|
||||||
func(vm); // -1 is the value and -2 is the key
|
if (!func(vm))
|
||||||
sq_pop(vm,2); // Pop the key and value
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sq_pop(vm,2);
|
||||||
}
|
}
|
||||||
// Pop the null iterator and the object
|
|
||||||
sq_pop(vm,2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user