rv = stack->Peek(&cx);
rv = GetContextFromStack(stack, &cx);
GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset){  aCharset.Truncate();  nsresult rv;  nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));  NS_ENSURE_SUCCESS(rv, rv);  JSContext *cx;  rv = stack->Peek(&cx);  NS_ENSURE_SUCCESS(rv, rv);  if (cx) {    nsCOMPtr<nsIDOMWindow> window =      do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));    NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);    nsCOMPtr<nsIDOMDocument> domDoc;    rv = window->GetDocument(getter_AddRefs(domDoc));    NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));    if (doc) {      aCharset = doc->GetDocumentCharacterSet();    }  }  return NS_OK;}