nsCOMPtr<nsICanvasRenderingContextInternal> internalctx(do_QueryInterface(mCurrentContext)); if (!internalctx) { mCurrentContext = nsnull; return NS_ERROR_FAILURE; }  rv = internalctx->SetCanvasElement(this);
rv = mCurrentContext->SetCanvasElement(this);
nsHTMLCanvasElement::GetContext(const nsAString& aContextId,                                nsISupports **aContext){  nsresult rv;  if (mCurrentContextId.IsEmpty()) {    nsCString ctxId;    ctxId.Assign(NS_LossyConvertUTF16toASCII(aContextId));    // check that ctxId is clamped to A-Za-z0-9_-    for (PRUint32 i = 0; i < ctxId.Length(); i++) {      if ((ctxId[i] < 'A' || ctxId[i] > 'Z') &&          (ctxId[i] < 'a' || ctxId[i] > 'z') &&          (ctxId[i] < '0' || ctxId[i] > '9') &&          (ctxId[i] != '-') &&          (ctxId[i] != '_'))      {        return NS_ERROR_INVALID_ARG;      }    }    nsCString ctxString("@mozilla.org/content/canvas-rendering-context;1?id=");    ctxString.Append(ctxId);    mCurrentContext = do_CreateInstance(nsPromiseFlatCString(ctxString).get(), &rv);    if (rv == NS_ERROR_OUT_OF_MEMORY)      return NS_ERROR_OUT_OF_MEMORY;    if (NS_FAILED(rv))      return NS_ERROR_INVALID_ARG;    nsCOMPtr<nsICanvasRenderingContextInternal> internalctx(do_QueryInterface(mCurrentContext));    if (!internalctx) {      mCurrentContext = nsnull;      return NS_ERROR_FAILURE;    }    rv = internalctx->SetCanvasElement(this);    NS_ENSURE_SUCCESS(rv, rv);    rv = UpdateImageContainer(PR_TRUE);    NS_ENSURE_SUCCESS(rv, rv);    mCurrentContextId.Assign(aContextId);  } else if (!mCurrentContextId.Equals(aContextId)) {    //XXX eventually allow for more than one active context on a given canvas    return NS_ERROR_INVALID_ARG;  }  NS_ADDREF (*aContext = mCurrentContext);  return NS_OK;}