Bug 824958 - Eliminate nsXULPrototypeScript::ScriptObjectHolder and make field private. r=smaug

This commit is contained in:
Andrew McCreight 2012-08-24 13:22:23 -07:00
parent 223411b20e
commit 7b004d061c
4 changed files with 29 additions and 30 deletions

View File

@ -1858,8 +1858,9 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXULPrototypeNode)
if (tmp->mType == nsXULPrototypeNode::eType_Script) {
nsXULPrototypeScript *script =
static_cast<nsXULPrototypeScript*>(tmp);
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(script->mScriptObject.mObject,
"mScriptObject.mObject")
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(script->GetScriptObject(),
"mScriptObject")
}
NS_IMPL_CYCLE_COLLECTION_TRACE_END
@ -1975,7 +1976,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
rv = tmp;
}
if (script->mScriptObject.mObject) {
if (script->GetScriptObject()) {
// This may return NS_OK without muxing script->mSrcURI's
// data into the cache file, in the case where that
// muxed document is already there (written by a prior
@ -2236,7 +2237,7 @@ nsXULPrototypeScript::nsXULPrototypeScript(uint32_t aLineNo, uint32_t aVersion)
mOutOfLine(true),
mSrcLoadWaiters(nullptr),
mLangVersion(aVersion),
mScriptObject()
mScriptObject(nullptr)
{
}
@ -2253,9 +2254,9 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
{
nsIScriptContext *context = aGlobal->GetScriptContext();
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
!mScriptObject.mObject,
!mScriptObject,
"script source still loading when serializing?!");
if (!mScriptObject.mObject)
if (!mScriptObject)
return NS_ERROR_FAILURE;
// Write basic prototype data
@ -2265,7 +2266,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
rv = aStream->Write32(mLangVersion);
if (NS_FAILED(rv)) return rv;
// And delegate the writing to the nsIScriptContext
rv = context->Serialize(aStream, mScriptObject.mObject);
rv = context->Serialize(aStream, mScriptObject);
if (NS_FAILED(rv)) return rv;
return NS_OK;
@ -2328,7 +2329,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
nsresult rv;
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
!mScriptObject.mObject,
!mScriptObject,
"prototype script not well-initialized when deserializing?!");
// Read basic prototype data
@ -2381,7 +2382,7 @@ nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
}
}
if (! mScriptObject.mObject) {
if (!mScriptObject) {
if (mSrcURI) {
rv = cache->GetInputStream(mSrcURI, getter_AddRefs(objectInput));
}
@ -2402,7 +2403,7 @@ nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
bool isChrome = false;
mSrcURI->SchemeIs("chrome", &isChrome);
if (isChrome)
cache->PutScript(mSrcURI, mScriptObject.mObject);
cache->PutScript(mSrcURI, mScriptObject);
}
cache->FinishInputStream(mSrcURI);
} else {
@ -2489,8 +2490,8 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
void
nsXULPrototypeScript::UnlinkJSObjects()
{
if (mScriptObject.mObject) {
mScriptObject.mObject = nullptr;
if (mScriptObject) {
mScriptObject = nullptr;
nsContentUtils::DropJSObjects(this);
}
}
@ -2498,15 +2499,15 @@ nsXULPrototypeScript::UnlinkJSObjects()
void
nsXULPrototypeScript::Set(JSScript* aObject)
{
NS_ASSERTION(!mScriptObject.mObject, "Leaking script object.");
MOZ_ASSERT(!mScriptObject, "Leaking script object.");
if (!aObject) {
mScriptObject.mObject = nullptr;
mScriptObject = nullptr;
return;
}
nsContentUtils::HoldJSObjects(
this, NS_CYCLE_COLLECTION_PARTICIPANT(nsXULPrototypeNode));
mScriptObject.mObject = aObject;
mScriptObject = aObject;
}
//----------------------------------------------------------------------

View File

@ -235,13 +235,10 @@ public:
}
void Set(JSScript* aObject);
struct ScriptObjectHolder
JSScript *GetScriptObject()
{
ScriptObjectHolder() : mObject(nullptr)
{
}
JSScript* mObject;
};
return mScriptObject;
}
nsCOMPtr<nsIURI> mSrcURI;
uint32_t mLineNo;
@ -249,7 +246,8 @@ public:
bool mOutOfLine;
nsXULDocument* mSrcLoadWaiters; // [OWNER] but not COMPtr
uint32_t mLangVersion;
ScriptObjectHolder mScriptObject;
private:
JSScript* mScriptObject;
};
class nsXULPrototypeText : public nsXULPrototypeNode

View File

@ -530,7 +530,7 @@ XULContentSinkImpl::HandleEndElement(const PRUnichar *aName)
static_cast<nsXULPrototypeScript*>(node.get());
// If given a src= attribute, we must ignore script tag content.
if (! script->mSrcURI && ! script->mScriptObject.mObject) {
if (!script->mSrcURI && !script->GetScriptObject()) {
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
script->mOutOfLine = false;

View File

@ -2932,7 +2932,7 @@ nsXULDocument::ResumeWalk()
if (NS_SUCCEEDED(rv) && blocked)
return NS_OK;
}
else if (scriptproto->mScriptObject.mObject) {
else if (scriptproto->GetScriptObject()) {
// An inline script
rv = ExecuteScript(scriptproto);
if (NS_FAILED(rv)) return rv;
@ -3285,7 +3285,7 @@ nsXULDocument::LoadScript(nsXULPrototypeScript* aScriptProto, bool* aBlock)
bool isChromeDoc = IsChromeURI(mDocumentURI);
if (isChromeDoc && aScriptProto->mScriptObject.mObject) {
if (isChromeDoc && aScriptProto->GetScriptObject()) {
rv = ExecuteScript(aScriptProto);
// Ignore return value from execution, and don't block
@ -3308,7 +3308,7 @@ nsXULDocument::LoadScript(nsXULPrototypeScript* aScriptProto, bool* aBlock)
aScriptProto->Set(newScriptObject);
}
if (aScriptProto->mScriptObject.mObject) {
if (aScriptProto->GetScriptObject()) {
rv = ExecuteScript(aScriptProto);
// Ignore return value from execution, and don't block
@ -3466,7 +3466,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
if (useXULCache && IsChromeURI(mDocumentURI)) {
nsXULPrototypeCache::GetInstance()->PutScript(
scriptProto->mSrcURI,
scriptProto->mScriptObject.mObject);
scriptProto->GetScriptObject());
}
if (mIsWritingFastLoad && mCurrentPrototype != mMasterPrototype) {
@ -3517,7 +3517,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
doc->mNextSrcLoadWaiter = nullptr;
// Execute only if we loaded and compiled successfully, then resume
if (NS_SUCCEEDED(aStatus) && scriptProto->mScriptObject.mObject) {
if (NS_SUCCEEDED(aStatus) && scriptProto->GetScriptObject()) {
doc->ExecuteScript(scriptProto);
}
doc->ResumeWalk();
@ -3558,8 +3558,8 @@ nsXULDocument::ExecuteScript(nsXULPrototypeScript *aScript)
// failure getting a script context is fatal.
NS_ENSURE_TRUE(context != nullptr, NS_ERROR_UNEXPECTED);
if (aScript->mScriptObject.mObject)
rv = ExecuteScript(context, aScript->mScriptObject.mObject);
if (aScript->GetScriptObject())
rv = ExecuteScript(context, aScript->GetScriptObject());
else
rv = NS_ERROR_UNEXPECTED;
return rv;