1
0
forked from mirrors/0ad

Replace JS_Enumerate with manual enumeration, to avoid its memory allocations.

Use LookupProperty to avoid having to check for getters.
Add a quicker method of rooting many script values.

This was SVN commit r7579.
This commit is contained in:
Ykkrosh
2010-05-25 18:24:12 +00:00
parent 121d1ead20
commit 47a03c3397
8 changed files with 158 additions and 51 deletions
+22 -1
View File
@@ -59,6 +59,8 @@ struct ScriptInterface_impl
JSContext* m_cx;
JSObject* m_glob; // global scope object
JSObject* m_nativeScope; // native function scope object
AutoGCRooter* m_rooter;
};
namespace
@@ -163,7 +165,16 @@ static void* jshook_function(JSContext* cx, JSStackFrame* fp, JSBool before, JSB
}
#endif
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, JSContext* cx)
void jshook_trace(JSTracer* trc, void* data)
{
ScriptInterface_impl* m = static_cast<ScriptInterface_impl*>(data);
if (m->m_rooter)
m->m_rooter->Trace(trc);
}
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, JSContext* cx) :
m_rooter(NULL)
{
JSBool ok;
@@ -201,6 +212,8 @@ ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, JSContex
| JSOPTION_VAROBJFIX // "recommended" (fixes variable scoping)
);
JS_SetExtraGCRoots(m_rt, jshook_trace, this);
// Threadsafe SpiderMonkey requires that we have a request before doing anything much
JS_BeginRequest(m_cx);
@@ -296,6 +309,14 @@ bool ScriptInterface::RemoveRoot(void* ptr)
return JS_RemoveRoot(m->m_cx, ptr) ? true : false;
}
AutoGCRooter* ScriptInterface::ReplaceAutoGCRooter(AutoGCRooter* rooter)
{
debug_assert(m->m_rt); // this class must own the runtime, else the rooter won't work
AutoGCRooter* ret = m->m_rooter;
m->m_rooter = rooter;
return ret;
}
ScriptInterface::LocalRootScope::LocalRootScope(JSContext* cx) :
m_cx(cx)
{