Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AutoRooters.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "AutoRooters.h"
21 
23 
25  : m_ScriptInterface(scriptInterface)
26 {
28 }
29 
31 {
33  ENSURE(r == this); // must be correctly nested
34 }
35 
36 void AutoGCRooter::Trace(JSTracer* trc)
37 {
38  if (m_Previous)
39  m_Previous->Trace(trc);
40 
41  for (size_t i = 0; i < m_Objects.size(); ++i)
42  {
43  JS_CALL_OBJECT_TRACER(trc, m_Objects[i], "AutoGCRooter object");
44  }
45 
46  for (size_t i = 0; i < m_Vals.size(); ++i)
47  {
48  JS_CALL_VALUE_TRACER(trc, m_Vals[i], "AutoGCRooter val");
49  }
50 
51  for (size_t i = 0; i < m_IdArrays.size(); ++i)
52  {
53  for (jsint j = 0; j < m_IdArrays[i]->length; ++j)
54  {
55  jsval val = JSVAL_VOID;
56  JS_IdToValue(m_ScriptInterface.GetContext(), m_IdArrays[i]->vector[j], &val);
57  JS_CALL_VALUE_TRACER(trc, val, "AutoGCRooter id array");
58  }
59  }
60 
61 }
AutoGCRooter(ScriptInterface &scriptInterface)
Definition: AutoRooters.cpp:24
std::vector< JSIdArray * > m_IdArrays
Definition: AutoRooters.h:49
ScriptInterface & m_ScriptInterface
Definition: AutoRooters.h:44
std::vector< jsval > m_Vals
Definition: AutoRooters.h:48
AutoGCRooter * ReplaceAutoGCRooter(AutoGCRooter *rooter)
#define ENSURE(expr)
ensure the expression &lt;expr&gt; evaluates to non-zero.
Definition: debug.h:282
AutoGCRooter * m_Previous
Definition: AutoRooters.h:45
std::vector< JSObject * > m_Objects
Definition: AutoRooters.h:47
Abstraction around a SpiderMonkey JSContext.
void Trace(JSTracer *trc)
Definition: AutoRooters.cpp:36
JSContext * GetContext() const
Helper for rooting large groups of script values.
Definition: AutoRooters.h:31