Bug 901106 - Pass nsXULPrototypeDocuments directly through serialization and use AutoSafeJSContext at the serialization point. r=smaug

This commit is contained in:
Bobby Holley 2013-08-19 16:24:27 -07:00
Родитель 31ddf22a6f
Коммит 2aa5ae896c
5 изменённых файлов: 48 добавлений и 62 удалений

Просмотреть файл

@ -47,7 +47,6 @@
#include "nsIRDFService.h"
#include "nsIScriptContext.h"
#include "nsIScriptRuntime.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "mozilla/css/StyleRule.h"
@ -1991,7 +1990,7 @@ nsXULPrototypeAttribute::~nsXULPrototypeAttribute()
nsresult
nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsresult rv;
@ -2053,7 +2052,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
case eType_Element:
case eType_Text:
case eType_PI:
tmp = child->Serialize(aStream, aGlobal, aNodeInfos);
tmp = child->Serialize(aStream, aProtoDoc, aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2070,7 +2069,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
rv = tmp;
}
if (! script->mOutOfLine) {
tmp = script->Serialize(aStream, aGlobal, aNodeInfos);
tmp = script->Serialize(aStream, aProtoDoc, aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2088,7 +2087,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
// muxed document is already there (written by a prior
// session, or by an earlier cache episode during this
// session).
tmp = script->SerializeOutOfLine(aStream, aGlobal);
tmp = script->SerializeOutOfLine(aStream, aProtoDoc);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2103,7 +2102,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
@ -2177,7 +2176,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2189,7 +2188,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2201,7 +2200,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2220,7 +2219,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
rv = tmp;
}
if (! script->mOutOfLine) {
tmp = script->Deserialize(aStream, aGlobal, aDocumentURI,
tmp = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
@ -2231,7 +2230,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
rv = tmp;
}
tmp = script->DeserializeOutOfLine(aStream, aGlobal);
tmp = script->DeserializeOutOfLine(aStream, aProtoDoc);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2371,11 +2370,14 @@ nsXULPrototypeScript::~nsXULPrototypeScript()
nsresult
nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsIScriptContext *context = aGlobal->GetScriptContext();
AutoPushJSContext cx(context->GetNativeContext());
AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, aProtoDoc->GetCompilationGlobal());
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
JSAutoCompartment ac(cx, global);
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
!mScriptObject,
"script source still loading when serializing?!");
@ -2402,7 +2404,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal)
nsXULPrototypeDocument* aProtoDoc)
{
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
@ -2432,7 +2434,7 @@ nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
rv = cache->GetOutputStream(mSrcURI, getter_AddRefs(oos));
NS_ENSURE_SUCCESS(rv, rv);
nsresult tmp = Serialize(oos, aGlobal, nullptr);
nsresult tmp = Serialize(oos, aProtoDoc, nullptr);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -2449,7 +2451,7 @@ nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
@ -2461,11 +2463,11 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
aStream->Read32(&mLineNo);
aStream->Read32(&mLangVersion);
nsIScriptContext *context = aGlobal->GetScriptContext();
AutoPushJSContext cx(context->GetNativeContext());
NS_ASSERTION(context != nullptr, "Have no context for deserialization");
NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
JSAutoRequest ar(cx);
AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, aProtoDoc->GetCompilationGlobal());
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
JSAutoCompartment ac(cx, global);
JS::Rooted<JSScript*> newScriptObject(cx);
MOZ_ASSERT(!strcmp(JS_GetClass(JS::CurrentGlobalOrNull(cx))->name,
"nsXULPrototypeScript compilation scope"));
@ -2479,7 +2481,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
nsresult
nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
nsIScriptGlobalObject* aGlobal)
nsXULPrototypeDocument* aProtoDoc)
{
// Keep track of failure via rv, so we can
// AbortCaching if things look bad.
@ -2523,7 +2525,7 @@ nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
// We're better off slow-loading than bailing out due to a
// error.
if (NS_SUCCEEDED(rv))
rv = Deserialize(objectInput, aGlobal, nullptr, nullptr);
rv = Deserialize(objectInput, aProtoDoc, nullptr, nullptr);
if (NS_SUCCEEDED(rv)) {
if (useXULCache && mSrcURI) {
@ -2678,7 +2680,7 @@ nsXULPrototypeScript::Set(JSScript* aObject)
nsresult
nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsresult rv;
@ -2696,7 +2698,7 @@ nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
@ -2714,7 +2716,7 @@ nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
nsresult
nsXULPrototypePI::Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{
nsresult rv;
@ -2736,7 +2738,7 @@ nsXULPrototypePI::Serialize(nsIObjectOutputStream* aStream,
nsresult
nsXULPrototypePI::Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos)
{

Просмотреть файл

@ -44,7 +44,6 @@ class nsXULPrototypeDocument;
class nsIObjectInputStream;
class nsIObjectOutputStream;
class nsIScriptGlobalObject;
class nsXULPrototypeNode;
typedef nsTArray<nsRefPtr<nsXULPrototypeNode> > nsPrototypeArray;
@ -111,10 +110,10 @@ public:
virtual ~nsXULPrototypeNode() {}
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) = 0;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) = 0;
@ -175,10 +174,10 @@ public:
}
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
@ -218,16 +217,16 @@ public:
#endif
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
nsresult SerializeOutOfLine(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal);
nsXULPrototypeDocument* aProtoDoc);
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
nsresult DeserializeOutOfLine(nsIObjectInputStream* aInput,
nsIScriptGlobalObject* aGlobal);
nsXULPrototypeDocument* aProtoDoc);
nsresult Compile(const PRUnichar* aText, int32_t aTextLength,
nsIURI* aURI, uint32_t aLineNo,
@ -293,10 +292,10 @@ public:
#endif
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
@ -321,10 +320,10 @@ public:
#endif
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;
virtual nsresult Deserialize(nsIObjectInputStream* aStream,
nsIScriptGlobalObject* aGlobal,
nsXULPrototypeDocument* aProtoDoc,
nsIURI* aDocumentURI,
const nsCOMArray<nsINodeInfo> *aNodeInfos) MOZ_OVERRIDE;

Просмотреть файл

@ -3615,20 +3615,8 @@ XULDocument::OnScriptCompileComplete(JSScript* aScript, nsresult aStatus)
// Ignore the return value, as we don't need to propagate
// a failure to write to the FastLoad file, because this
// method aborts that whole process on error.
nsIScriptGlobalObject* global =
mCurrentPrototype->GetScriptGlobalObject();
NS_ASSERTION(global != nullptr, "master prototype w/o global?!");
if (global) {
nsIScriptContext *scriptContext =
global->GetScriptContext();
NS_ASSERTION(scriptContext != nullptr,
"Failed to get script context for language");
if (scriptContext)
scriptProto->SerializeOutOfLine(nullptr, global);
}
scriptProto->SerializeOutOfLine(nullptr, mCurrentPrototype);
}
// ignore any evaluation errors
}

