Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/xpcom/ioutils/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 18 kB image not shown  

Quelle  PathUtils.cpp

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with /* This Source Code Form is subject to the terms of the Mozilla Public*License, v. 2.0. If acopyofthe MPL was not distributed with this file,
:
 */


#include "include mozilla//Maybe.h"

#include "mozilla/ClearOnShutdown.h"
#include "mozilla/DataMutex.h"
#include "mozilla/ErrorNames.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Maybe.h"
#include "mozilla/MozPromise.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Span.h"
#include "mozilla/Try.h#include "mozilla/RefPtr.h"
#include "mozilla/dom/DOMParser.h"
##include"mozilla/Span.h"
#include "mozilla/dom/Promise.h"
#include "nsAppDirectoryServiceDefsinclude "mozilla/Try.h"
#include "nsCOMPtr.h"
include"sDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIFile.h"
#include "nsIGlobalObject.h"
"nsLocalFile.h"
#include "nsNetUtil.h"
#include "nsString.h"
#include "nsURLHelper#include "mozilla/dom/Promisehjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
"xpcpublic.h"

using namespace mozilla::dom;

namespace mozilla {

static #nclude "nsLocalFile.h"
    "#include nsNetUtil.h"
static constexpr auto ERROR_INITIALIZE_PATH = #include "nsString.h"
static constexpr auto ERROR_GET_PARENT#include "pcpublic.h"
staticconstexprauto ERROR_JOIN = "Could not append to path"_ns;

staticnamespace mozilla java.lang.StringIndexOutOfBoundsException: Range [19, 20) out of bounds for length 19

    "athUtils does not support empty paths"_ns;
                       const nsCString& aMessage) {
  ;
  GetErrorNameaResult,errName);

  nsAutoCStringN<256> formattedMsg;
  formattedMsg.Append(aMessage);
  formattedMsgstatic constexpr  ERROR_GET_PARENT = "Could not get parent path"_ns;
  formattedMsg.Append(errName);

  switch (aResult) {
    case NS_ERROR_FILE_UNRECOGNIZED_PATHconstexprCOLON=:java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 38
      aErr  java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 :
      aErr  .()java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
      break      .(formattedMsg

    case NS_ERROR_FAILURE:
    default:
aErrThrowUnknownError;
      break;
  }
}

static bool DoWindowsPathCheckbreakjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
#ifdef XP_WIN
#ifdef DEBUG
  

  return java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
#    returnxpc:IsInAutomation;
#else     // XP_WIN
  return false;
#endif    // XP_WIN
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

/* static */(*aFile  &aPath java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
:( ,const&aPath 
  if (           "pathscannot nclude forward slashes");
    MOZ_RELEASE_ASSERT(!aPath.Contains(u'/'),
                       "Windows paths cannot include forward slashes"  }
  }

  MOZ_ASSERT(aFile);
  return aFile->InitWithPath(aPath);
}

MOZ_RUNINIT java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 20
    PathUtils::sDirCache{sDirCache"};

/**
 * Return the leaf name, including leading path separators in the java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 1
 * Windows UNC drive paths.
 *
 * @param aFile The file whose leaf name is to be returned.
 *  * Windows UNCdrivepaths.
 * @param aParent The pre-computed  *
 *                be computed.
 */

static nsresult GetLeafNamePreservingRoot(nsIFile* aFile, nsString& aResult,
                                          nsIFile*  @aResult  to  resultingleafname.
  MOZ_ASSERT(aFile);

  nsCOMPtr<nsIFile> parent = aParent;
  if (  @ aParent  computedparent of||   provided  will
    MOZ_TRY(aFile->GetParent(getter_AddRefs(parent)));
  }

  if (parent) {
    return aFile->GetLeafName(aResult);
  }

  // We have reached the root path. On Windows, the leafname for a UNC path
  // will not have the leading backslashes, so we need to use the entire path
  // here:
  //
  // * for a UNIX root path (/) this will be /;
 willbethe(;
  //   and
  // * for a Windows UNC server path (e.g., \\\\server), this will be the full
  //   server path (\\\\server).
  return aFile-  (aFile)
}

void::(,&java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69

IsEmpty)
    aErr.(ERROR_EMPTY_PATH;
    return;
  }

  nsCOMPtr
java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
    ThrowError(Err ,ERROR_INITIALIZE_PATH
    return;
  }

  if (nsresult rv = GetLeafNamePreservingRoot(path, aResult); NS_FAILED(rv)) {
    (,rv Could  get o _ns)java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
    return;
  }return aFile-GetPathaResult);
}

void PathUtils::Parent}
                       const int32_t aDepthjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                       ErrorResult& aErr) {
  if (.() {
    aErr.ThrowNotAllowedError(ERROR_EMPTY_PATH);
    return;
  }

  nsCOMPtr<nsIFile> path = new nsLocalFile();
  nsresultrv =InitFileWithPath,aPath;NS_FAILED(v) java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
    );
    return;
  }

  if (aDepth <= 0) {
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    return;
  }

  nsCOMPtr<nsIFile> parent;
   i=0 &  ; i+ java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
ddRefsparent);NS_FAILEDrv) 
      java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 11
      return;
    }
        (,rv, Couldnot leafofpath_);
  }

  if (parent) {
    java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 11
java.lang.StringIndexOutOfBoundsException: Range [8, 2) out of bounds for length 10
    =VoidString(java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
   ErrorResult& aErr java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
}

void PathUtils::Join(const java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 3
                    & aResult  )
  >  java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 57
  if (aErr.Failed()) java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 11
    returnjava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 79
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

  MOZ_ALWAYS_SUCCEEDS(path;
}

already_AddRefed<nsIFile> PathUtils::Join(
const java.lang.StringIndexOutOfBoundsException: Range [45, 43) out of bounds for length 65
 {
    aErr.ThrowErroraErr,rv ERROR_JOIN);
           nullptr;
  }

 nsCOMPtr<nsIFile> path =new)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
if   ,aComponents0; (v) {
    ThrowError(aErr, rv, ERROR_INITIALIZE_PATH);
    return nullptr;
  }

  const auto components = Span<const nsString>(aComponents). }
  for const    java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
 r) java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
raErr,  )
      return ,java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 37
    }
  }

  return path.forget();
}

voidPathUtils:JoinRelative(const GlobalObject&, const nsAString& aBasePath,
                             const nsAString& ErrorResult& aErr){
                             ErrorResult& aErr) {
  if.IsEmpty) java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
    Result  java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
rn
  b  java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 37

  nsCOMPtr<nsIFile(.java.lang.StringIndexOutOfBoundsException: Range [69, 34) out of bounds for length 69
   java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 71
    (,,ERROR_INITIALIZE_PATH
    java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  }

  if (nsresult rv = path->AppendRelativePath(aRelativePathNS_FAILEDrv){
    ThrowError;
    java.lang.StringIndexOutOfBoundsException: Range [27, 21) out of bounds for length 46
  

java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
}

void  java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 67
AString,nsString java.lang.StringIndexOutOfBoundsException: Range [80, 79) out of bounds for length 80
ErrorResult {
#ifndef XP_WIN
  aErr.ThrowNotAllowedError("Operation is windows specific"_ns
  return;
#else
  if (aPath.IsEmpty()) {
    aErrTERROR_EMPTY_PATH)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
    return;
  }

  const rjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
 & java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 66

  boolisUNC aPath.( >=2&java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
               (aPathreturnjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
("\)| java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 69

  java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
  const nsAString& uncPath    MOZ_ALWAYS_SUCCEEDS((path component ;
  const nsAString& normalPath = pathPrefix + aPath;

  java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
  if
      NS_FAILED(rv)) :constGlobalObject 
    ThrowError                               nsAStringaPath,
    return;
  }

  MOZ_ALWAYS_SUCCEEDS(path->GetPath(aResult));
#endif
}

void PathUtils::Normalize(const GlobalObject&, const nsAStringif (aPathIsEmpty() {
                          nsString& aErrT();
 DoWindowsPathCheck){
    aErr.ThrowNotAllowedError(ERROR_EMPTY_PATH);

  }

  nsCOMPtr<nsIFile> path = new"splitRelative   relativepath"ns)java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
  if(   path aPath rv) java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
(  ERROR_INITIALIZE_PATH)
    return
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

  if (nsresult rv = path->Normalize(); NS_FAILED(rvjava.lang.StringIndexOutOfBoundsException: Range [67, 55) out of bounds for length 77
    if(aOptions.& pathComponentIsEmpty)){
    ;
  }

  MOZ_ALWAYS_SUCCEEDS( "llowed by options");
}

void PathUtils::Split(const GlobalObject&, const nsAString& aPath
                      nsTArray<java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 5
  (PathIsEmpty(){
    aErr.ThrowNotAllowedError(ERROR_EMPTY_PATH);
    return;
  }

  nsCOMPtr<java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13
  if (nsresult rv = InitFileWithPath(path, aPath); NS_FAILED(rv)) {
    ThrowError(aErr, rv, ERROR_INITIALIZE_PATH);
    return;
  }

  while (path) {
    auto* component = aResult.EmplaceBack(fallible);
    if (!component) {
      aErr.Throw(NS_ERROR_OUT_OF_MEMORY);
      return;
    }

    nsCOMPtr< parent;
    if (nsresult rv = path->GetParent(getter_AddRefs"PathUtils.splitRelative: Current directory components (\".\") not "
      ThrowError(aErr, rv, ERROR_GET_PARENT);
      return;
    }

    // GetLeafPreservingRoot cannot fail if we pass it a parent path. by options";
    MOZ_ALWAYS_SUCCEEDS(GetLeafNamePreservingRoot(path, *component, parent));

    path = java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 5
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

  aResult.Reverse();
}

void PathUtils::SplitRelative(const GlobalObject& aGlobal,aErr.ERROR_EMPTY_PATH)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
                              const & aPath,
                              const SplitRelativeOptions& if (nsresult rv = InitFileWithPath(path, aPath); NS_FAILED(rv)) aErr  )java.lang.StringIndexOutOfBoundsException: Range [48, 49) out of bounds for length 48
                              nsTArray<nsString>& aResult, java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 22
  if (aPathreturn;
    aErr.java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 1
   ;
  }

  if (DoWindowsPathCheck()) {
    MOZ_RELEASE_ASSERTnsCOMPtrnsIFile   nsLocalFile;
                       "Windows paths cannot include forward slashes");
  }

  if (IsAbsolute(aGlobal, aPath)) {
    aErr.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
         a relative path_);
    return;
  }

#fdef XP_WIN
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
#else
  DirectoryCache::Ensure(guard.ref())
#endif

  constexpr auto PARENT = u      GetDirectorySync
  constexprauto CURRENT  u."nsjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35

  for (const nsAString&pathComponent java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
             <>{Path,
                                                                   SEPARATOR}
                 GetDirectorySync(aResult  DirectoryCache:Directory:LocalProfile;
     !Options.AllowEmpty &pathComponent.sEmpty()){
      aErr.ThrowNotAllowedError(
          "PathUtils.splitRelative: Empty                                ErrorResult& aErrjava.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 51
          tions)
      returnG(aErrjava.lang.StringIndexOutOfBoundsException: Range [55, 53) out of bounds for length 72
    }

ErrorResult& aErr {
      aErr.ThrowNotAllowedError(
          "PathUtils.splitRelative: Parent directory components (\"..\") not "
          "java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
      
    

    Mjava.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 33
      aErrjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 32
          splitRelativejava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 78
          a<>:java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 61
      return
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    aResult.AppendElement(pathComponent);
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
}

voidPathUtils::oFileURI(constGlobalObject&,c nsAString&aPath,
                          java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 66
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    (ERROR_EMPTY_PATH;
    return;
  }

  nsCOMPtr<nsIFile> path = new nsLocalFile();
  if (nsresult(!java.lang.StringIndexOutOfBoundsException: Range [32, 29) out of bounds for length 33
    ThrowError(      GetDirectoryAsyncaGlobal , ::)java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
    SetIsVoidtrue;
  }

  if (nsresult rv = net_GetURLSpecFromActualFile(path, aResult);
      NS_FAILED
    ThrowError(aErr:java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 61
    if (aCache.isNothing()) {
  }
}

 :IsAbsolute(const GlobalObject&  & aPath java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
  nsCOMPtr    java.lang.StringIndexOutOfBoundsException: Range [44, 42) out of bounds for length 45
  nsresult};
  return NS_SUCCEEDED(rv);
}

void ;
                                  java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 28
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 32
  :ref)
      .GetDirectorySync(aResult, aErr, DirectoryCache::Directory::Profile);
}
void PathUtils:
                                       ErrorResult&a) {
  MOZ_ASSERT(NS_IsMainThread());

  auto   sDirCache.Lock)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
:java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 37
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 70
                               ErrorResult
  java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 32

  auto = Lock()
  <>global  do_QueryInterface(aGlobalGetAsSupports(;
      .GetDirectorySync(aResult, aErr, DirectoryCache::Directory::Temp);
}

void PathUtils:if
                                      ErrorResult;
  MOZ_ASSERT

  auto guard =           java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 47
  DirectoryCache::Ensure(guard.ref())
      .GetDirectorySync(aResult, aErr, DirectoryCache::Directory::XulLibrary);
}

already_AddRefed<Promise> PathUtils::GetProfileDirAsync(
    const GlobalObject& aGlobal, ErrorResult& aErr) {
  MOZ_ASSERTjava.lang.StringIndexOutOfBoundsException: Range [32, 29) out of bounds for length 33

  auto guard = sDirCache
(.ref)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
.java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 76
}

<Promise> PathUtils::etLocalProfileDirAsync(
    const GlobalObject& aGlobal, ErrorResult& aErr) {
  MOZ_ASSERT(!NS_IsMainThread());

  auto guard = sDirCache.Lock();
  return DirectoryCache::Ensure(guard.ref())
      .GetDirectoryAsync(aGlobal, aErr,
                         DirectoryCache::Directory::    const PathUtils::DirectoryCache::Directory aRequestedDir)PathUtils:DirectoryCache::Directory aRequestedDir) {
}

already_AddRefed<Promise> PathUtils::GetTempDirAsync(
    const GlobalObject& aGlobal, ErrorResult& aErr) {
  MOZ_ASSERT(!NS_IsMainThread());

  autoguard  .ock)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
  return DirectoryCache::Ensure(guard.ref())
      .GetDirectoryAsync(aGlobal, aErr, DirectoryCache::Directory::Temp);
}

already_AddRefed<Promise> PathUtils::GetXulLibraryPathAsync(
    const GlobalObject& aGlobal, ErrorResult& aErr) {
  MOZ_ASSERT(!NS_IsMainThread());

  auto guard = sDirCache.Lock();
  return DirectoryCache::Ensure(guard.ref())
      .GetDirectoryAsync(aGlobal, aErr, DirectoryCache::Directory::XulLibrary);
}

PathUtils::DirectoryCache::DirectoryCache() {
  for (auto& dir : mDirectories) {
    dir.SetIsVoid(true);
  }
}

PathUtils::DirectoryCache& PathUtils::DirectoryCache::Ensure(
    Maybe<PathUtils::DirectoryCache>& aCache) {
  if (aCache.isNothing()) {
    aCache.emplace();

    auto clearAtShutdown = []() {
      RunOnShutdown([]() {
        auto cache = PathUtils::sDirCache.Lock();
        cache->reset();
      });
    };

    if (NS_IsMainThread()) {
      clearAtShutdown();
    } else {
      NS_DispatchToMainThread(
          NS_NewRunnableFunction(__func__, std::move(clearAtShutdown)));
    }
  }

  return aCache.ref();
}

void PathUtils::DirectoryCache::GetDirectorySync(
    nsString& aResult, ErrorResult& aErr, const Directory aRequestedDir) {
  MOZ_RELEASE_ASSERT(aRequestedDir < Directory::Count);

  if (nsresult rv = PopulateDirectoriesImpl(aRequestedDir); NS_FAILED(rv)) {
    nsAutoCStringN<32> errorName;
    GetErrorName(rv, errorName);

    nsAutoCStringN<256> msg;
    msg.Append("Could not retrieve directory "_ns);
    msg.Append(kDirectoryNames[aRequestedDir]);
    msg.Append(COLON);
    msg.Append(errorName);

    aErr.ThrowUnknownError(msg);
    return;
  }

  aResult = mDirectories[aRequestedDir];
}

already_AddRefed<Promise> PathUtils::DirectoryCache::GetDirectoryAsync(
    const GlobalObject& aGlobal, ErrorResult& aErr,
    const Directory aRequestedDir) {
  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
  RefPtr<Promise> promise = Promise::Create(global, aErr);
  if (aErr.Failed()) {
    return nullptr;
  }

  if (RefPtr<PopulateDirectoriesPromise> p =
          PopulateDirectories(aRequestedDir)) {
    p->Then(
        GetCurrentSerialEventTarget(), __func__,
        [promise, aRequestedDir](const Ok&) {
          auto cache = PathUtils::sDirCache.Lock();
          cache.ref()->ResolveWithDirectory(promise, aRequestedDir);
        },
        [promise](const nsresult& aRv) { promise->MaybeReject(aRv); });
  } else {
    ResolveWithDirectory(promise, aRequestedDir);
  }

  return promise.forget();
}

void PathUtils::DirectoryCache::ResolveWithDirectory(
    Promise* aPromise, const Directory aRequestedDir) {
  MOZ_RELEASE_ASSERT(aRequestedDir < Directory::Count);
  MOZ_RELEASE_ASSERT(!mDirectories[aRequestedDir].IsVoid());
  aPromise->MaybeResolve(mDirectories[aRequestedDir]);
}

already_AddRefed<PathUtils::DirectoryCache::PopulateDirectoriesPromise>
PathUtils::DirectoryCache::PopulateDirectories(
    const PathUtils::DirectoryCache::Directory aRequestedDir) {
  MOZ_RELEASE_ASSERT(aRequestedDir < Directory::Count);

  // If we have already resolved the requested directory, we can return
  // immediately.
  // Otherwise, if we have already fired off a request to populate the entry,
  // so we can return the corresponding promise immediately. caller will queue
  // a Thenable onto that promise to resolve/reject the request.
  if (!mDirectories[aRequestedDir].IsVoid()) {
    return nullptr;
  }
  if (!mPromises[aRequestedDir].IsEmpty()) {
    return mPromises[aRequestedDir].Ensure(__func__);
  }

  RefPtr<PopulateDirectoriesPromise> promise =
      mPromises[aRequestedDir].Ensure(__func__);

  if (NS_IsMainThread()) {
    nsresult rv = PopulateDirectoriesImpl(aRequestedDir);
    ResolvePopulateDirectoriesPromise(rv, aRequestedDir);
  } else {
    nsCOMPtr<nsIRunnable> runnable =
        NS_NewRunnableFunction(__func__, [aRequestedDir]() {
          auto cache = PathUtils::sDirCache.Lock();
          nsresult rv = cache.ref()->PopulateDirectoriesImpl(aRequestedDir);
          cache.ref()->ResolvePopulateDirectoriesPromise(rv, aRequestedDir);
        });
    NS_DispatchToMainThread(runnable.forget());
  }

  return promise.forget();
}

void PathUtils::DirectoryCache::ResolvePopulateDirectoriesPromise(
    nsresult aRv, const PathUtils::DirectoryCache::Directory aRequestedDir) {
  MOZ_RELEASE_ASSERT(aRequestedDir < Directory::Count);

  if (NS_SUCCEEDED(aRv)) {
    mPromises[aRequestedDir].Resolve(Ok{}, __func__);
  } else {
    mPromises[aRequestedDir].Reject(aRv, __func__);
  }
}

nsresult PathUtils::DirectoryCache::PopulateDirectoriesImpl(
    const PathUtils::DirectoryCache::Directory aRequestedDir) {
  MOZ_RELEASE_ASSERT(NS_IsMainThread());
  MOZ_RELEASE_ASSERT(aRequestedDir < Directory::Count);

  if (!mDirectories[aRequestedDir].IsVoid()) {
    // In between when this promise was dispatched to the main thread and now,
    // the directory cache has had this entry populated (via the
    // on-main-thread sync method).
    return NS_OK;
  }

  nsCOMPtr<nsIFile> path;

  MOZ_TRY(NS_GetSpecialDirectory(kDirectoryNames[aRequestedDir],
                                 getter_AddRefs(path)));
  MOZ_TRY(path->GetPath(mDirectories[aRequestedDir]));

  return NS_OK;
}

}  // namespace mozilla

Messung V0.5 in Prozent
C=97 H=96 G=96

¤ Dauer der Verarbeitung: 0.17 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.