зеркало из https://github.com/mozilla/pjs.git
Bug 20147. Make sure to correctly scope 'parent' when creating script objects. XUL document's parent is the window; XUL element's parent is the document. r=brendan
This commit is contained in:
Родитель
6fd322ea4b
Коммит
7f0d4111fa
|
@ -1443,8 +1443,12 @@ nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject)
|
|||
nsresult rv = NS_OK;
|
||||
|
||||
if (! mScriptObject) {
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
NS_ASSERTION(mDocument != nsnull, "element has no document");
|
||||
if (! mDocument)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// The actual script object that we create will depend on our
|
||||
// tag...
|
||||
nsresult (*fn)(nsIScriptContext* aContext, nsISupports* aSupports, nsISupports* aParent, void** aReturn);
|
||||
|
||||
if (Tag() == kTreeAtom) {
|
||||
|
@ -1457,25 +1461,13 @@ nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject)
|
|||
fn = NS_NewScriptXULElement;
|
||||
}
|
||||
|
||||
rv = fn(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject);
|
||||
|
||||
NS_RELEASE(global);
|
||||
rv = fn(aContext, (nsIDOMXULElement*) this, mDocument, (void**) &mScriptObject);
|
||||
|
||||
// Ensure that a reference exists to this element
|
||||
if (mDocument) {
|
||||
nsAutoString tag;
|
||||
Tag()->ToString(tag);
|
||||
nsAutoString tag;
|
||||
Tag()->ToString(tag);
|
||||
|
||||
char buf[64];
|
||||
char* p = buf;
|
||||
if (tag.Length() >= PRInt32(sizeof buf))
|
||||
p = (char *)nsAllocator::Alloc(tag.Length() + 1);
|
||||
|
||||
aContext->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
|
||||
|
||||
if (p != buf)
|
||||
nsCRT::free(p);
|
||||
}
|
||||
aContext->AddNamedReference((void*) &mScriptObject, mScriptObject, nsCAutoString(tag));
|
||||
}
|
||||
|
||||
*aScriptObject = mScriptObject;
|
||||
|
|
|
@ -3048,16 +3048,40 @@ nsXULDocument::Finalize(JSContext *aContext)
|
|||
NS_IMETHODIMP
|
||||
nsXULDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
if (! mScriptObject) {
|
||||
// ...we need to instantiate our script object for the first
|
||||
// time.
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptXULDocument(aContext, NS_STATIC_CAST(nsISupports *, NS_STATIC_CAST(nsIDOMXULDocument *, this)), global, (void**)&mScriptObject);
|
||||
// Make sure that we've got our script context owner; this
|
||||
// assertion will fire if we've tried to get the script object
|
||||
// before our scope has been set up.
|
||||
NS_ASSERTION(mScriptContextOwner != nsnull, "no script context owner");
|
||||
if (! mScriptContextOwner)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// Use the global object from our script context owner (the
|
||||
// window) as the parent of our own script object. (Using the
|
||||
// global object from aContext would make our script object
|
||||
// dynamically scoped in the first context that ever tried to
|
||||
// use us!)
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
rv = mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(global != nsnull, "script context owner has no global object");
|
||||
if (! global)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = NS_NewScriptXULDocument(aContext,
|
||||
NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMXULDocument*, this)),
|
||||
global, &mScriptObject);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
*aScriptObject = mScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3048,16 +3048,40 @@ nsXULDocument::Finalize(JSContext *aContext)
|
|||
NS_IMETHODIMP
|
||||
nsXULDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
if (! mScriptObject) {
|
||||
// ...we need to instantiate our script object for the first
|
||||
// time.
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptXULDocument(aContext, NS_STATIC_CAST(nsISupports *, NS_STATIC_CAST(nsIDOMXULDocument *, this)), global, (void**)&mScriptObject);
|
||||
// Make sure that we've got our script context owner; this
|
||||
// assertion will fire if we've tried to get the script object
|
||||
// before our scope has been set up.
|
||||
NS_ASSERTION(mScriptContextOwner != nsnull, "no script context owner");
|
||||
if (! mScriptContextOwner)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// Use the global object from our script context owner (the
|
||||
// window) as the parent of our own script object. (Using the
|
||||
// global object from aContext would make our script object
|
||||
// dynamically scoped in the first context that ever tried to
|
||||
// use us!)
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
rv = mScriptContextOwner->GetScriptGlobalObject(getter_AddRefs(global));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(global != nsnull, "script context owner has no global object");
|
||||
if (! global)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = NS_NewScriptXULDocument(aContext,
|
||||
NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMXULDocument*, this)),
|
||||
global, &mScriptObject);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
*aScriptObject = mScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1443,8 +1443,12 @@ nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject)
|
|||
nsresult rv = NS_OK;
|
||||
|
||||
if (! mScriptObject) {
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
NS_ASSERTION(mDocument != nsnull, "element has no document");
|
||||
if (! mDocument)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// The actual script object that we create will depend on our
|
||||
// tag...
|
||||
nsresult (*fn)(nsIScriptContext* aContext, nsISupports* aSupports, nsISupports* aParent, void** aReturn);
|
||||
|
||||
if (Tag() == kTreeAtom) {
|
||||
|
@ -1457,25 +1461,13 @@ nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject)
|
|||
fn = NS_NewScriptXULElement;
|
||||
}
|
||||
|
||||
rv = fn(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject);
|
||||
|
||||
NS_RELEASE(global);
|
||||
rv = fn(aContext, (nsIDOMXULElement*) this, mDocument, (void**) &mScriptObject);
|
||||
|
||||
// Ensure that a reference exists to this element
|
||||
if (mDocument) {
|
||||
nsAutoString tag;
|
||||
Tag()->ToString(tag);
|
||||
nsAutoString tag;
|
||||
Tag()->ToString(tag);
|
||||
|
||||
char buf[64];
|
||||
char* p = buf;
|
||||
if (tag.Length() >= PRInt32(sizeof buf))
|
||||
p = (char *)nsAllocator::Alloc(tag.Length() + 1);
|
||||
|
||||
aContext->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
|
||||
|
||||
if (p != buf)
|
||||
nsCRT::free(p);
|
||||
}
|
||||
aContext->AddNamedReference((void*) &mScriptObject, mScriptObject, nsCAutoString(tag));
|
||||
}
|
||||
|
||||
*aScriptObject = mScriptObject;
|
||||
|
|
Загрузка…
Ссылка в новой задаче