зеркало из https://github.com/mozilla/gecko-dev.git
Bug 738760 - Move nsContentUtils::GetContextAndScope into nsDocument.cpp; r=sicking
This commit is contained in:
Родитель
3ca758f544
Коммит
03768e8823
|
@ -250,20 +250,6 @@ public:
|
||||||
*/
|
*/
|
||||||
static JSContext* GetContextFromDocument(nsIDocument *aDocument);
|
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
|
* 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.
|
* 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();
|
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
|
//static
|
||||||
void
|
void
|
||||||
nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)
|
nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)
|
||||||
|
|
|
@ -6004,6 +6004,75 @@ private:
|
||||||
nsCOMPtr<nsIDocument> mOwnerDoc;
|
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
|
NS_IMETHODIMP
|
||||||
nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
|
nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
|
||||||
{
|
{
|
||||||
|
@ -6102,7 +6171,7 @@ nsDocument::AdoptNode(nsIDOMNode *aAdoptedNode, nsIDOMNode **aResult)
|
||||||
JSContext *cx = nsnull;
|
JSContext *cx = nsnull;
|
||||||
JSObject *newScope = nsnull;
|
JSObject *newScope = nsnull;
|
||||||
if (!sameDocument) {
|
if (!sameDocument) {
|
||||||
rv = nsContentUtils::GetContextAndScope(oldDocument, this, &cx, &newScope);
|
rv = GetContextAndScope(oldDocument, this, &cx, &newScope);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче