зеркало из https://github.com/mozilla/gecko-dev.git
Bug 332648 - Part a: Move AutoGCRooter to jsapi.h; r=evilpie
This also moves AutoCheckRequestDepth into jsapi.h and moves some assertions from CHECK_REQUEST to the AutoCheckRequestDepth constructor.
This commit is contained in:
Родитель
ddea4e045a
Коммит
60a7130336
|
@ -6855,3 +6855,22 @@ JS_CallOnce(JSCallOnceType *once, JSInitCallback func)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace JS {
|
||||
|
||||
AutoGCRooter::AutoGCRooter(JSContext *cx, ptrdiff_t tag)
|
||||
: down(cx->autoGCRooters), tag(tag), context(cx)
|
||||
{
|
||||
JS_ASSERT(this != cx->autoGCRooters);
|
||||
CHECK_REQUEST(cx);
|
||||
cx->autoGCRooters = this;
|
||||
}
|
||||
|
||||
AutoGCRooter::~AutoGCRooter()
|
||||
{
|
||||
JS_ASSERT(this == context->autoGCRooters);
|
||||
CHECK_REQUEST(context);
|
||||
context->autoGCRooters = down;
|
||||
}
|
||||
|
||||
} // namespace JS
|
||||
|
|
|
@ -54,6 +54,10 @@
|
|||
|
||||
#include "js/Utility.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "mozilla/Attributes.h"
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/* JS::Value can store a full int32_t. */
|
||||
|
@ -786,6 +790,74 @@ inline Anchor<Value>::~Anchor()
|
|||
|
||||
#endif
|
||||
|
||||
#if defined JS_THREADSAFE && defined DEBUG
|
||||
|
||||
class JS_PUBLIC_API(AutoCheckRequestDepth)
|
||||
{
|
||||
JSContext *cx;
|
||||
public:
|
||||
AutoCheckRequestDepth(JSContext *cx);
|
||||
~AutoCheckRequestDepth();
|
||||
};
|
||||
|
||||
# define CHECK_REQUEST(cx) \
|
||||
JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx)
|
||||
|
||||
#else
|
||||
|
||||
# define CHECK_REQUEST(cx) \
|
||||
((void) 0)
|
||||
|
||||
#endif
|
||||
|
||||
class JS_PUBLIC_API(AutoGCRooter) {
|
||||
public:
|
||||
AutoGCRooter(JSContext *cx, ptrdiff_t tag);
|
||||
~AutoGCRooter();
|
||||
|
||||
/* Implemented in jsgc.cpp. */
|
||||
inline void trace(JSTracer *trc);
|
||||
void traceAll(JSTracer *trc);
|
||||
|
||||
protected:
|
||||
AutoGCRooter * const down;
|
||||
|
||||
/*
|
||||
* Discriminates actual subclass of this being used. If non-negative, the
|
||||
* subclass roots an array of values of the length stored in this field.
|
||||
* If negative, meaning is indicated by the corresponding value in the enum
|
||||
* below. Any other negative value indicates some deeper problem such as
|
||||
* memory corruption.
|
||||
*/
|
||||
ptrdiff_t tag;
|
||||
|
||||
JSContext * const context;
|
||||
|
||||
enum {
|
||||
JSVAL = -1, /* js::AutoValueRooter */
|
||||
VALARRAY = -2, /* js::AutoValueArrayRooter */
|
||||
PARSER = -3, /* js::Parser */
|
||||
SHAPEVECTOR = -4, /* js::AutoShapeVector */
|
||||
ENUMERATOR = -5, /* js::AutoEnumStateRooter */
|
||||
IDARRAY = -6, /* js::AutoIdArray */
|
||||
DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */
|
||||
NAMESPACES = -8, /* js::AutoNamespaceArray */
|
||||
XML = -9, /* js::AutoXMLRooter */
|
||||
OBJECT = -10, /* js::AutoObjectRooter */
|
||||
ID = -11, /* js::AutoIdRooter */
|
||||
VALVECTOR = -12, /* js::AutoValueVector */
|
||||
DESCRIPTOR = -13, /* js::AutoPropertyDescriptorRooter */
|
||||
STRING = -14, /* js::AutoStringRooter */
|
||||
IDVECTOR = -15, /* js::AutoIdVector */
|
||||
OBJVECTOR = -16 /* js::AutoObjectVector */
|
||||
};
|
||||
|
||||
private:
|
||||
/* No copy or assignment semantics. */
|
||||
AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE;
|
||||
void operator=(AutoGCRooter &ida) MOZ_DELETE;
|
||||
};
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
/************************************************************************/
|
||||
|
|
|
@ -1712,3 +1712,26 @@ AutoEnumStateRooter::~AutoEnumStateRooter()
|
|||
}
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
namespace JS {
|
||||
|
||||
#if defined JS_THREADSAFE && defined DEBUG
|
||||
|
||||
AutoCheckRequestDepth::AutoCheckRequestDepth(JSContext *cx)
|
||||
: cx(cx)
|
||||
{
|
||||
JS_ASSERT(cx->thread());
|
||||
JS_ASSERT(cx->thread()->data.requestDepth || cx->thread() == cx->runtime->gcThread);
|
||||
JS_ASSERT(cx->runtime->onOwnerThread());
|
||||
cx->thread()->checkRequestDepth++;
|
||||
}
|
||||
|
||||
AutoCheckRequestDepth::~AutoCheckRequestDepth()
|
||||
{
|
||||
JS_ASSERT(cx->thread()->checkRequestDepth != 0);
|
||||
cx->thread()->checkRequestDepth--;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace JS
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "jsprvtd.h"
|
||||
#include "jsatom.h"
|
||||
|
@ -794,7 +795,6 @@ extern const JSDebugHooks js_NullDebugHooks; /* defined in jsdbgapi.cpp */
|
|||
|
||||
namespace js {
|
||||
|
||||
class AutoGCRooter;
|
||||
template <typename T> class Root;
|
||||
class CheckRoot;
|
||||
|
||||
|
@ -1310,29 +1310,6 @@ struct JSContext
|
|||
|
||||
namespace js {
|
||||
|
||||
#if defined JS_THREADSAFE && defined DEBUG
|
||||
|
||||
class AutoCheckRequestDepth {
|
||||
JSContext *cx;
|
||||
public:
|
||||
AutoCheckRequestDepth(JSContext *cx) : cx(cx) { cx->thread()->checkRequestDepth++; }
|
||||
|
||||
~AutoCheckRequestDepth() {
|
||||
JS_ASSERT(cx->thread()->checkRequestDepth != 0);
|
||||
cx->thread()->checkRequestDepth--;
|
||||
}
|
||||
};
|
||||
|
||||
# define CHECK_REQUEST(cx) \
|
||||
JS_ASSERT((cx)->thread()); \
|
||||
JS_ASSERT((cx)->thread()->data.requestDepth || (cx)->thread() == (cx)->runtime->gcThread); \
|
||||
JS_ASSERT(cx->runtime->onOwnerThread()); \
|
||||
AutoCheckRequestDepth _autoCheckRequestDepth(cx);
|
||||
|
||||
#else
|
||||
# define CHECK_REQUEST(cx) ((void) 0)
|
||||
#endif
|
||||
|
||||
struct AutoResolving {
|
||||
public:
|
||||
enum Kind {
|
||||
|
@ -1369,64 +1346,6 @@ struct AutoResolving {
|
|||
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
};
|
||||
|
||||
class AutoGCRooter {
|
||||
public:
|
||||
AutoGCRooter(JSContext *cx, ptrdiff_t tag)
|
||||
: down(cx->autoGCRooters), tag(tag), context(cx)
|
||||
{
|
||||
JS_ASSERT(this != cx->autoGCRooters);
|
||||
CHECK_REQUEST(cx);
|
||||
cx->autoGCRooters = this;
|
||||
}
|
||||
|
||||
~AutoGCRooter() {
|
||||
JS_ASSERT(this == context->autoGCRooters);
|
||||
CHECK_REQUEST(context);
|
||||
context->autoGCRooters = down;
|
||||
}
|
||||
|
||||
/* Implemented in jsgc.cpp. */
|
||||
inline void trace(JSTracer *trc);
|
||||
void traceAll(JSTracer *trc);
|
||||
|
||||
protected:
|
||||
AutoGCRooter * const down;
|
||||
|
||||
/*
|
||||
* Discriminates actual subclass of this being used. If non-negative, the
|
||||
* subclass roots an array of values of the length stored in this field.
|
||||
* If negative, meaning is indicated by the corresponding value in the enum
|
||||
* below. Any other negative value indicates some deeper problem such as
|
||||
* memory corruption.
|
||||
*/
|
||||
ptrdiff_t tag;
|
||||
|
||||
JSContext * const context;
|
||||
|
||||
enum {
|
||||
JSVAL = -1, /* js::AutoValueRooter */
|
||||
VALARRAY = -2, /* js::AutoValueArrayRooter */
|
||||
PARSER = -3, /* js::Parser */
|
||||
SHAPEVECTOR = -4, /* js::AutoShapeVector */
|
||||
ENUMERATOR = -5, /* js::AutoEnumStateRooter */
|
||||
IDARRAY = -6, /* js::AutoIdArray */
|
||||
DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */
|
||||
NAMESPACES = -8, /* js::AutoNamespaceArray */
|
||||
XML = -9, /* js::AutoXMLRooter */
|
||||
OBJECT = -10, /* js::AutoObjectRooter */
|
||||
ID = -11, /* js::AutoIdRooter */
|
||||
VALVECTOR = -12, /* js::AutoValueVector */
|
||||
DESCRIPTOR = -13, /* js::AutoPropertyDescriptorRooter */
|
||||
STRING = -14, /* js::AutoStringRooter */
|
||||
IDVECTOR = -15, /* js::AutoIdVector */
|
||||
OBJVECTOR = -16 /* js::AutoObjectVector */
|
||||
};
|
||||
|
||||
private:
|
||||
AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE;
|
||||
void operator=(AutoGCRooter &ida) MOZ_DELETE;
|
||||
};
|
||||
|
||||
/*
|
||||
* Moving GC Stack Rooting
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
#include <new>
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsarray.h"
|
||||
#include "jsbool.h"
|
||||
#include "jscntxt.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче