NS_IMETHODIMP
nsDOMExceptionProvider::GetException(nsresult result,
                                     nsIException *aDefaultException,
                                     nsIException **_retval)
{
  if (!NS_IsMainThread()) {
    return NS_ERROR_NOT_IMPLEMENTED;
  }

  switch (NS_ERROR_GET_MODULE(result))
  {
    case NS_ERROR_MODULE_SVG:
      return NS_NewSVGException(result, aDefaultException, _retval);
    case NS_ERROR_MODULE_DOM_XPATH:
      return NS_NewXPathException(result, aDefaultException, _retval);
    case NS_ERROR_MODULE_XPCONNECT:
      return CreateXPConnectException(result, aDefaultException, _retval);
    default:
      MOZ_ASSERT(NS_ERROR_GET_MODULE(result) == NS_ERROR_MODULE_DOM ||
          NS_ERROR_GET_MODULE(result) == NS_ERROR_MODULE_DOM_FILE ||
          NS_ERROR_GET_MODULE(result) == NS_ERROR_MODULE_DOM_INDEXEDDB,
          "Trying to create an exception for the wrong error module.");
      return NS_NewDOMException(result, aDefaultException, _retval);
  }
  NS_NOTREACHED("Not reached");
  return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsDOMExceptionProvider::GetException(nsresult result,
                                     nsIException *aDefaultException,
                                     nsIException **_retval)
{
  if (!NS_IsMainThread()) {
    return NS_ERROR_NOT_IMPLEMENTED;
  }

  switch (NS_ERROR_GET_MODULE(result))
  {
    case NS_ERROR_MODULE_SVG:
      return NS_NewSVGException(result, aDefaultException, _retval);
    case NS_ERROR_MODULE_DOM_XPATH:
      return NS_NewXPathException(result, aDefaultException, _retval);
    case NS_ERROR_MODULE_XPCONNECT:
      return CreateXPConnectException(result, aDefaultException, _retval);
    case NS_ERROR_MODULE_DOM_FILE:
      return NS_NewFileException(result, aDefaultException, _retval);
    case NS_ERROR_MODULE_DOM_INDEXEDDB:
      return NS_NewIDBDatabaseException(result, aDefaultException, _retval);
    default:
      return NS_NewDOMException(result, aDefaultException, _retval);
  }
  NS_NOTREACHED("Not reached");
  return NS_ERROR_UNEXPECTED;
}
/*
 * Class:     org_mozilla_dom_NodeImpl
 * Method:    setPrefix
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_org_mozilla_dom_NodeImpl_nativeSetPrefix
  (JNIEnv *env, jobject jthis, jstring jprefix)
{
  nsIDOMNode* node = (nsIDOMNode*) 
    env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
  if (!node || !jprefix) {
    JavaDOMGlobals::ThrowException(env,
      "Node.setPrefix: NULL pointer");
    return;
  }

  nsString* prefix = JavaDOMGlobals::GetUnicode(env, jprefix);
  if (!prefix)
    return;

  nsresult rv = node->SetPrefix(*prefix);
  nsMemory::Free(prefix);

  if (NS_FAILED(rv)) {
    JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
    if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
	(rv == NS_ERROR_DOM_INVALID_CHARACTER_ERR ||
	 rv == NS_ERROR_DOM_NAMESPACE_ERR ||
	 rv == NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR)) {
	exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
    }
    JavaDOMGlobals::ThrowException(env,
      "Node.setPrefix: failed", rv, exceptionType);
  }
}
示例#4
0
NS_IMETHODIMP
NSSErrorsService::GetErrorMessage(nsresult aXPCOMErrorCode, nsAString &aErrorMessage)
{
  if (NS_ERROR_GET_MODULE(aXPCOMErrorCode) != NS_ERROR_MODULE_SECURITY ||
      NS_ERROR_GET_SEVERITY(aXPCOMErrorCode) != NS_ERROR_SEVERITY_ERROR) {
    return NS_ERROR_FAILURE;
  }
  
  int32_t aNSPRCode = -1 * NS_ERROR_GET_CODE(aXPCOMErrorCode);

  if (!mozilla::psm::IsNSSErrorCode(aNSPRCode)) {
    return NS_ERROR_FAILURE;
  }

  nsCOMPtr<nsIStringBundle> theBundle = mPIPNSSBundle;
  const char *id_str = nsNSSErrors::getOverrideErrorStringName(aNSPRCode);

  if (!id_str) {
    id_str = nsNSSErrors::getDefaultErrorStringName(aNSPRCode);
    theBundle = mNSSErrorsBundle;
  }

  if (!id_str || !theBundle) {
    return NS_ERROR_FAILURE;
  }

  nsAutoString msg;
  nsresult rv =
    theBundle->GetStringFromName(NS_ConvertASCIItoUTF16(id_str).get(),
                                 getter_Copies(msg));
  if (NS_SUCCEEDED(rv)) {
    aErrorMessage = msg;
  }
  return rv;
}
示例#5
0
nsresult
nsExceptionService::DoGetExceptionFromProvider(nsresult errCode, 
                                               nsIException * defaultException,
                                               nsIException **_exc)
{
    // Check for an existing exception
    nsresult nr = GetCurrentException(_exc);
    if (NS_SUCCEEDED(nr) && *_exc) {
        (*_exc)->GetResult(&nr);
        // If it matches our result then use it
        if (nr == errCode)
            return NS_OK;
        NS_RELEASE(*_exc);
    }
    nsProviderKey key(NS_ERROR_GET_MODULE(errCode));
    nsCOMPtr<nsIExceptionProvider> provider =
        dont_AddRef((nsIExceptionProvider *)mProviders.Get(&key));

    // No provider so we'll return the default exception
    if (!provider) {
        *_exc = defaultException;
        NS_IF_ADDREF(*_exc);
        return NS_OK;
    }

    return provider->GetException(errCode, defaultException, _exc);
}
示例#6
0
bool
Throw(JSContext* aCx, nsresult aRv, const char* aMessage)
{
  if (JS_IsExceptionPending(aCx)) {
    // Don't clobber the existing exception.
    return false;
  }

  CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get();
  nsCOMPtr<nsIException> existingException = runtime->GetPendingException();
  if (existingException) {
    nsresult nr;
    if (NS_SUCCEEDED(existingException->GetResult(&nr)) && 
        aRv == nr) {
      // Reuse the existing exception.

      // Clear pending exception
      runtime->SetPendingException(nullptr);

      if (!ThrowExceptionObject(aCx, existingException)) {
        // If we weren't able to throw an exception we're
        // most likely out of memory
        JS_ReportOutOfMemory(aCx);
      }
      return false;
    }
  }

  nsRefPtr<Exception> finalException;

  // Do we use DOM exceptions for this error code?
  switch (NS_ERROR_GET_MODULE(aRv)) {
  case NS_ERROR_MODULE_DOM:
  case NS_ERROR_MODULE_SVG:
  case NS_ERROR_MODULE_DOM_XPATH:
  case NS_ERROR_MODULE_DOM_INDEXEDDB:
  case NS_ERROR_MODULE_DOM_FILEHANDLE:
    finalException = DOMException::Create(aRv);
    break;

  default:
      break;
  }

  // If not, use the default.
  if (!finalException) {
    // aMessage can be null.
    finalException = new Exception(nsCString(aMessage), aRv,
                                   EmptyCString(), nullptr, nullptr);
  }

  MOZ_ASSERT(finalException);
  if (!ThrowExceptionObject(aCx, finalException)) {
    // If we weren't able to throw an exception we're
    // most likely out of memory
    JS_ReportOutOfMemory(aCx);
  }

  return false;
}
NS_IMETHODIMP
nsDOMExceptionProvider::GetException(nsresult result,
                                     nsIException *aDefaultException,
                                     nsIException **_retval)
{
  if (!NS_IsMainThread()) {
    return NS_ERROR_NOT_IMPLEMENTED;
  }

  switch (NS_ERROR_GET_MODULE(result))
  {
    case NS_ERROR_MODULE_DOM:
    case NS_ERROR_MODULE_SVG:
    case NS_ERROR_MODULE_DOM_XPATH:
    case NS_ERROR_MODULE_DOM_FILE:
    case NS_ERROR_MODULE_DOM_INDEXEDDB:
    case NS_ERROR_MODULE_DOM_FILEHANDLE:
      return NS_NewDOMException(result, aDefaultException, _retval);
    default:
      NS_WARNING("Trying to create an exception for the wrong error module.");
      return NS_ERROR_FAILURE;
  }
  NS_NOTREACHED("Not reached");
  return NS_ERROR_UNEXPECTED;
}
示例#8
0
already_AddRefed<Exception>
CreateException(JSContext* aCx, nsresult aRv, const nsACString& aMessage)
{
  // Do we use DOM exceptions for this error code?
  switch (NS_ERROR_GET_MODULE(aRv)) {
  case NS_ERROR_MODULE_DOM:
  case NS_ERROR_MODULE_SVG:
  case NS_ERROR_MODULE_DOM_XPATH:
  case NS_ERROR_MODULE_DOM_INDEXEDDB:
  case NS_ERROR_MODULE_DOM_FILEHANDLE:
  case NS_ERROR_MODULE_DOM_BLUETOOTH:
  case NS_ERROR_MODULE_DOM_ANIM:
  case NS_ERROR_MODULE_DOM_PUSH:
    if (aMessage.IsEmpty()) {
      return DOMException::Create(aRv);
    }
    return DOMException::Create(aRv, aMessage);
  default:
    break;
  }

  // If not, use the default.
  RefPtr<Exception> exception =
    new Exception(aMessage, aRv, EmptyCString(), nullptr, nullptr);
  return exception.forget();
}
/*
 * Class:     org_mozilla_dom_NodeImpl
 * Method:    removeChild
 * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node;
 */
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_nativeRemoveChild
  (JNIEnv *env, jobject jthis, jobject joldChild)
{
  nsIDOMNode* node = (nsIDOMNode*) 
    env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
  if (!node || !joldChild) {
    JavaDOMGlobals::ThrowException(env,
      "Node.removeChild: NULL pointer");
    return NULL;
  }

  nsIDOMNode* oldChild = (nsIDOMNode*) 
      env->GetLongField(joldChild, JavaDOMGlobals::nodePtrFID);
  if (!oldChild) {
    JavaDOMGlobals::ThrowException(env,
        "Node.removeChild: NULL oldChild pointer");
    return NULL;
  }

  nsIDOMNode* ret = nsnull;
  nsresult rv = node->RemoveChild(oldChild, &ret);
  if (NS_FAILED(rv) || !ret) {
    JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
    if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
        (rv == NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR ||
         rv == NS_ERROR_DOM_NOT_FOUND_ERR)) {
      exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
    }
    JavaDOMGlobals::ThrowException(env,
      "Node.removeChild: failed", rv, exceptionType);
    return NULL;
  }

  return JavaDOMGlobals::CreateNodeSubtype(env, ret);
}
/*
 * Class:     org_mozilla_dom_DocumentImpl
 * Method:    createProcessingInstruction
 * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/w3c/dom/ProcessingInstruction;
 */
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_nativeCreateProcessingInstruction
  (JNIEnv *env, jobject jthis, jstring jtarget, jstring jdata)
{
  nsIDOMDocument* doc = (nsIDOMDocument*) 
    env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
  if (!doc || !jtarget || !jdata) {
    JavaDOMGlobals::ThrowException(env,
      "Document.createProcessingInstruction: NULL pointer");
    return NULL;
  }

  nsIDOMProcessingInstruction* ret = nsnull;
  
  nsString* target = JavaDOMGlobals::GetUnicode(env, jtarget);
  if (!target)
    return NULL;

  nsString* data = JavaDOMGlobals::GetUnicode(env, jdata);
  if (!data) {
    nsMemory::Free(target);
    return NULL;
  }

  nsresult rv = doc->CreateProcessingInstruction(*target, *data, &ret);
  nsMemory::Free(target);
  nsMemory::Free(data);

  if (NS_FAILED(rv)) {
    JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
    if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
        (rv == NS_ERROR_DOM_NOT_SUPPORTED_ERR ||
         rv == NS_ERROR_DOM_INVALID_CHARACTER_ERR)) {
      exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
    }
    JavaDOMGlobals::ThrowException(env,
      "Document.createProcessingInstruction failed", rv, exceptionType);
    return NULL;
  }

  jobject jret = env->AllocObject(JavaDOMGlobals::processingInstructionClass);
  if (!jret) {
    JavaDOMGlobals::ThrowException(env,
      "Document.createProcessingInstruction: failed to allocate object");
    return NULL;
  }

  env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret);
  if (env->ExceptionOccurred()) {
    JavaDOMGlobals::ThrowException(env,
      "Document.createProcessingInstruction: failed to set node ptr");
    return NULL;
  }

  ret->AddRef();
  return jret;
}
NS_IMETHODIMP
nsDOMException::GetCode(PRUint16* aCode)
{
  NS_ENSURE_ARG_POINTER(aCode);
  *aCode = mCode;

  // Warn only when the code was changed (IndexedDB or File API)
  // or the code is useless (zero)
  if (NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM_INDEXEDDB ||
      NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM_FILE ||
      !mCode) {
    nsCOMPtr<nsIDocument> doc =
      do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
    if (doc) {
      doc->WarnOnceAbout(nsIDocument::eDOMExceptionCode);
    }
  }

  return NS_OK;
}
// caller must return from JNI immediately after calling this function
void JavaDOMGlobals::ThrowException(JNIEnv *env,
                                    const char * message,
                                    nsresult rv,
                                    ExceptionType exceptionType) {

    jthrowable newException = NULL;

    if (exceptionType == EXCEPTION_DOM) {
        PR_LOG(log, PR_LOG_ERROR,
               ("JavaDOMGlobals::ThrowException: (%x) %s: %s\n",
                NS_ERROR_GET_CODE(rv),
                message ? message : "",
                DOM_EXCEPTION_MESSAGE[NS_ERROR_GET_CODE(rv)]));

        jstring jmessage =
            env->NewStringUTF(DOM_EXCEPTION_MESSAGE[NS_ERROR_GET_CODE(rv)]);

        newException =
            (jthrowable)env->NewObject(domExceptionClass,
                                       domExceptionInitMID,
                                       NS_ERROR_GET_CODE(rv),
                                       jmessage);
    } else {
        char buffer[256];
        const char* msg = message;
        if (rv != NS_OK) {
            sprintf(buffer,
                    "(%x.%x) %s",
                    NS_ERROR_GET_MODULE(rv),
                    NS_ERROR_GET_CODE(rv),
                    message ? message : "");
            msg = buffer;
        }

        PR_LOG(log, PR_LOG_ERROR,
               ("JavaDOMGlobals::ThrowException: %s\n", msg));

        jstring jmessage = env->NewStringUTF(msg);

        newException =
            (jthrowable)env->NewObject(runtimeExceptionClass,
                                       runtimeExceptionInitMID,
                                       jmessage);

    }

    if (newException != NULL) {
        env->Throw(newException);
    }

    // an exception is thrown in any case
}
示例#13
0
void
IDBRequest::SetError(nsresult aRv)
{
  AssertIsOnOwningThread();
  MOZ_ASSERT(NS_FAILED(aRv));
  MOZ_ASSERT(NS_ERROR_GET_MODULE(aRv) == NS_ERROR_MODULE_DOM_INDEXEDDB);
  MOZ_ASSERT(!mError);

  mHaveResultOrErrorCode = true;
  mError = new DOMError(GetOwner(), aRv);
  mErrorCode = aRv;

  mResultVal.setUndefined();
}
示例#14
0
PyObject *PyXPCOM_BuildErrorMessage(nsresult r)
{
    char msg[512];
    bool gotMsg = false;

    if (!gotMsg)
    {
        nsresult rc;
        nsCOMPtr <nsIExceptionService> es;
        es = do_GetService (NS_EXCEPTIONSERVICE_CONTRACTID, &rc);
        if (NS_SUCCEEDED (rc))
        {
            nsCOMPtr <nsIExceptionManager> em;
            rc = es->GetCurrentExceptionManager (getter_AddRefs (em));
            if (NS_SUCCEEDED (rc))
            {
                nsCOMPtr <nsIException> ex;
                rc = em->GetExceptionFromProvider(r, NULL, getter_AddRefs (ex));
                if  (NS_SUCCEEDED (rc) && ex)
                {
                    nsXPIDLCString emsg;
                    ex->GetMessage(getter_Copies(emsg));
                    PR_snprintf(msg, sizeof(msg), "%s",
                                emsg.get());
                    gotMsg = true;
                }
            }
        }
    }

    if (!gotMsg)
    {
        const RTCOMERRMSG* pMsg = RTErrCOMGet(r);
        if (strncmp(pMsg->pszMsgFull, "Unknown", 7) != 0)
        {
            PR_snprintf(msg, sizeof(msg), "%s (%s)",
                        pMsg->pszMsgFull, pMsg->pszDefine);
            gotMsg = true;
        }
    }

    if (!gotMsg)
    {
        PR_snprintf(msg, sizeof(msg), "Error 0x%x in module 0x%x",
                    NS_ERROR_GET_CODE(r), NS_ERROR_GET_MODULE(r));
    }
    PyObject *evalue = Py_BuildValue("is", r, msg);
    return evalue;
}
示例#15
0
void
FileSystemTaskBase::SetError(const nsresult& aErrorValue)
{
  uint16_t module = NS_ERROR_GET_MODULE(aErrorValue);
  if (module == NS_ERROR_MODULE_DOM_FILESYSTEM ||
      module == NS_ERROR_MODULE_DOM_FILE ||
      module == NS_ERROR_MODULE_DOM) {
    mErrorValue = aErrorValue;
    return;
  }

  switch (aErrorValue) {
    case NS_OK:
      mErrorValue = NS_OK;
      return;

    case NS_ERROR_FILE_INVALID_PATH:
    case NS_ERROR_FILE_UNRECOGNIZED_PATH:
      mErrorValue = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
      return;

    case NS_ERROR_FILE_DESTINATION_NOT_DIR:
      mErrorValue = NS_ERROR_DOM_FILESYSTEM_INVALID_MODIFICATION_ERR;
      return;

    case NS_ERROR_FILE_ACCESS_DENIED:
    case NS_ERROR_FILE_DIR_NOT_EMPTY:
      mErrorValue = NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR;
      return;

    case NS_ERROR_FILE_TARGET_DOES_NOT_EXIST:
    case NS_ERROR_NOT_AVAILABLE:
      mErrorValue = NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
      return;

    case NS_ERROR_FILE_ALREADY_EXISTS:
      mErrorValue = NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR;
      return;

    case NS_ERROR_FILE_NOT_DIRECTORY:
      mErrorValue = NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR;
      return;

    case NS_ERROR_UNEXPECTED:
    default:
      mErrorValue = NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR;
      return;
  }
}
/*
 * Class:     org_mozilla_dom_DocumentImpl
 * Method:    createEntityReference
 * Signature: (Ljava/lang/String;)Lorg/w3c/dom/EntityReference;
 */
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DocumentImpl_nativeCreateEntityReference
  (JNIEnv *env, jobject jthis, jstring jname)
{
  nsIDOMDocument* doc = (nsIDOMDocument*) 
    env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
  if (!doc || !jname) {
    JavaDOMGlobals::ThrowException(env,
      "Document.createEntityReference: NULL pointer");
    return NULL;
  }

  nsIDOMEntityReference* ret = nsnull;
  nsString* name = JavaDOMGlobals::GetUnicode(env, jname);
  if (!name)
    return NULL;

  nsresult rv = doc->CreateEntityReference(*name, &ret);  
  nsMemory::Free(name);

  if (NS_FAILED(rv) || ret == nsnull) {
    JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
    if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
        (rv == NS_ERROR_DOM_INVALID_CHARACTER_ERR ||
         rv == NS_ERROR_DOM_NOT_SUPPORTED_ERR)) {
      exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
    }
    JavaDOMGlobals::ThrowException(env,
      "Document.createEntityReference: failed", rv, exceptionType);
    return NULL;
  }

  jobject jret = env->AllocObject(JavaDOMGlobals::entityReferenceClass);
  if (!jret) {
    JavaDOMGlobals::ThrowException(env,
      "Document.createEntityReference: failed to allocate object");
    return NULL;
  }

  env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret);
  if (env->ExceptionOccurred()) {
    JavaDOMGlobals::ThrowException(env,
      "Document.createEntityReference: failed to set node ptr");
    return NULL;
  }

  ret->AddRef();
  return jret;
}
/*
 * Class:     org_mozilla_dom_NodeImpl
 * Method:    insertBefore
 * Signature: (Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node;
 */
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NodeImpl_nativeInsertBefore
  (JNIEnv *env, jobject jthis, jobject jnewChild, jobject jrefChild)
{
  nsIDOMNode* node = (nsIDOMNode*) 
    env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
  if (!node || !jnewChild) {
    JavaDOMGlobals::ThrowException(env,
      "Node.insertBefore: NULL pointer");
    return NULL;
  }

  nsIDOMNode* newChild = (nsIDOMNode*) 
      env->GetLongField(jnewChild, JavaDOMGlobals::nodePtrFID);
  if (!newChild) {
    JavaDOMGlobals::ThrowException(env,
        "Node.insertBefore: NULL newChild pointer");
    return NULL;
  }

  nsIDOMNode* refChild = NULL;
  if (jrefChild) {
    refChild = (nsIDOMNode*) 
        env->GetLongField(jrefChild, JavaDOMGlobals::nodePtrFID);
    if (!refChild) {
      JavaDOMGlobals::ThrowException(env,
	"Node.insertBefore: NULL refChild pointer");
      return NULL;
    }
  }

  nsIDOMNode* ret = nsnull;
  nsresult rv = node->InsertBefore(newChild, refChild, &ret);
  if (NS_FAILED(rv) || !ret) {
    JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
    if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
        (rv == NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR ||
         rv == NS_ERROR_DOM_WRONG_DOCUMENT_ERR ||
         rv == NS_ERROR_DOM_NOT_FOUND_ERR ||
         rv == NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)) {
        exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
    }
    JavaDOMGlobals::ThrowException(env,
      "Node.insertBefore: failed", rv, exceptionType);
    return NULL;
  }

  return JavaDOMGlobals::CreateNodeSubtype(env, ret);
}
void
txStylesheetCompiler::cancel(nsresult aError, const PRUnichar *aErrorText,
                             const PRUnichar *aParam)
{
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
           ("Compiler::cancel: %s, module: %d, code %d\n",
            NS_LossyConvertUTF16toASCII(mStylesheetURI).get(),
            NS_ERROR_GET_MODULE(aError),
            NS_ERROR_GET_CODE(aError)));
    if (NS_SUCCEEDED(mStatus)) {
        mStatus = aError;
    }

    if (mObserver) {
        mObserver->onDoneCompiling(this, mStatus, aErrorText, aParam);
        // This will ensure that we don't call onDoneCompiling twice. Also
        // ensures that we don't keep the observer alive longer then necessary.
        mObserver = nsnull;
    }
}
示例#19
0
void
IDBRequest::DispatchNonTransactionError(nsresult aErrorCode)
{
  AssertIsOnOwningThread();
  MOZ_ASSERT(NS_FAILED(aErrorCode));
  MOZ_ASSERT(NS_ERROR_GET_MODULE(aErrorCode) == NS_ERROR_MODULE_DOM_INDEXEDDB);

  SetError(aErrorCode);

  // Make an error event and fire it at the target.
  nsCOMPtr<nsIDOMEvent> event =
    CreateGenericEvent(this,
                       nsDependentString(kErrorEventType),
                       eDoesBubble,
                       eCancelable);
  MOZ_ASSERT(event);

  bool ignored;
  if (NS_FAILED(DispatchEvent(event, &ignored))) {
    NS_WARNING("Failed to dispatch event!");
  }
}
示例#20
0
already_AddRefed<Exception>
CreateException(JSContext* aCx, nsresult aRv, const char* aMessage)
{
  // Do we use DOM exceptions for this error code?
  switch (NS_ERROR_GET_MODULE(aRv)) {
  case NS_ERROR_MODULE_DOM:
  case NS_ERROR_MODULE_SVG:
  case NS_ERROR_MODULE_DOM_XPATH:
  case NS_ERROR_MODULE_DOM_INDEXEDDB:
  case NS_ERROR_MODULE_DOM_FILEHANDLE:
    return DOMException::Create(aRv);
  default:
    break;
  }

  // If not, use the default.
  // aMessage can be null, so we can't use nsDependentCString on it.
  nsRefPtr<Exception> exception =
    new Exception(nsCString(aMessage), aRv,
                  EmptyCString(), nullptr, nullptr);
  return exception.forget();
}
/*
 * Class:     org_mozilla_dom_NamedNodeMapImpl
 * Method:    setNamedItem
 * Signature: (Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node;
 */
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_NamedNodeMapImpl_nativeSetNamedItem
  (JNIEnv *env, jobject jthis, jobject jarg)
{
  nsIDOMNamedNodeMap* map = (nsIDOMNamedNodeMap*) 
    env->GetLongField(jthis, JavaDOMGlobals::namedNodeMapPtrFID);
  if (!map || !jarg) {
    JavaDOMGlobals::ThrowException(env,
      "NodeMap.setNamedItem: NULL pointer");
    return NULL;
  }
  
  nsIDOMNode* arg = (nsIDOMNode*)
    env->GetLongField(jarg, JavaDOMGlobals::namedNodeMapPtrFID);
  if (!arg) {
    JavaDOMGlobals::ThrowException(env,
      "NodeMap.setNamedItem: NULL item pointer");
    return NULL;
  }

  nsIDOMNode* node = nsnull;
  nsresult rv = map->SetNamedItem(arg, &node);
  if (NS_FAILED(rv)) {
    JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
    if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
        (rv == NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR ||
         rv == NS_ERROR_DOM_WRONG_DOCUMENT_ERR ||
         rv == NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR)) {
      exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
    }
    JavaDOMGlobals::ThrowException(env,
      "NodeMap.setNamedItem: failed", rv, exceptionType);
    return NULL;
  }
  if (!node)
    return NULL;

  return JavaDOMGlobals::CreateNodeSubtype(env, node);
}
示例#22
0
  bool
  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
  {
    RefPtr<Promise> promise = mProxy->WorkerPromise();
    if (NS_SUCCEEDED(mStatus)) {
      if (mEndpoint.IsEmpty()) {
        promise->MaybeResolve(JS::NullHandleValue);
      } else {
        RefPtr<PushSubscription> sub =
            new PushSubscription(nullptr, mEndpoint, mScope,
                                 Move(mRawP256dhKey), Move(mAuthSecret),
                                 Move(mAppServerKey));
        promise->MaybeResolve(sub);
      }
    } else if (NS_ERROR_GET_MODULE(mStatus) == NS_ERROR_MODULE_DOM_PUSH ) {
      promise->MaybeReject(mStatus);
    } else {
      promise->MaybeReject(NS_ERROR_DOM_PUSH_ABORT_ERR);
    }

    mProxy->CleanUp();

    return true;
  }
