Checking in the real fix for 34130.

This commit is contained in:
hyatt%netscape.com 2000-04-03 07:13:07 +00:00
Родитель 1a8756d781
Коммит bcab583ed6
4 изменённых файлов: 68 добавлений и 44 удалений

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

@ -333,31 +333,29 @@ nsXBLBinding::nsXBLBinding(void)
} }
} }
/**
* Removes a root inadvertently left over.
* This is really an error condition, but I've written
* this to prevent the JS GC from asserting.
*/
static nsresult removeRoot(void* aSlot)
{
const char kJSRuntimeServiceProgID[] = "nsJSRuntimeService";
nsresult rv;
NS_WITH_SERVICE(nsIJSRuntimeService, runtimeService, kJSRuntimeServiceProgID, &rv);
if (NS_FAILED(rv)) return rv;
JSRuntime* rt;
rv = runtimeService->GetRuntime(&rt);
if (NS_FAILED(rv)) return rv;
return (JS_RemoveRootRT(rt, aSlot) ? NS_OK : NS_ERROR_FAILURE);
}
// Error code that ensures the binding clears
// out its script object, even in cases where it should
// have done so earlier.
static nsresult RemoveRoot(void* aSlot)
{
const char kJSRuntimeServiceProgID[] = "nsJSRuntimeService";
nsresult rv;
NS_WITH_SERVICE(nsIJSRuntimeService, runtimeService, kJSRuntimeServiceProgID, &rv);
if (NS_FAILED(rv)) return rv;
JSRuntime* rt;
rv = runtimeService->GetRuntime(&rt);
if (NS_FAILED(rv)) return rv;
return (JS_RemoveRootRT(rt, aSlot) ? NS_OK : NS_ERROR_FAILURE);
}
nsXBLBinding::~nsXBLBinding(void) nsXBLBinding::~nsXBLBinding(void)
{ {
NS_ASSERTION(!mScriptObject, "XBL binding hasn't properly cleared its script object out.");
if (mScriptObject) { if (mScriptObject) {
removeRoot(&mScriptObject); RemoveRoot(&mScriptObject);
mScriptObject = nsnull; mScriptObject = nsnull;
} }
delete mAttributeTable; delete mAttributeTable;

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

@ -341,6 +341,20 @@ nsXBLService::FlushBindings(nsIContent* aContent)
if (!bindable) if (!bindable)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
// Get the original binding.
nsCOMPtr<nsIXBLBinding> binding;
bindable->GetBinding(getter_AddRefs(binding));
if (binding) {
// Clear out the script references.
nsCOMPtr<nsIDocument> document;
aContent->GetDocument(*getter_AddRefs(document));
nsCOMPtr<nsIScriptGlobalObject> global;
document->GetScriptGlobalObject(getter_AddRefs(global));
nsCOMPtr<nsIScriptContext> context;
global->GetContext(getter_AddRefs(context));
binding->RemoveScriptReferences(context);
}
bindable->SetBinding(nsnull); // Flush old bindings bindable->SetBinding(nsnull); // Flush old bindings
return NS_OK; return NS_OK;
} }

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

@ -333,31 +333,29 @@ nsXBLBinding::nsXBLBinding(void)
} }
} }
/**
* Removes a root inadvertently left over.
* This is really an error condition, but I've written
* this to prevent the JS GC from asserting.
*/
static nsresult removeRoot(void* aSlot)
{
const char kJSRuntimeServiceProgID[] = "nsJSRuntimeService";
nsresult rv;
NS_WITH_SERVICE(nsIJSRuntimeService, runtimeService, kJSRuntimeServiceProgID, &rv);
if (NS_FAILED(rv)) return rv;
JSRuntime* rt;
rv = runtimeService->GetRuntime(&rt);
if (NS_FAILED(rv)) return rv;
return (JS_RemoveRootRT(rt, aSlot) ? NS_OK : NS_ERROR_FAILURE);
}
// Error code that ensures the binding clears
// out its script object, even in cases where it should
// have done so earlier.
static nsresult RemoveRoot(void* aSlot)
{
const char kJSRuntimeServiceProgID[] = "nsJSRuntimeService";
nsresult rv;
NS_WITH_SERVICE(nsIJSRuntimeService, runtimeService, kJSRuntimeServiceProgID, &rv);
if (NS_FAILED(rv)) return rv;
JSRuntime* rt;
rv = runtimeService->GetRuntime(&rt);
if (NS_FAILED(rv)) return rv;
return (JS_RemoveRootRT(rt, aSlot) ? NS_OK : NS_ERROR_FAILURE);
}
nsXBLBinding::~nsXBLBinding(void) nsXBLBinding::~nsXBLBinding(void)
{ {
NS_ASSERTION(!mScriptObject, "XBL binding hasn't properly cleared its script object out.");
if (mScriptObject) { if (mScriptObject) {
removeRoot(&mScriptObject); RemoveRoot(&mScriptObject);
mScriptObject = nsnull; mScriptObject = nsnull;
} }
delete mAttributeTable; delete mAttributeTable;

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

@ -341,6 +341,20 @@ nsXBLService::FlushBindings(nsIContent* aContent)
if (!bindable) if (!bindable)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
// Get the original binding.
nsCOMPtr<nsIXBLBinding> binding;
bindable->GetBinding(getter_AddRefs(binding));
if (binding) {
// Clear out the script references.
nsCOMPtr<nsIDocument> document;
aContent->GetDocument(*getter_AddRefs(document));
nsCOMPtr<nsIScriptGlobalObject> global;
document->GetScriptGlobalObject(getter_AddRefs(global));
nsCOMPtr<nsIScriptContext> context;
global->GetContext(getter_AddRefs(context));
binding->RemoveScriptReferences(context);
}
bindable->SetBinding(nsnull); // Flush old bindings bindable->SetBinding(nsnull); // Flush old bindings
return NS_OK; return NS_OK;
} }