Bug 738760 - Move nsContentUtils::GetContextAndScope into nsDocument.cpp; r=sicking

This commit is contained in:
Ms2ger 2012-04-03 09:25:39 +02:00
Родитель 3ca758f544
Коммит 03768e8823
3 изменённых файлов: 70 добавлений и 73 удалений

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

@ -250,20 +250,6 @@ public:
*/
static JSContext* GetContextFromDocument(nsIDocument *aDocument);
/**
* Get a scope from aNewDocument. Also get a context through the scope of one
* of the documents, from the stack or the safe context.
*
* @param aOldDocument The document to try to get a context from. May be null.
* @param aNewDocument The document to get aNewScope from.
* @param aCx [out] Context gotten through one of the scopes, from the stack
* or the safe context.
* @param aNewScope [out] Scope gotten from aNewDocument.
*/
static nsresult GetContextAndScope(nsIDocument *aOldDocument,
nsIDocument *aNewDocument,
JSContext **aCx, JSObject **aNewScope);
/**
* When a document's scope changes (e.g., from document.open(), call this
* function to move all content wrappers from the old scope to the new one.

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

@ -1616,64 +1616,6 @@ nsContentUtils::GetContextFromDocument(nsIDocument *aDocument)
return scx->GetNativeContext();
}
// static
nsresult
nsContentUtils::GetContextAndScope(nsIDocument *aOldDocument,
nsIDocument *aNewDocument, JSContext **aCx,
JSObject **aNewScope)
{
*aCx = nsnull;
*aNewScope = nsnull;
JSObject *newScope = aNewDocument->GetWrapper();
JSObject *global;
if (!newScope) {
nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject();
if (!newSGO || !(global = newSGO->GetGlobalJSObject())) {
return NS_OK;
}
}
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_NOT_INITIALIZED);
JSContext *cx = aOldDocument ? GetContextFromDocument(aOldDocument) : nsnull;
if (!cx) {
cx = GetContextFromDocument(aNewDocument);
if (!cx) {
// No context reachable from the old or new document, use the
// calling context, or the safe context if no caller can be
// found.
sThreadJSContextStack->Peek(&cx);
if (!cx) {
sThreadJSContextStack->GetSafeJSContext(&cx);
if (!cx) {
// No safe context reachable, bail.
NS_WARNING("No context reachable in GetContextAndScopes()!");
return NS_ERROR_NOT_AVAILABLE;
}
}
}
}
if (!newScope && cx) {
jsval v;
nsresult rv = WrapNative(cx, global, aNewDocument, aNewDocument, &v);
NS_ENSURE_SUCCESS(rv, rv);
newScope = JSVAL_TO_OBJECT(v);
}
*aCx = cx;
*aNewScope = newScope;
return NS_OK;
}
//static
void
nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)

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

@ -6004,6 +6004,75 @@ private:
nsCOMPtr<nsIDocument> mOwnerDoc;
};
/**
* Get a scope from aNewDocument. Also get a context through the scope of one
* of the documents, from the stack or the safe context.
*
* @param aOldDocument The document to try to get a context from.
* @param aNewDocument The document to get aNewScope from.
* @param aCx [out] Context gotten through one of the scopes, from the stack
* or the safe context.
* @param aNewScope [out] Scope gotten from aNewDocument.
*/
static nsresult
GetContextAndScope(nsIDocument* aOldDocument, nsIDocument* aNewDocument,
JSContext** aCx, JSObject** aNewScope)
{
MOZ_ASSERT(aOldDocument);
MOZ_ASSERT(aNewDocument);
*aCx = nsnull;
*aNewScope = nsnull;
JSObject* newScope = aNewDocument->GetWrapper();
JSObject* global;
if (!newScope) {
nsIScriptGlobalObject *newSGO = aNewDocument->GetScopeObject();
if (!newSGO || !(global = newSGO->GetGlobalJSObject())) {
return NS_OK;
}
}
JSContext* cx = nsContentUtils::GetContextFromDocument(aOldDocument);
if (!cx) {
cx = nsContentUtils::GetContextFromDocument(aNewDocument);
if (!cx) {
// No context reachable from the old or new document, use the
// calling context, or the safe context if no caller can be
// found.
nsIThreadJSContextStack* stack = nsContentUtils::ThreadJSContextStack();
stack->Peek(&cx);
if (!cx) {
stack->GetSafeJSContext(&cx);
if (!cx) {
// No safe context reachable, bail.
NS_WARNING("No context reachable in GetContextAndScopes()!");
return NS_ERROR_NOT_AVAILABLE;
}
}
}
}
if (!newScope && cx) {
JS::Value v;
nsresult rv = nsContentUtils::WrapNative(cx, global, aNewDocument,
aNewDocument, &v);
NS_ENSURE_SUCCESS(rv, rv);
newScope = JSVAL_TO_OBJECT(v);
}
*aCx = cx;
*aNewScope = newScope;
return NS_OK;
}
NS_IMETHODIMP
nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
{
@ -6102,7 +6171,7 @@ nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
JSContext *cx = nsnull;
JSObject *newScope = nsnull;
if (!sameDocument) {
rv = nsContentUtils::GetContextAndScope(oldDocument, this, &cx, &newScope);
rv = GetContextAndScope(oldDocument, this, &cx, &newScope);
NS_ENSURE_SUCCESS(rv, rv);
}