nsAutoString name;  JSString *jsstring = JS_ValueToString(cx, id); if (nsnull != jsstring) { name.SetString(JS_GetStringChars(jsstring)); } else { name.SetString(""); }
nsresult result = NS_OK;
GetHTMLDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp){  nsIDOMHTMLDocument *a = (nsIDOMHTMLDocument*)nsJSUtils::nsGetNativeThis(cx, obj);  // If there's no private data, this must be the prototype, so ignore  if (nsnull == a) {    return JS_TRUE;  }  PRBool checkNamedItem = PR_TRUE;  nsresult rv = NS_OK;  if (JSVAL_IS_INT(id)) {    nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);    if (!secMan)        return PR_FALSE;    checkNamedItem = PR_FALSE;    switch(JSVAL_TO_INT(id)) {      case HTMLDOCUMENT_TITLE:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_TITLE, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          rv = a->GetTitle(prop);          if (NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);          }        }        break;      }      case HTMLDOCUMENT_REFERRER:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_REFERRER, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          rv = a->GetReferrer(prop);          if (NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);          }        }        break;      }      case HTMLDOCUMENT_DOMAIN:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_DOMAIN, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          rv = a->GetDomain(prop);          if (NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);          }        }        break;      }      case HTMLDOCUMENT_URL:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_URL, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          rv = a->GetURL(prop);          if (NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);          }        }        break;      }      case HTMLDOCUMENT_BODY:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_BODY, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLElement* prop;          rv = a->GetBody(&prop);          if (NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);          }        }        break;      }      case HTMLDOCUMENT_IMAGES:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_IMAGES, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLCollection* prop;          rv = a->GetImages(&prop);          if (NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);          }        }        break;      }      case HTMLDOCUMENT_APPLETS:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_APPLETS, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLCollection* prop;          rv = a->GetApplets(&prop);          if (NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);          }        }        break;      }      case HTMLDOCUMENT_LINKS:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_LINKS, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLCollection* prop;          rv = a->GetLinks(&prop);          if (NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);          }        }        break;      }      case HTMLDOCUMENT_FORMS:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_FORMS, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLCollection* prop;          rv = a->GetForms(&prop);          if (NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);          }        }        break;      }      case HTMLDOCUMENT_ANCHORS:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_ANCHORS, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLCollection* prop;          rv = a->GetAnchors(&prop);          if (NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);          }        }        break;      }      case HTMLDOCUMENT_COOKIE:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_HTMLDOCUMENT_COOKIE, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          rv = a->GetCookie(prop);          if (NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);          }        }        break;      }      case NSHTMLDOCUMENT_ALINKCOLOR:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_ALINKCOLOR, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetAlinkColor(prop);            if(NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      case NSHTMLDOCUMENT_LINKCOLOR:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_LINKCOLOR, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetLinkColor(prop);            if(NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      case NSHTMLDOCUMENT_VLINKCOLOR:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_VLINKCOLOR, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetVlinkColor(prop);            if(NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      case NSHTMLDOCUMENT_BGCOLOR:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_BGCOLOR, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetBgColor(prop);            if(NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      case NSHTMLDOCUMENT_FGCOLOR:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_FGCOLOR, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetFgColor(prop);            if(NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      case NSHTMLDOCUMENT_LASTMODIFIED:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_LASTMODIFIED, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsAutoString prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetLastModified(prop);            if(NS_SUCCEEDED(rv)) {            nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      case NSHTMLDOCUMENT_EMBEDS:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_EMBEDS, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLCollection* prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetEmbeds(&prop);            if(NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      case NSHTMLDOCUMENT_PLUGINS:      {        rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSHTMLDOCUMENT_PLUGINS, PR_FALSE);        if (NS_SUCCEEDED(rv)) {          nsIDOMHTMLCollection* prop;          nsIDOMNSHTMLDocument* b;          if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {            rv = b->GetPlugins(&prop);            if(NS_SUCCEEDED(rv)) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);            }            NS_RELEASE(b);          }          else {            rv = NS_ERROR_DOM_WRONG_TYPE_ERR;          }        }        break;      }      default:        checkNamedItem = PR_TRUE;    }  }  if (checkNamedItem) {    nsIDOMElement* prop;    nsIDOMNSHTMLDocument* b;    nsAutoString name;    JSString *jsstring = JS_ValueToString(cx, id);    if (nsnull != jsstring) {      name.SetString(JS_GetStringChars(jsstring));    }    else {      name.SetString("");    }    if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {      nsresult result = NS_OK;      result = b->NamedItem(name, &prop);      if (NS_SUCCEEDED(result)) {        NS_RELEASE(b);        if (NULL != prop) {            // get the js object            nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);        }        else {          return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);        }      }      else {        NS_RELEASE(b);        return nsJSUtils::nsReportError(cx, obj, result);      }    }    else {      return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);    }  }  else {    return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);  }  if (NS_FAILED(rv))      return nsJSUtils::nsReportError(cx, obj, rv);  return PR_TRUE;}