Просмотреть файл

@ -985,7 +985,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
// file right away. Otherwise we'll end up reloading the script and
// corrupting the FastLoad file trying to serialize it, in the case
// where it's already there.
script->DeserializeOutOfLine(nullptr, mPrototype->GetScriptGlobalObject());
script->DeserializeOutOfLine(nullptr, mPrototype);
}
nsPrototypeArray* children = nullptr;

Просмотреть файл

@ -349,7 +349,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
break;
}
tmp = pi->Deserialize(aStream, mGlobalObject, mURI, &nodeInfos);
tmp = pi->Deserialize(aStream, this, mURI, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -358,7 +358,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
rv = tmp;
}
} else if ((nsXULPrototypeNode::Type)type == nsXULPrototypeNode::eType_Element) {
tmp = mRoot->Deserialize(aStream, mGlobalObject, mURI, &nodeInfos);
tmp = mRoot->Deserialize(aStream, this, mURI, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
@ -508,20 +508,17 @@ nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream)
}
// Now serialize the document contents
nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED);
count = mProcessingInstructions.Length();
for (i = 0; i < count; ++i) {
nsXULPrototypePI* pi = mProcessingInstructions[i];
tmp = pi->Serialize(aStream, globalObject, &nodeInfos);
tmp = pi->Serialize(aStream, this, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
}
if (mRoot) {
tmp = mRoot->Serialize(aStream, globalObject, &nodeInfos);
tmp = mRoot->Serialize(aStream, this, &nodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}