NS_IMETHODIMP
nsStringBundleService::FormatStatusMessage(nsresult aStatus,
                                           const PRUnichar* aStatusArg,
                                           PRUnichar* *result)
{
  nsresult rv;
  PRUint32 i, argCount = 0;
  nsCOMPtr<nsIStringBundle> bundle;
  nsXPIDLCString stringBundleURL;

  // XXX hack for mailnews who has already formatted their messages:
  if (aStatus == NS_OK && aStatusArg) {
    *result = nsCRT::strdup(aStatusArg);
    NS_ENSURE_TRUE(*result, NS_ERROR_OUT_OF_MEMORY);
    return NS_OK;
  }

  if (aStatus == NS_OK) {
    return NS_ERROR_FAILURE;       // no message to format
  }

  // format the arguments:
  const nsDependentString args(aStatusArg);
  argCount = args.CountChar(PRUnichar('\n')) + 1;
  NS_ENSURE_ARG(argCount <= 10); // enforce 10-parameter limit
  PRUnichar* argArray[10];

  // convert the aStatusArg into a PRUnichar array
  if (argCount == 1) {
    // avoid construction for the simple case:
    argArray[0] = (PRUnichar*)aStatusArg;
  }
  else if (argCount > 1) {
    PRInt32 offset = 0;
    for (i = 0; i < argCount; i++) {
      PRInt32 pos = args.FindChar('\n', offset);
      if (pos == -1) 
        pos = args.Length();
      argArray[i] = ToNewUnicode(Substring(args, offset, pos - offset));
      if (argArray[i] == nsnull) {
        rv = NS_ERROR_OUT_OF_MEMORY;
        argCount = i - 1; // don't try to free uninitialized memory
        goto done;
      }
      offset = pos + 1;
    }
  }

  // find the string bundle for the error's module:
  rv = mErrorService->GetErrorStringBundle(NS_ERROR_GET_MODULE(aStatus), 
                                           getter_Copies(stringBundleURL));
  if (NS_SUCCEEDED(rv)) {
    rv = getStringBundle(stringBundleURL, getter_AddRefs(bundle));
    if (NS_SUCCEEDED(rv)) {
      rv = FormatWithBundle(bundle, aStatus, argCount, argArray, result);
    }
  }
  if (NS_FAILED(rv)) {
    rv = getStringBundle(GLOBAL_PROPERTIES, getter_AddRefs(bundle));
    if (NS_SUCCEEDED(rv)) {
      rv = FormatWithBundle(bundle, aStatus, argCount, argArray, result);
    }
  }

done:
  if (argCount > 1) {
    for (i = 0; i < argCount; i++) {
      if (argArray[i])
        nsMemory::Free(argArray[i]);
    }
  }
  return rv;
}
NS_IMETHODIMP
nsAbLDAPAutoCompFormatter::FormatException(int32_t aState, 
                                           nsresult aErrorCode, 
                                           nsIAutoCompleteItem **aItem) 
{
    int32_t errorKey;
    nsresult rv;

    // create an nsIAutoCompleteItem to hold the returned value
    //
    nsCOMPtr<nsIAutoCompleteItem> item = do_CreateInstance(
        NS_AUTOCOMPLETEITEM_CONTRACTID, &rv);

    if (NS_FAILED(rv)) {
        NS_ERROR("nsAbLDAPAutoCompFormatter::FormatException(): couldn't"
                 " create " NS_AUTOCOMPLETEITEM_CONTRACTID "\n");
        return NS_ERROR_NOT_AVAILABLE;
    }

    // get the string bundle service
    //
    nsString errMsg, ldapErrMsg, alertMsg, ldapHint;
    nsString errCodeNum;

    nsCOMPtr<nsIStringBundleService> stringBundleSvc =
        mozilla::services::GetStringBundleService();
    if (stringBundleSvc) {
        NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException():"
                 " error getting string bundle service");
        return NS_ERROR_UNEXPECTED;
    }

    // get the string bundles relevant here: the main LDAP bundle,
    // and the ldap AutoCompletion-specific bundle
    //
    nsCOMPtr<nsIStringBundle> ldapBundle, ldapACBundle;

    rv = stringBundleSvc->CreateBundle(
        LDAP_ERROR_BUNDLE,
        getter_AddRefs(ldapBundle));
    if (NS_FAILED(rv)) {
        NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException():"
                 " error creating string bundle "
                 LDAP_ERROR_BUNDLE);
        return rv;
    } 

    rv = stringBundleSvc->CreateBundle(
        LDAP_AUTOCOMPLETE_ERROR_BUNDLE,
        getter_AddRefs(ldapACBundle));
    if (NS_FAILED(rv)) {
        NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException():"
                 " error creating string bundle "
                 LDAP_AUTOCOMPLETE_ERROR_BUNDLE);
        return rv;
    }

    // get the general error that goes in the dropdown and the window
    // title
    //
    rv = ldapACBundle->GetStringFromID(aState, getter_Copies(errMsg));
    if (NS_FAILED(rv)) {
        NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException():"
                 " error getting general error from bundle "
                 LDAP_AUTOCOMPLETE_ERROR_BUNDLE);
        return rv;
    }

    // for LDAP errors
    //
    if (NS_ERROR_GET_MODULE(aErrorCode) == NS_ERROR_MODULE_LDAP) {

        errorKey = NS_ERROR_GET_CODE(aErrorCode);

        // put the number itself in string form
        //
        errCodeNum.AppendInt(errorKey);

        // get the LDAP error message itself
        //
        rv = ldapBundle->GetStringFromID(NS_ERROR_GET_CODE(aErrorCode), 
                                                getter_Copies(ldapErrMsg));
        if (NS_FAILED(rv)) {
            NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException"
                     "(): error getting string 2 from bundle "
                     LDAP_ERROR_BUNDLE);
            return rv;
        }
  
    } else {

        // put the entire nsresult in string form
        //
        errCodeNum.AppendLiteral("0x");
        errCodeNum.AppendInt(aErrorCode, 16);    

        // figure out the key to index into the string bundle
        //
        const int32_t HOST_NOT_FOUND_ERROR=5000;
        const int32_t GENERIC_ERROR=9999;
        errorKey = ( (aErrorCode == NS_ERROR_UNKNOWN_HOST) ? 
                     HOST_NOT_FOUND_ERROR : GENERIC_ERROR );

        // get the specific error message itself
        rv = ldapACBundle->GetStringFromID(errorKey,
                                           getter_Copies(ldapErrMsg));
        if (NS_FAILED(rv)) {
            NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException"
                     "(): error getting specific non LDAP error-string "
                     "from bundle "
                     LDAP_AUTOCOMPLETE_ERROR_BUNDLE);
            return rv;
        }
    }

    // and try to find a hint about what the user should do next
    //
    const int32_t HINT_BASE=10000;
    const int32_t GENERIC_HINT_CODE = 9999;
    rv = ldapACBundle->GetStringFromID(HINT_BASE + errorKey, 
                                       getter_Copies(ldapHint));
    if (NS_FAILED(rv)) {
        rv = ldapACBundle->GetStringFromID(HINT_BASE + GENERIC_HINT_CODE,
                                           getter_Copies(ldapHint));
        if (NS_FAILED(rv)) {
            NS_ERROR("nsAbLDAPAutoCompleteFormatter::FormatException()"
                     "(): error getting hint string from bundle "
                     LDAP_AUTOCOMPLETE_ERROR_BUNDLE);
            return rv;
        }
    }
        
    const PRUnichar *stringParams[3] = { errCodeNum.get(),
                                         ldapErrMsg.get(), ldapHint.get() };

    rv = ldapACBundle->FormatStringFromName(
        NS_LITERAL_STRING("errorAlertFormat").get(), stringParams, 3,
        getter_Copies(alertMsg));
    if (NS_FAILED(rv)) {
        NS_WARNING("Failed to format warning string\n");
    }

    // put the error message, between angle brackets, into the XPIDL |value|
    // attribute.  Note that the hardcoded string is only used since 
    // stringbundles have already failed us.
    //
    if (errMsg.Length()) {
        nsString tErrMsg(NS_LITERAL_STRING("<"));
        tErrMsg.Append(errMsg);
        tErrMsg.AppendLiteral(">");
        rv = item->SetValue(tErrMsg);
    } else {
        rv = item->SetValue(
            NS_LITERAL_STRING("<Unknown LDAP autocompletion error>"));
    }

    if (NS_FAILED(rv)) {
        NS_ERROR("nsAbLDAPAutoCompFormatter::FormatException(): "
                 "item->SetValue failed");
        return rv;
    }
    
    // pass the alert message in as the param; if that fails, proceed anyway
    //
    nsCOMPtr<nsISupportsString> alert(do_CreateInstance(
                                           NS_SUPPORTS_STRING_CONTRACTID,
                                           &rv));
    if (NS_FAILED(rv)) {
        NS_WARNING("nsAbLDAPAutoCompFormatter::FormatException(): "
                   "could not create nsISupportsString");
    } else {
        rv = alert->SetData(alertMsg);
        if (NS_FAILED(rv)) {
            NS_WARNING("nsAbLDAPAutoCompFormatter::FormatException(): "
                     "alert.Set() failed");
        } else {
            rv = item->SetParam(alert);
            if (NS_FAILED(rv)) {
                NS_WARNING("nsAbLDAPAutoCompFormatter::FormatException(): "
                           "item->SetParam failed");
            }
        }
    }

    // this is a remote addressbook, set the class name so the autocomplete 
    // item can be styled to show this
    //
    rv = item->SetClassName("remote-err");
    if (NS_FAILED(rv)) {
        NS_WARNING("nsAbLDAPAutoCompleteFormatter::FormatException():"
                   " item->SetClassName() failed");
    }

    // all done; return the item
    //
    NS_IF_ADDREF(*aItem = item);
    return NS_OK;
}