nsCOMPtr<nsIScriptGlobalObject> sgo; aDocument->GetScriptGlobalObject(getter_AddRefs(sgo));
nsIScriptGlobalObject *sgo = aDocument->GetScriptGlobalObject();
nsresult GetContextFromDocument(nsIDocument *aDocument, JSContext **cx){  *cx = nsnull;  nsCOMPtr<nsIScriptGlobalObject> sgo;  aDocument->GetScriptGlobalObject(getter_AddRefs(sgo));  if (!sgo) {    // No script global, no context.    return NS_OK;  }  nsCOMPtr<nsIScriptContext> scx;  sgo->GetContext(getter_AddRefs(scx));  if (!scx) {    // No context left in the old scope...    return NS_OK;  }  *cx = (JSContext *)scx->GetNativeContext();  return NS_OK;}