зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1753375 - Disallow PathUtils.get*Dir on main thread r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D140145
This commit is contained in:
Родитель
d12845864e
Коммит
41849df494
|
@ -103,17 +103,26 @@ namespace PathUtils {
|
|||
|
||||
[Exposed=Window]
|
||||
partial namespace PathUtils {
|
||||
/**
|
||||
* The profile directory.
|
||||
*/
|
||||
[Throws, BinaryName="ProfileDirSync"]
|
||||
readonly attribute DOMString profileDir;
|
||||
|
||||
/**
|
||||
* The local-specific profile directory.
|
||||
*/
|
||||
[Throws, BinaryName="LocalProfileDirSync"]
|
||||
readonly attribute DOMString localProfileDir;
|
||||
|
||||
/**
|
||||
* The temporary directory for the process.
|
||||
*/
|
||||
[Throws, BinaryName="TempDirSync"]
|
||||
readonly attribute DOMString tempDir;
|
||||
};
|
||||
|
||||
[Exposed=(Window, Worker)]
|
||||
[Exposed=Worker]
|
||||
partial namespace PathUtils {
|
||||
/**
|
||||
* The profile directory.
|
||||
|
|
|
@ -376,7 +376,7 @@ void PathUtils::GetTempDirSync(const GlobalObject&, nsString& aResult,
|
|||
|
||||
already_AddRefed<Promise> PathUtils::GetProfileDirAsync(
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr) {
|
||||
// NB: This will eventually be off-main-thread only.
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
auto guard = sDirCache.Lock();
|
||||
return DirectoryCache::Ensure(guard.ref())
|
||||
|
@ -385,7 +385,7 @@ already_AddRefed<Promise> PathUtils::GetProfileDirAsync(
|
|||
|
||||
already_AddRefed<Promise> PathUtils::GetLocalProfileDirAsync(
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr) {
|
||||
// NB: This will eventually be off-main-thread only.
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
auto guard = sDirCache.Lock();
|
||||
return DirectoryCache::Ensure(guard.ref())
|
||||
|
@ -395,7 +395,7 @@ already_AddRefed<Promise> PathUtils::GetLocalProfileDirAsync(
|
|||
|
||||
already_AddRefed<Promise> PathUtils::GetTempDirAsync(
|
||||
const GlobalObject& aGlobal, ErrorResult& aErr) {
|
||||
// NB: This will eventually be off-main-thread only.
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
auto guard = sDirCache.Lock();
|
||||
return DirectoryCache::Ensure(guard.ref())
|
||||
|
|
|
@ -318,7 +318,7 @@
|
|||
// symlink to `/var`, so we need to pre-normalize our temporary directory
|
||||
// or expected paths won't match.
|
||||
const tmpDir = PathUtils.join(
|
||||
PathUtils.normalize(await PathUtils.getTempDir()),
|
||||
PathUtils.normalize(PathUtils.tempDir),
|
||||
"pathutils_test"
|
||||
);
|
||||
|
||||
|
@ -475,19 +475,16 @@
|
|||
add_task(async function test_getDirectories() {
|
||||
// See: nsAppDirectoryServiceDefs.h
|
||||
const tests = [
|
||||
["profileDir", "getProfileDir", "ProfD"],
|
||||
["localProfileDir", "getLocalProfileDir", "ProfLD"],
|
||||
["tempDir", "getTempDir", AppConstants.MOZ_SANDBOX ? "ContentTmpD" : "TmpD"],
|
||||
["profileDir", "ProfD"],
|
||||
["localProfileDir", "ProfLD"],
|
||||
["tempDir", AppConstants.MOZ_SANDBOX ? "ContentTmpD" : "TmpD"],
|
||||
];
|
||||
|
||||
for (const [attrName, methName, dirConstant] of tests) {
|
||||
for (const [attrName, dirConstant] of tests) {
|
||||
const expected = Services.dirsvc.get(dirConstant, Ci.nsIFile).path;
|
||||
|
||||
const attrValue = PathUtils[attrName];
|
||||
is(attrValue, expected, `PathUtils.${attrName} == Services.dirsvc.get("${dirConstant}", Ci.nsIFile).path`);
|
||||
|
||||
const methValue = await PathUtils[methName]();
|
||||
is(methValue, expected, `PathUtils.${methName}() == Services.dirsvc.get("${dirConstant}", Ci.nsIFile).path`);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче