зеркало из https://github.com/mozilla/gecko-dev.git
Bug 626631 - nsAutoJSValHolder should root its jsval (r=gal)
--HG-- extra : rebase_source : 12bb96e9927e7c8740ccbd4b3838894a81165861
This commit is contained in:
Родитель
514649def9
Коммит
00fb7faade
|
@ -56,7 +56,6 @@ public:
|
||||||
nsAutoJSValHolder()
|
nsAutoJSValHolder()
|
||||||
: mRt(NULL)
|
: mRt(NULL)
|
||||||
, mVal(JSVAL_NULL)
|
, mVal(JSVAL_NULL)
|
||||||
, mGCThing(NULL)
|
|
||||||
, mHeld(JS_FALSE)
|
, mHeld(JS_FALSE)
|
||||||
{
|
{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
|
@ -78,11 +77,11 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hold by rooting on the runtime.
|
* Hold by rooting on the runtime.
|
||||||
* Note that mGCThing may be JSVAL_NULL, which is not a problem.
|
* Note that mVal may be JSVAL_NULL, which is not a problem.
|
||||||
*/
|
*/
|
||||||
JSBool Hold(JSRuntime* aRt) {
|
JSBool Hold(JSRuntime* aRt) {
|
||||||
if (!mHeld) {
|
if (!mHeld) {
|
||||||
if (js_AddGCThingRootRT(aRt, &mGCThing, "nsAutoJSValHolder")) {
|
if (js_AddRootRT(aRt, &mVal, "nsAutoJSValHolder")) {
|
||||||
mRt = aRt;
|
mRt = aRt;
|
||||||
mHeld = JS_TRUE;
|
mHeld = JS_TRUE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,7 +92,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manually release, nullifying mVal, mGCThing, and mRt, but returning
|
* Manually release, nullifying mVal, and mRt, but returning
|
||||||
* the original jsval.
|
* the original jsval.
|
||||||
*/
|
*/
|
||||||
jsval Release() {
|
jsval Release() {
|
||||||
|
@ -102,12 +101,11 @@ public:
|
||||||
jsval oldval = mVal;
|
jsval oldval = mVal;
|
||||||
|
|
||||||
if (mHeld) {
|
if (mHeld) {
|
||||||
js_RemoveRoot(mRt, &mGCThing); // infallible
|
js_RemoveRoot(mRt, &mVal); // infallible
|
||||||
mHeld = JS_FALSE;
|
mHeld = JS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
mVal = JSVAL_NULL;
|
mVal = JSVAL_NULL;
|
||||||
mGCThing = NULL;
|
|
||||||
mRt = NULL;
|
mRt = NULL;
|
||||||
|
|
||||||
return oldval;
|
return oldval;
|
||||||
|
@ -154,16 +152,12 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
mVal = aOther;
|
mVal = aOther;
|
||||||
mGCThing = JSVAL_IS_GCTHING(aOther)
|
|
||||||
? JSVAL_TO_GCTHING(aOther)
|
|
||||||
: NULL;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JSRuntime* mRt;
|
JSRuntime* mRt;
|
||||||
jsval mVal;
|
jsval mVal;
|
||||||
void* mGCThing;
|
|
||||||
JSBool mHeld;
|
JSBool mHeld;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче