1 /******************************************************************************
3 * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "base/scriptframe.hpp"
21 #include "base/scriptglobal.hpp"
22 #include "base/exception.hpp"
24 using namespace icinga;
26 boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;
28 ScriptFrame::ScriptFrame(void)
29 : Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false)
34 ScriptFrame::ScriptFrame(const Value& self)
35 : Locals(new Dictionary()), Self(self), Sandboxed(false)
40 ScriptFrame::~ScriptFrame(void)
42 ScriptFrame *frame = PopFrame();
43 ASSERT(frame == this);
46 ScriptFrame *ScriptFrame::GetCurrentFrame(void)
48 std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
50 ASSERT(!frames->empty());
54 ScriptFrame *ScriptFrame::PopFrame(void)
56 std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
58 ASSERT(!frames->empty());
60 ScriptFrame *frame = frames->top();
66 void ScriptFrame::PushFrame(ScriptFrame *frame)
68 std::stack<ScriptFrame *> *frames = m_ScriptFrames.get();
71 frames = new std::stack<ScriptFrame *>();
72 m_ScriptFrames.reset(frames);
75 if (frames->size() > 500)
76 BOOST_THROW_EXCEPTION(ScriptError("Recursion level too deep."));