Bug 1766130 - Properly propagate errors from Promise creation. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D144515
This commit is contained in:
Peter Van der Beken
2022-05-02 07:44:23 +00:00
parent 5a9c0d8542
commit 1c499dc49d
51 changed files with 846 additions and 692 deletions

View File

@@ -1527,16 +1527,10 @@ bool Document::CallerIsTrustedAboutHttpsOnlyError(JSContext* aCx,
} }
already_AddRefed<mozilla::dom::Promise> Document::AddCertException( already_AddRefed<mozilla::dom::Promise> Document::AddCertException(
bool aIsTemporary) { bool aIsTemporary, ErrorResult& aError) {
nsIGlobalObject* global = GetScopeObject(); RefPtr<Promise> promise = Promise::Create(GetScopeObject(), aError,
if (!global) { Promise::ePropagateUserInteraction);
return nullptr; if (aError.Failed()) {
}
ErrorResult er;
RefPtr<Promise> promise =
Promise::Create(global, er, Promise::ePropagateUserInteraction);
if (er.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -4025,7 +4025,8 @@ class Document : public nsINode,
static bool AutomaticStorageAccessPermissionCanBeGranted( static bool AutomaticStorageAccessPermissionCanBeGranted(
nsIPrincipal* aPrincipal); nsIPrincipal* aPrincipal);
already_AddRefed<Promise> AddCertException(bool aIsTemporary); already_AddRefed<Promise> AddCertException(bool aIsTemporary,
ErrorResult& aError);
void ReloadWithHttpsOnlyException(); void ReloadWithHttpsOnlyException();

View File

@@ -1397,7 +1397,8 @@ Promise* Navigator::GetBattery(ErrorResult& aRv) {
// Navigator::Share() - Web Share API // Navigator::Share() - Web Share API
//***************************************************************************** //*****************************************************************************
Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) { already_AddRefed<Promise> Navigator::Share(const ShareData& aData,
ErrorResult& aRv) {
if (!mWindow || !mWindow->IsFullyActive()) { if (!mWindow || !mWindow->IsFullyActive()) {
aRv.ThrowInvalidStateError("The document is not fully active."); aRv.ThrowInvalidStateError("The document is not fully active.");
return nullptr; return nullptr;
@@ -1495,7 +1496,7 @@ Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) {
} }
self->mSharePromise = nullptr; self->mSharePromise = nullptr;
}); });
return mSharePromise; return do_AddRef(mSharePromise);
} }
//***************************************************************************** //*****************************************************************************

View File

@@ -133,7 +133,7 @@ class Navigator final : public nsISupports, public nsWrapperCache {
Promise* GetBattery(ErrorResult& aRv); Promise* GetBattery(ErrorResult& aRv);
bool CanShare(const ShareData& aData); bool CanShare(const ShareData& aData);
Promise* Share(const ShareData& aData, ErrorResult& aRv); already_AddRefed<Promise> Share(const ShareData& aData, ErrorResult& aRv);
static void AppName(nsAString& aAppName, nsIPrincipal* aCallerPrincipal, static void AppName(nsAString& aAppName, nsIPrincipal* aCallerPrincipal,
bool aUsePrefOverriddenValue); bool aUsePrefOverriddenValue);

View File

@@ -33,6 +33,7 @@ namespace IOUtils {
* @return Resolves with an array of unsigned byte values read from disk, * @return Resolves with an array of unsigned byte values read from disk,
* otherwise rejects with a DOMException. * otherwise rejects with a DOMException.
*/ */
[NewObject]
Promise<Uint8Array> read(DOMString path, optional ReadOptions opts = {}); Promise<Uint8Array> read(DOMString path, optional ReadOptions opts = {});
/** /**
* Reads the UTF-8 text file located at |path| and returns the decoded * Reads the UTF-8 text file located at |path| and returns the decoded
@@ -45,6 +46,7 @@ namespace IOUtils {
* @return Resolves with the file contents encoded as a string, otherwise * @return Resolves with the file contents encoded as a string, otherwise
* rejects with a DOMException. * rejects with a DOMException.
*/ */
[NewObject]
Promise<UTF8String> readUTF8(DOMString path, optional ReadUTF8Options opts = {}); Promise<UTF8String> readUTF8(DOMString path, optional ReadUTF8Options opts = {});
/** /**
* Read the UTF-8 text file located at |path| and return the contents * Read the UTF-8 text file located at |path| and return the contents
@@ -56,6 +58,7 @@ namespace IOUtils {
* *
* @return Resolves with the contents of the file parsed as JSON. * @return Resolves with the contents of the file parsed as JSON.
*/ */
[NewObject]
Promise<any> readJSON(DOMString path, optional ReadUTF8Options opts = {}); Promise<any> readJSON(DOMString path, optional ReadUTF8Options opts = {});
/** /**
* Attempts to safely write |data| to a file at |path|. * Attempts to safely write |data| to a file at |path|.
@@ -74,6 +77,7 @@ namespace IOUtils {
* @return Resolves with the number of bytes successfully written to the file, * @return Resolves with the number of bytes successfully written to the file,
* otherwise rejects with a DOMException. * otherwise rejects with a DOMException.
*/ */
[NewObject]
Promise<unsigned long long> write(DOMString path, Uint8Array data, optional WriteOptions options = {}); Promise<unsigned long long> write(DOMString path, Uint8Array data, optional WriteOptions options = {});
/** /**
* Attempts to encode |string| to UTF-8, then safely write the result to a * Attempts to encode |string| to UTF-8, then safely write the result to a
@@ -86,6 +90,7 @@ namespace IOUtils {
* @return Resolves with the number of bytes successfully written to the file, * @return Resolves with the number of bytes successfully written to the file,
* otherwise rejects with a DOMException. * otherwise rejects with a DOMException.
*/ */
[NewObject]
Promise<unsigned long long> writeUTF8(DOMString path, UTF8String string, optional WriteOptions options = {}); Promise<unsigned long long> writeUTF8(DOMString path, UTF8String string, optional WriteOptions options = {});
/** /**
* Attempts to serialize |value| into a JSON string and encode it as into a * Attempts to serialize |value| into a JSON string and encode it as into a
@@ -99,6 +104,7 @@ namespace IOUtils {
* @return Resolves with the number of bytes successfully written to the file, * @return Resolves with the number of bytes successfully written to the file,
* otherwise rejects with a DOMException. * otherwise rejects with a DOMException.
*/ */
[NewObject]
Promise<unsigned long long> writeJSON(DOMString path, any value, optional WriteOptions options = {}); Promise<unsigned long long> writeJSON(DOMString path, any value, optional WriteOptions options = {});
/** /**
* Moves the file from |sourcePath| to |destPath|, creating necessary parents. * Moves the file from |sourcePath| to |destPath|, creating necessary parents.
@@ -113,6 +119,7 @@ namespace IOUtils {
* @return Resolves if the file is moved successfully, otherwise rejects with * @return Resolves if the file is moved successfully, otherwise rejects with
* a DOMException. * a DOMException.
*/ */
[NewObject]
Promise<void> move(DOMString sourcePath, DOMString destPath, optional MoveOptions options = {}); Promise<void> move(DOMString sourcePath, DOMString destPath, optional MoveOptions options = {});
/** /**
* Removes a file or directory at |path| according to |options|. * Removes a file or directory at |path| according to |options|.
@@ -123,6 +130,7 @@ namespace IOUtils {
* @return Resolves if the file is removed successfully, otherwise rejects * @return Resolves if the file is removed successfully, otherwise rejects
* with a DOMException. * with a DOMException.
*/ */
[NewObject]
Promise<void> remove(DOMString path, optional RemoveOptions options = {}); Promise<void> remove(DOMString path, optional RemoveOptions options = {});
/** /**
* Creates a new directory at |path| according to |options|. * Creates a new directory at |path| according to |options|.
@@ -132,6 +140,7 @@ namespace IOUtils {
* @return Resolves if the directory is created successfully, otherwise * @return Resolves if the directory is created successfully, otherwise
* rejects with a DOMException. * rejects with a DOMException.
*/ */
[NewObject]
Promise<void> makeDirectory(DOMString path, optional MakeDirectoryOptions options = {}); Promise<void> makeDirectory(DOMString path, optional MakeDirectoryOptions options = {});
/** /**
* Obtains information about a file, such as size, modification dates, etc. * Obtains information about a file, such as size, modification dates, etc.
@@ -144,6 +153,7 @@ namespace IOUtils {
* *
* @see FileInfo * @see FileInfo
*/ */
[NewObject]
Promise<FileInfo> stat(DOMString path); Promise<FileInfo> stat(DOMString path);
/** /**
* Copies a file or directory from |sourcePath| to |destPath| according to * Copies a file or directory from |sourcePath| to |destPath| according to
@@ -157,6 +167,7 @@ namespace IOUtils {
* @return Resolves if the file was copied successfully, otherwise rejects * @return Resolves if the file was copied successfully, otherwise rejects
* with a DOMException. * with a DOMException.
*/ */
[NewObject]
Promise<void> copy(DOMString sourcePath, DOMString destPath, optional CopyOptions options = {}); Promise<void> copy(DOMString sourcePath, DOMString destPath, optional CopyOptions options = {});
/** /**
* Updates the |modification| time for the file at |path|. * Updates the |modification| time for the file at |path|.
@@ -173,6 +184,7 @@ namespace IOUtils {
* milliseconds since the Unix epoch, otherwise rejects with a * milliseconds since the Unix epoch, otherwise rejects with a
* DOMException. * DOMException.
*/ */
[NewObject]
Promise<long long> setModificationTime(DOMString path, optional long long modification); Promise<long long> setModificationTime(DOMString path, optional long long modification);
/** /**
* Retrieves a (possibly empty) list of immediate children of the directory at * Retrieves a (possibly empty) list of immediate children of the directory at
@@ -184,6 +196,7 @@ namespace IOUtils {
* children of the directory at |path|, otherwise rejects with a * children of the directory at |path|, otherwise rejects with a
* DOMException. * DOMException.
*/ */
[NewObject]
Promise<sequence<DOMString>> getChildren(DOMString path, optional GetChildrenOptions options = {}); Promise<sequence<DOMString>> getChildren(DOMString path, optional GetChildrenOptions options = {});
/** /**
* Set the permissions of the file at |path|. * Set the permissions of the file at |path|.
@@ -204,6 +217,7 @@ namespace IOUtils {
* @return Resolves if the permissions were set successfully, otherwise * @return Resolves if the permissions were set successfully, otherwise
* rejects with a DOMException. * rejects with a DOMException.
*/ */
[NewObject]
Promise<void> setPermissions(DOMString path, unsigned long permissions, optional boolean honorUmask = true); Promise<void> setPermissions(DOMString path, unsigned long permissions, optional boolean honorUmask = true);
/** /**
* Return whether or not the file exists at the given path. * Return whether or not the file exists at the given path.
@@ -212,6 +226,7 @@ namespace IOUtils {
* *
* @return A promise that resolves to whether or not the given file exists. * @return A promise that resolves to whether or not the given file exists.
*/ */
[NewObject]
Promise<boolean> exists(DOMString path); Promise<boolean> exists(DOMString path);
/** /**
@@ -223,6 +238,7 @@ namespace IOUtils {
* *
* @return A promise that resolves to a unique filename. * @return A promise that resolves to a unique filename.
*/ */
[NewObject]
Promise<DOMString> createUniqueFile(DOMString parent, DOMString prefix, optional unsigned long permissions = 0644); Promise<DOMString> createUniqueFile(DOMString parent, DOMString prefix, optional unsigned long permissions = 0644);
/** /**
@@ -234,6 +250,7 @@ namespace IOUtils {
* *
* @return A promise that resolves to a unique directory name. * @return A promise that resolves to a unique directory name.
*/ */
[NewObject]
Promise<DOMString> createUniqueDirectory(DOMString parent, DOMString prefix, optional unsigned long permissions = 0755); Promise<DOMString> createUniqueDirectory(DOMString parent, DOMString prefix, optional unsigned long permissions = 0755);
#if defined(XP_WIN) #if defined(XP_WIN)
@@ -244,6 +261,7 @@ namespace IOUtils {
* *
* @return A promise that resolves to the Windows-specific file attributes. * @return A promise that resolves to the Windows-specific file attributes.
*/ */
[NewObject]
Promise<WindowsFileAttributes> getWindowsAttributes(DOMString path); Promise<WindowsFileAttributes> getWindowsAttributes(DOMString path);
/** /**
@@ -256,6 +274,7 @@ namespace IOUtils {
* *
* @return A promise that resolves is the attributes were set successfully. * @return A promise that resolves is the attributes were set successfully.
*/ */
[NewObject]
Promise<void> setWindowsAttributes(DOMString path, optional WindowsFileAttributes attrs = {}); Promise<void> setWindowsAttributes(DOMString path, optional WindowsFileAttributes attrs = {});
#elif defined(XP_MACOSX) #elif defined(XP_MACOSX)
/** /**
@@ -267,6 +286,7 @@ namespace IOUtils {
* @return A promise that resolves to whether or not the file has an extended * @return A promise that resolves to whether or not the file has an extended
* attribute, or rejects with an error. * attribute, or rejects with an error.
*/ */
[NewObject]
Promise<boolean> hasMacXAttr(DOMString path, UTF8String attr); Promise<boolean> hasMacXAttr(DOMString path, UTF8String attr);
/** /**
* Return the value of an extended attribute for a file. * Return the value of an extended attribute for a file.
@@ -277,6 +297,7 @@ namespace IOUtils {
* @return A promise that resolves to the value of the extended attribute, or * @return A promise that resolves to the value of the extended attribute, or
* rejects with an error. * rejects with an error.
*/ */
[NewObject]
Promise<Uint8Array> getMacXAttr(DOMString path, UTF8String attr); Promise<Uint8Array> getMacXAttr(DOMString path, UTF8String attr);
/** /**
* Set the extended attribute on a file. * Set the extended attribute on a file.
@@ -288,6 +309,7 @@ namespace IOUtils {
* @return A promise that resolves to whether or not the file has an extended * @return A promise that resolves to whether or not the file has an extended
* attribute, or rejects with an error. * attribute, or rejects with an error.
*/ */
[NewObject]
Promise<void> setMacXAttr(DOMString path, UTF8String attr, Uint8Array value); Promise<void> setMacXAttr(DOMString path, UTF8String attr, Uint8Array value);
/** /**
* Delete the extended attribute on a file. * Delete the extended attribute on a file.
@@ -298,6 +320,7 @@ namespace IOUtils {
* @return A promise that resolves if the attribute was deleted, or rejects * @return A promise that resolves if the attribute was deleted, or rejects
* with an error. * with an error.
*/ */
[NewObject]
Promise<void> delMacXAttr(DOMString path, UTF8String attr); Promise<void> delMacXAttr(DOMString path, UTF8String attr);
#endif #endif
}; };

View File

@@ -144,6 +144,7 @@ interface FluentBundleIterator {
[LegacyNoInterfaceObject, Exposed=Window] [LegacyNoInterfaceObject, Exposed=Window]
interface FluentBundleAsyncIterator { interface FluentBundleAsyncIterator {
[NewObject]
Promise<FluentBundleIteratorResult> next(); Promise<FluentBundleIteratorResult> next();
[Alias="@@asyncIterator"] FluentBundleAsyncIterator values(); [Alias="@@asyncIterator"] FluentBundleAsyncIterator values();
}; };

View File

@@ -111,7 +111,7 @@ already_AddRefed<Promise> CredentialsContainer::Get(
} }
EnsureWebAuthnManager(); EnsureWebAuthnManager();
return mManager->GetAssertion(aOptions.mPublicKey, aOptions.mSignal); return mManager->GetAssertion(aOptions.mPublicKey, aOptions.mSignal, aRv);
} }
already_AddRefed<Promise> CredentialsContainer::Create( already_AddRefed<Promise> CredentialsContainer::Create(
@@ -121,7 +121,7 @@ already_AddRefed<Promise> CredentialsContainer::Create(
} }
EnsureWebAuthnManager(); EnsureWebAuthnManager();
return mManager->MakeCredential(aOptions.mPublicKey, aOptions.mSignal); return mManager->MakeCredential(aOptions.mPublicKey, aOptions.mSignal, aRv);
} }
already_AddRefed<Promise> CredentialsContainer::Store( already_AddRefed<Promise> CredentialsContainer::Store(
@@ -131,7 +131,7 @@ already_AddRefed<Promise> CredentialsContainer::Store(
} }
EnsureWebAuthnManager(); EnsureWebAuthnManager();
return mManager->Store(aCredential); return mManager->Store(aCredential, aRv);
} }
already_AddRefed<Promise> CredentialsContainer::PreventSilentAccess( already_AddRefed<Promise> CredentialsContainer::PreventSilentAccess(

View File

@@ -47,11 +47,10 @@ FileSystemDirectoryHandle::Values() {
} }
already_AddRefed<Promise> FileSystemDirectoryHandle::GetFileHandle( already_AddRefed<Promise> FileSystemDirectoryHandle::GetFileHandle(
const nsAString& aName, const FileSystemGetFileOptions& aOptions) { const nsAString& aName, const FileSystemGetFileOptions& aOptions,
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -61,11 +60,10 @@ already_AddRefed<Promise> FileSystemDirectoryHandle::GetFileHandle(
} }
already_AddRefed<Promise> FileSystemDirectoryHandle::GetDirectoryHandle( already_AddRefed<Promise> FileSystemDirectoryHandle::GetDirectoryHandle(
const nsAString& aName, const FileSystemGetDirectoryOptions& aOptions) { const nsAString& aName, const FileSystemGetDirectoryOptions& aOptions,
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -75,11 +73,10 @@ already_AddRefed<Promise> FileSystemDirectoryHandle::GetDirectoryHandle(
} }
already_AddRefed<Promise> FileSystemDirectoryHandle::RemoveEntry( already_AddRefed<Promise> FileSystemDirectoryHandle::RemoveEntry(
const nsAString& aName, const FileSystemRemoveOptions& aOptions) { const nsAString& aName, const FileSystemRemoveOptions& aOptions,
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -89,11 +86,9 @@ already_AddRefed<Promise> FileSystemDirectoryHandle::RemoveEntry(
} }
already_AddRefed<Promise> FileSystemDirectoryHandle::Resolve( already_AddRefed<Promise> FileSystemDirectoryHandle::Resolve(
FileSystemHandle& aPossibleDescendant) { FileSystemHandle& aPossibleDescendant, ErrorResult& aError) {
IgnoredErrorResult rv; RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
if (aError.Failed()) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -9,7 +9,11 @@
#include "mozilla/dom/FileSystemHandle.h" #include "mozilla/dom/FileSystemHandle.h"
namespace mozilla::dom { namespace mozilla {
class ErrorResult;
namespace dom {
class FileSystemDirectoryIterator; class FileSystemDirectoryIterator;
struct FileSystemGetFileOptions; struct FileSystemGetFileOptions;
@@ -36,20 +40,25 @@ class FileSystemDirectoryHandle final : public FileSystemHandle {
[[nodiscard]] already_AddRefed<FileSystemDirectoryIterator> Values(); [[nodiscard]] already_AddRefed<FileSystemDirectoryIterator> Values();
already_AddRefed<Promise> GetFileHandle( already_AddRefed<Promise> GetFileHandle(
const nsAString& aName, const FileSystemGetFileOptions& aOptions); const nsAString& aName, const FileSystemGetFileOptions& aOptions,
ErrorResult& aError);
already_AddRefed<Promise> GetDirectoryHandle( already_AddRefed<Promise> GetDirectoryHandle(
const nsAString& aName, const FileSystemGetDirectoryOptions& aOptions); const nsAString& aName, const FileSystemGetDirectoryOptions& aOptions,
ErrorResult& aError);
already_AddRefed<Promise> RemoveEntry( already_AddRefed<Promise> RemoveEntry(const nsAString& aName,
const nsAString& aName, const FileSystemRemoveOptions& aOptions); const FileSystemRemoveOptions& aOptions,
ErrorResult& aError);
already_AddRefed<Promise> Resolve(FileSystemHandle& aPossibleDescendant); already_AddRefed<Promise> Resolve(FileSystemHandle& aPossibleDescendant,
ErrorResult& aError);
private: private:
~FileSystemDirectoryHandle() = default; ~FileSystemDirectoryHandle() = default;
}; };
} // namespace mozilla::dom } // namespace dom
} // namespace mozilla
#endif // DOM_FS_FILESYSTEMDIRECTORYHANDLE_H_ #endif // DOM_FS_FILESYSTEMDIRECTORYHANDLE_H_

View File

@@ -37,11 +37,10 @@ JSObject* FileSystemDirectoryIterator::WrapObject(
// WebIDL Interface // WebIDL Interface
already_AddRefed<Promise> FileSystemDirectoryIterator::Next() { already_AddRefed<Promise> FileSystemDirectoryIterator::Next(
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -13,7 +13,11 @@
class nsIGlobalObject; class nsIGlobalObject;
namespace mozilla::dom { namespace mozilla {
class ErrorResult;
namespace dom {
class Promise; class Promise;
@@ -31,7 +35,7 @@ class FileSystemDirectoryIterator : public nsISupports, public nsWrapperCache {
JS::Handle<JSObject*> aGivenProto) override; JS::Handle<JSObject*> aGivenProto) override;
// WebIDL Interface // WebIDL Interface
already_AddRefed<Promise> Next(); already_AddRefed<Promise> Next(ErrorResult& aError);
protected: protected:
virtual ~FileSystemDirectoryIterator() = default; virtual ~FileSystemDirectoryIterator() = default;
@@ -39,6 +43,7 @@ class FileSystemDirectoryIterator : public nsISupports, public nsWrapperCache {
nsCOMPtr<nsIGlobalObject> mGlobal; nsCOMPtr<nsIGlobalObject> mGlobal;
}; };
} // namespace mozilla::dom } // namespace dom
} // namespace mozilla
#endif // DOM_FS_FILESYSTEMDIRECTORYITERATOR_H_ #endif // DOM_FS_FILESYSTEMDIRECTORYITERATOR_H_

View File

@@ -30,11 +30,9 @@ FileSystemHandleKind FileSystemFileHandle::Kind() {
return FileSystemHandleKind::File; return FileSystemHandleKind::File;
} }
already_AddRefed<Promise> FileSystemFileHandle::GetFile() { already_AddRefed<Promise> FileSystemFileHandle::GetFile(ErrorResult& aError) {
IgnoredErrorResult rv; RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
if (aError.Failed()) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -44,11 +42,9 @@ already_AddRefed<Promise> FileSystemFileHandle::GetFile() {
} }
already_AddRefed<Promise> FileSystemFileHandle::CreateWritable( already_AddRefed<Promise> FileSystemFileHandle::CreateWritable(
const FileSystemCreateWritableOptions& aOptions) { const FileSystemCreateWritableOptions& aOptions, ErrorResult& aError) {
IgnoredErrorResult rv; RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
if (aError.Failed()) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -57,11 +53,10 @@ already_AddRefed<Promise> FileSystemFileHandle::CreateWritable(
return promise.forget(); return promise.forget();
} }
already_AddRefed<Promise> FileSystemFileHandle::CreateSyncAccessHandle() { already_AddRefed<Promise> FileSystemFileHandle::CreateSyncAccessHandle(
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -9,7 +9,11 @@
#include "mozilla/dom/FileSystemHandle.h" #include "mozilla/dom/FileSystemHandle.h"
namespace mozilla::dom { namespace mozilla {
class ErrorResult;
namespace dom {
struct FileSystemCreateWritableOptions; struct FileSystemCreateWritableOptions;
@@ -26,17 +30,18 @@ class FileSystemFileHandle final : public FileSystemHandle {
// WebIDL interface // WebIDL interface
FileSystemHandleKind Kind() override; FileSystemHandleKind Kind() override;
already_AddRefed<Promise> GetFile(); already_AddRefed<Promise> GetFile(ErrorResult& aError);
already_AddRefed<Promise> CreateWritable( already_AddRefed<Promise> CreateWritable(
const FileSystemCreateWritableOptions& aOptions); const FileSystemCreateWritableOptions& aOptions, ErrorResult& aError);
already_AddRefed<Promise> CreateSyncAccessHandle(); already_AddRefed<Promise> CreateSyncAccessHandle(ErrorResult& aError);
private: private:
~FileSystemFileHandle() = default; ~FileSystemFileHandle() = default;
}; };
} // namespace mozilla::dom } // namespace dom
} // namespace mozilla
#endif // DOM_FS_FILESYSTEMFILEHANDLE_H_ #endif // DOM_FS_FILESYSTEMFILEHANDLE_H_

View File

@@ -34,11 +34,9 @@ JSObject* FileSystemHandle::WrapObject(JSContext* aCx,
void FileSystemHandle::GetName(DOMString& aResult) { aResult.SetNull(); } void FileSystemHandle::GetName(DOMString& aResult) { aResult.SetNull(); }
already_AddRefed<Promise> FileSystemHandle::IsSameEntry( already_AddRefed<Promise> FileSystemHandle::IsSameEntry(
FileSystemHandle& aOther) { FileSystemHandle& aOther, ErrorResult& aError) {
IgnoredErrorResult rv; RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
if (aError.Failed()) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -13,7 +13,11 @@
class nsIGlobalObject; class nsIGlobalObject;
namespace mozilla::dom { namespace mozilla {
class ErrorResult;
namespace dom {
class DOMString; class DOMString;
enum class FileSystemHandleKind : uint8_t; enum class FileSystemHandleKind : uint8_t;
@@ -35,7 +39,8 @@ class FileSystemHandle : public nsISupports, public nsWrapperCache {
void GetName(DOMString& aResult); void GetName(DOMString& aResult);
already_AddRefed<Promise> IsSameEntry(FileSystemHandle& aOther); already_AddRefed<Promise> IsSameEntry(FileSystemHandle& aOther,
ErrorResult& aError);
protected: protected:
virtual ~FileSystemHandle() = default; virtual ~FileSystemHandle() = default;
@@ -43,6 +48,7 @@ class FileSystemHandle : public nsISupports, public nsWrapperCache {
nsCOMPtr<nsIGlobalObject> mGlobal; nsCOMPtr<nsIGlobalObject> mGlobal;
}; };
} // namespace mozilla::dom } // namespace dom
} // namespace mozilla
#endif // DOM_FS_FILESYSTEMHANDLE_H_ #endif // DOM_FS_FILESYSTEMHANDLE_H_

View File

@@ -45,11 +45,10 @@ uint64_t FileSystemSyncAccessHandle::Write(
return 0; return 0;
} }
already_AddRefed<Promise> FileSystemSyncAccessHandle::Truncate(uint64_t aSize) { already_AddRefed<Promise> FileSystemSyncAccessHandle::Truncate(
IgnoredErrorResult rv; uint64_t aSize, ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -58,11 +57,10 @@ already_AddRefed<Promise> FileSystemSyncAccessHandle::Truncate(uint64_t aSize) {
return promise.forget(); return promise.forget();
} }
already_AddRefed<Promise> FileSystemSyncAccessHandle::GetSize() { already_AddRefed<Promise> FileSystemSyncAccessHandle::GetSize(
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -71,11 +69,10 @@ already_AddRefed<Promise> FileSystemSyncAccessHandle::GetSize() {
return promise.forget(); return promise.forget();
} }
already_AddRefed<Promise> FileSystemSyncAccessHandle::Flush() { already_AddRefed<Promise> FileSystemSyncAccessHandle::Flush(
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -84,11 +81,10 @@ already_AddRefed<Promise> FileSystemSyncAccessHandle::Flush() {
return promise.forget(); return promise.forget();
} }
already_AddRefed<Promise> FileSystemSyncAccessHandle::Close() { already_AddRefed<Promise> FileSystemSyncAccessHandle::Close(
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -13,7 +13,11 @@
class nsIGlobalObject; class nsIGlobalObject;
namespace mozilla::dom { namespace mozilla {
class ErrorResult;
namespace dom {
struct FileSystemReadWriteOptions; struct FileSystemReadWriteOptions;
class MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer; class MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer;
@@ -40,13 +44,13 @@ class FileSystemSyncAccessHandle final : public nsISupports,
const MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aBuffer, const MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aBuffer,
const FileSystemReadWriteOptions& aOptions); const FileSystemReadWriteOptions& aOptions);
already_AddRefed<Promise> Truncate(uint64_t aSize); already_AddRefed<Promise> Truncate(uint64_t aSize, ErrorResult& aError);
already_AddRefed<Promise> GetSize(); already_AddRefed<Promise> GetSize(ErrorResult& aError);
already_AddRefed<Promise> Flush(); already_AddRefed<Promise> Flush(ErrorResult& aError);
already_AddRefed<Promise> Close(); already_AddRefed<Promise> Close(ErrorResult& aError);
private: private:
virtual ~FileSystemSyncAccessHandle() = default; virtual ~FileSystemSyncAccessHandle() = default;
@@ -54,6 +58,7 @@ class FileSystemSyncAccessHandle final : public nsISupports,
nsCOMPtr<nsIGlobalObject> mGlobal; nsCOMPtr<nsIGlobalObject> mGlobal;
}; };
} // namespace mozilla::dom } // namespace dom
} // namespace mozilla
#endif // DOM_FS_FILESYSTEMSYNCACCESSHANDLE_H_ #endif // DOM_FS_FILESYSTEMSYNCACCESSHANDLE_H_

View File

@@ -26,11 +26,10 @@ JSObject* FileSystemWritableFileStream::WrapObject(
// WebIDL Interface // WebIDL Interface
already_AddRefed<Promise> FileSystemWritableFileStream::Write( already_AddRefed<Promise> FileSystemWritableFileStream::Write(
const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams& aData) { const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams& aData,
IgnoredErrorResult rv; ErrorResult& aError) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -40,11 +39,9 @@ already_AddRefed<Promise> FileSystemWritableFileStream::Write(
} }
already_AddRefed<Promise> FileSystemWritableFileStream::Seek( already_AddRefed<Promise> FileSystemWritableFileStream::Seek(
uint64_t aPosition) { uint64_t aPosition, ErrorResult& aError) {
IgnoredErrorResult rv; RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
if (aError.Failed()) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -54,11 +51,9 @@ already_AddRefed<Promise> FileSystemWritableFileStream::Seek(
} }
already_AddRefed<Promise> FileSystemWritableFileStream::Truncate( already_AddRefed<Promise> FileSystemWritableFileStream::Truncate(
uint64_t aSize) { uint64_t aSize, ErrorResult& aError) {
IgnoredErrorResult rv; RefPtr<Promise> promise = Promise::Create(GetParentObject(), aError);
if (aError.Failed()) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -9,7 +9,11 @@
#include "mozilla/dom/WritableStream.h" #include "mozilla/dom/WritableStream.h"
namespace mozilla::dom { namespace mozilla {
class ErrorResult;
namespace dom {
class ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams; class ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams;
@@ -25,16 +29,18 @@ class FileSystemWritableFileStream final : public WritableStream {
// WebIDL Interface // WebIDL Interface
already_AddRefed<Promise> Write( already_AddRefed<Promise> Write(
const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams& aData); const ArrayBufferViewOrArrayBufferOrBlobOrUSVStringOrWriteParams& aData,
ErrorResult& aError);
already_AddRefed<Promise> Seek(uint64_t aPosition); already_AddRefed<Promise> Seek(uint64_t aPosition, ErrorResult& aError);
already_AddRefed<Promise> Truncate(uint64_t aSize); already_AddRefed<Promise> Truncate(uint64_t aSize, ErrorResult& aError);
private: private:
~FileSystemWritableFileStream() = default; ~FileSystemWritableFileStream() = default;
}; };
} // namespace mozilla::dom } // namespace dom
} // namespace mozilla
#endif // DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_ #endif // DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_

View File

@@ -103,6 +103,7 @@ already_AddRefed<Promise> GamepadServiceTest::AddGamepad(
uint32_t aNumButtons, uint32_t aNumAxes, uint32_t aNumHaptics, uint32_t aNumButtons, uint32_t aNumAxes, uint32_t aNumHaptics,
uint32_t aNumLightIndicator, uint32_t aNumTouchEvents, ErrorResult& aRv) { uint32_t aNumLightIndicator, uint32_t aNumTouchEvents, ErrorResult& aRv) {
if (mShuttingDown) { if (mShuttingDown) {
aRv.ThrowInvalidStateError("Shutting down");
return nullptr; return nullptr;
} }
@@ -134,6 +135,7 @@ already_AddRefed<Promise> GamepadServiceTest::AddGamepad(
already_AddRefed<Promise> GamepadServiceTest::RemoveGamepad( already_AddRefed<Promise> GamepadServiceTest::RemoveGamepad(
uint32_t aHandleSlot, ErrorResult& aRv) { uint32_t aHandleSlot, ErrorResult& aRv) {
if (mShuttingDown) { if (mShuttingDown) {
aRv.ThrowInvalidStateError("Shutting down");
return nullptr; return nullptr;
} }
@@ -161,6 +163,7 @@ already_AddRefed<Promise> GamepadServiceTest::NewButtonEvent(
uint32_t aHandleSlot, uint32_t aButton, bool aPressed, bool aTouched, uint32_t aHandleSlot, uint32_t aButton, bool aPressed, bool aTouched,
ErrorResult& aRv) { ErrorResult& aRv) {
if (mShuttingDown) { if (mShuttingDown) {
aRv.ThrowInvalidStateError("Shutting down");
return nullptr; return nullptr;
} }
@@ -186,6 +189,7 @@ already_AddRefed<Promise> GamepadServiceTest::NewButtonValueEvent(
uint32_t aHandleSlot, uint32_t aButton, bool aPressed, bool aTouched, uint32_t aHandleSlot, uint32_t aButton, bool aPressed, bool aTouched,
double aValue, ErrorResult& aRv) { double aValue, ErrorResult& aRv) {
if (mShuttingDown) { if (mShuttingDown) {
aRv.ThrowInvalidStateError("Shutting down");
return nullptr; return nullptr;
} }
@@ -210,6 +214,7 @@ already_AddRefed<Promise> GamepadServiceTest::NewButtonValueEvent(
already_AddRefed<Promise> GamepadServiceTest::NewAxisMoveEvent( already_AddRefed<Promise> GamepadServiceTest::NewAxisMoveEvent(
uint32_t aHandleSlot, uint32_t aAxis, double aValue, ErrorResult& aRv) { uint32_t aHandleSlot, uint32_t aAxis, double aValue, ErrorResult& aRv) {
if (mShuttingDown) { if (mShuttingDown) {
aRv.ThrowInvalidStateError("Shutting down");
return nullptr; return nullptr;
} }
@@ -239,6 +244,7 @@ already_AddRefed<Promise> GamepadServiceTest::NewPoseMove(
const Nullable<Float32Array>& aLinVelocity, const Nullable<Float32Array>& aLinVelocity,
const Nullable<Float32Array>& aLinAcceleration, ErrorResult& aRv) { const Nullable<Float32Array>& aLinAcceleration, ErrorResult& aRv) {
if (mShuttingDown) { if (mShuttingDown) {
aRv.ThrowInvalidStateError("Shutting down");
return nullptr; return nullptr;
} }
@@ -322,6 +328,7 @@ already_AddRefed<Promise> GamepadServiceTest::NewTouch(
uint8_t aSurfaceId, const Float32Array& aPos, uint8_t aSurfaceId, const Float32Array& aPos,
const Nullable<Float32Array>& aSurfDim, ErrorResult& aRv) { const Nullable<Float32Array>& aSurfDim, ErrorResult& aRv) {
if (mShuttingDown) { if (mShuttingDown) {
aRv.ThrowInvalidStateError("Shutting down");
return nullptr; return nullptr;
} }

View File

@@ -1112,13 +1112,17 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(PeerConnectionImpl::Operation) NS_IMPL_CYCLE_COLLECTING_ADDREF(PeerConnectionImpl::Operation)
NS_IMPL_CYCLE_COLLECTING_RELEASE(PeerConnectionImpl::Operation) NS_IMPL_CYCLE_COLLECTING_RELEASE(PeerConnectionImpl::Operation)
PeerConnectionImpl::Operation::Operation(PeerConnectionImpl* aPc) PeerConnectionImpl::Operation::Operation(PeerConnectionImpl* aPc,
: mPromise(aPc->MakePromise()), mPc(aPc) {} ErrorResult& aError)
: mPromise(aPc->MakePromise(aError)), mPc(aPc) {}
PeerConnectionImpl::Operation::~Operation() = default; PeerConnectionImpl::Operation::~Operation() = default;
void PeerConnectionImpl::Operation::Call() { void PeerConnectionImpl::Operation::Call(ErrorResult& aError) {
RefPtr<dom::Promise> opPromise = CallImpl(); RefPtr<dom::Promise> opPromise = CallImpl(aError);
if (aError.Failed()) {
return;
}
// Upon fulfillment or rejection of the promise returned by the operation, // Upon fulfillment or rejection of the promise returned by the operation,
// run the following steps: // run the following steps:
// (NOTE: mPromise is p from https://w3c.github.io/webrtc-pc/#dfn-chain, // (NOTE: mPromise is p from https://w3c.github.io/webrtc-pc/#dfn-chain,
@@ -1138,7 +1142,7 @@ void PeerConnectionImpl::Operation::ResolvedCallback(
// steps: // steps:
// (Static analysis forces us to use a temporary) // (Static analysis forces us to use a temporary)
RefPtr<PeerConnectionImpl> pc = mPc; RefPtr<PeerConnectionImpl> pc = mPc;
pc->RunNextOperation(); pc->RunNextOperation(aRv);
} }
} }
@@ -1154,7 +1158,7 @@ void PeerConnectionImpl::Operation::RejectedCallback(
// steps: // steps:
// (Static analysis forces us to use a temporary) // (Static analysis forces us to use a temporary)
RefPtr<PeerConnectionImpl> pc = mPc; RefPtr<PeerConnectionImpl> pc = mPc;
pc->RunNextOperation(); pc->RunNextOperation(aRv);
} }
} }
@@ -1170,21 +1174,29 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PeerConnectionImpl::JSOperation)
NS_INTERFACE_MAP_END_INHERITING(PeerConnectionImpl::Operation) NS_INTERFACE_MAP_END_INHERITING(PeerConnectionImpl::Operation)
PeerConnectionImpl::JSOperation::JSOperation(PeerConnectionImpl* aPc, PeerConnectionImpl::JSOperation::JSOperation(PeerConnectionImpl* aPc,
dom::ChainedOperation& aOp) dom::ChainedOperation& aOp,
: Operation(aPc), mOperation(&aOp) {} ErrorResult& aError)
: Operation(aPc, aError), mOperation(&aOp) {}
RefPtr<dom::Promise> PeerConnectionImpl::JSOperation::CallImpl() { RefPtr<dom::Promise> PeerConnectionImpl::JSOperation::CallImpl(
ErrorResult& aError) {
// Static analysis will not let us call this without a temporary :( // Static analysis will not let us call this without a temporary :(
RefPtr<dom::ChainedOperation> op = mOperation; RefPtr<dom::ChainedOperation> op = mOperation;
return op->Call(); return op->Call(aError);
} }
already_AddRefed<dom::Promise> PeerConnectionImpl::Chain( already_AddRefed<dom::Promise> PeerConnectionImpl::Chain(
dom::ChainedOperation& aOperation) { dom::ChainedOperation& aOperation, ErrorResult& aError) {
MOZ_RELEASE_ASSERT(!mChainingOperation); MOZ_RELEASE_ASSERT(!mChainingOperation);
mChainingOperation = true; mChainingOperation = true;
RefPtr<Operation> operation = new JSOperation(this, aOperation); RefPtr<Operation> operation = new JSOperation(this, aOperation, aError);
RefPtr<Promise> promise = Chain(operation); if (aError.Failed()) {
return nullptr;
}
RefPtr<Promise> promise = Chain(operation, aError);
if (aError.Failed()) {
return nullptr;
}
mChainingOperation = false; mChainingOperation = false;
return promise.forget(); return promise.forget();
} }
@@ -1194,12 +1206,15 @@ already_AddRefed<dom::Promise> PeerConnectionImpl::Chain(
// run _immediately_ (without any Promise.Then!) if the operations chain is // run _immediately_ (without any Promise.Then!) if the operations chain is
// empty. // empty.
already_AddRefed<dom::Promise> PeerConnectionImpl::Chain( already_AddRefed<dom::Promise> PeerConnectionImpl::Chain(
const RefPtr<Operation>& aOperation) { const RefPtr<Operation>& aOperation, ErrorResult& aError) {
// If connection.[[IsClosed]] is true, return a promise rejected with a newly // If connection.[[IsClosed]] is true, return a promise rejected with a newly
// created InvalidStateError. // created InvalidStateError.
if (IsClosed()) { if (IsClosed()) {
CSFLogDebug(LOGTAG, "%s:%d: Peer connection is closed", __FILE__, __LINE__); CSFLogDebug(LOGTAG, "%s:%d: Peer connection is closed", __FILE__, __LINE__);
RefPtr<dom::Promise> error = MakePromise(); RefPtr<dom::Promise> error = MakePromise(aError);
if (aError.Failed()) {
return nullptr;
}
error->MaybeRejectWithInvalidStateError("Peer connection is closed"); error->MaybeRejectWithInvalidStateError("Peer connection is closed");
return error.forget(); return error.forget();
} }
@@ -1209,14 +1224,17 @@ already_AddRefed<dom::Promise> PeerConnectionImpl::Chain(
// If the length of [[Operations]] is exactly 1, execute operation. // If the length of [[Operations]] is exactly 1, execute operation.
if (mOperations.Length() == 1) { if (mOperations.Length() == 1) {
aOperation->Call(); aOperation->Call(aError);
if (aError.Failed()) {
return nullptr;
}
} }
// This is the promise p from https://w3c.github.io/webrtc-pc/#dfn-chain // This is the promise p from https://w3c.github.io/webrtc-pc/#dfn-chain
return do_AddRef(aOperation->GetPromise()); return do_AddRef(aOperation->GetPromise());
} }
void PeerConnectionImpl::RunNextOperation() { void PeerConnectionImpl::RunNextOperation(ErrorResult& aError) {
// If connection.[[IsClosed]] is true, abort these steps. // If connection.[[IsClosed]] is true, abort these steps.
if (IsClosed()) { if (IsClosed()) {
return; return;
@@ -1230,7 +1248,7 @@ void PeerConnectionImpl::RunNextOperation() {
if (mOperations.Length()) { if (mOperations.Length()) {
// Cannot call without a temporary :( // Cannot call without a temporary :(
RefPtr<Operation> op = mOperations[0]; RefPtr<Operation> op = mOperations[0];
op->Call(); op->Call(aError);
return; return;
} }
@@ -1246,14 +1264,10 @@ void PeerConnectionImpl::RunNextOperation() {
UpdateNegotiationNeeded(); UpdateNegotiationNeeded();
} }
already_AddRefed<dom::Promise> PeerConnectionImpl::MakePromise() const { already_AddRefed<dom::Promise> PeerConnectionImpl::MakePromise(
ErrorResult& aError) const {
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow); nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
ErrorResult rv; return dom::Promise::Create(global, aError);
RefPtr<dom::Promise> result = dom::Promise::Create(global, rv);
if (NS_WARN_IF(rv.Failed())) {
rv.StealNSResult();
}
return result.forget();
} }
void PeerConnectionImpl::UpdateNegotiationNeeded() { void PeerConnectionImpl::UpdateNegotiationNeeded() {

View File

@@ -403,9 +403,9 @@ class PeerConnectionImpl final
public: public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(Operation) NS_DECL_CYCLE_COLLECTION_CLASS(Operation)
explicit Operation(PeerConnectionImpl* aPc); Operation(PeerConnectionImpl* aPc, ErrorResult& aError);
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
void Call(); void Call(ErrorResult& aError);
dom::Promise* GetPromise() { return mPromise; } dom::Promise* GetPromise() { return mPromise; }
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue, void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
@@ -417,7 +417,7 @@ class PeerConnectionImpl final
protected: protected:
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
virtual RefPtr<dom::Promise> CallImpl() = 0; virtual RefPtr<dom::Promise> CallImpl(ErrorResult& aError) = 0;
virtual ~Operation(); virtual ~Operation();
// This is the promise p from https://w3c.github.io/webrtc-pc/#dfn-chain // This is the promise p from https://w3c.github.io/webrtc-pc/#dfn-chain
// This will be a content promise, since we return this to the caller of // This will be a content promise, since we return this to the caller of
@@ -428,22 +428,25 @@ class PeerConnectionImpl final
class JSOperation final : public Operation { class JSOperation final : public Operation {
public: public:
explicit JSOperation(PeerConnectionImpl* aPc, dom::ChainedOperation& aOp); JSOperation(PeerConnectionImpl* aPc, dom::ChainedOperation& aOp,
ErrorResult& aError);
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JSOperation, Operation) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JSOperation, Operation)
private: private:
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
RefPtr<dom::Promise> CallImpl() override; RefPtr<dom::Promise> CallImpl(ErrorResult& aError) override;
~JSOperation() = default; ~JSOperation() = default;
RefPtr<dom::ChainedOperation> mOperation; RefPtr<dom::ChainedOperation> mOperation;
}; };
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
already_AddRefed<dom::Promise> Chain(dom::ChainedOperation& aOperation); already_AddRefed<dom::Promise> Chain(dom::ChainedOperation& aOperation,
ErrorResult& aError);
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
already_AddRefed<dom::Promise> Chain(const RefPtr<Operation>& aOperation); already_AddRefed<dom::Promise> Chain(const RefPtr<Operation>& aOperation,
already_AddRefed<dom::Promise> MakePromise() const; ErrorResult& aError);
already_AddRefed<dom::Promise> MakePromise(ErrorResult& aError) const;
void UpdateNegotiationNeeded(); void UpdateNegotiationNeeded();
@@ -545,7 +548,7 @@ class PeerConnectionImpl final
const; const;
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
void RunNextOperation(); void RunNextOperation(ErrorResult& aError);
// Timecard used to measure processing time. This should be the first class // Timecard used to measure processing time. This should be the first class
// attribute so that we accurately measure the time required to instantiate // attribute so that we accurately measure the time required to instantiate

View File

@@ -146,12 +146,10 @@ RTCDtlsTransport* RTCRtpReceiver::GetTransport() const {
return mTransceiverImpl->GetDtlsTransport(); return mTransceiverImpl->GetDtlsTransport();
} }
already_AddRefed<Promise> RTCRtpReceiver::GetStats() { already_AddRefed<Promise> RTCRtpReceiver::GetStats(ErrorResult& aError) {
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow); nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
ErrorResult rv; RefPtr<Promise> promise = Promise::Create(global, aError);
RefPtr<Promise> promise = Promise::Create(global, rv); if (NS_WARN_IF(aError.Failed())) {
if (NS_WARN_IF(rv.Failed())) {
rv.StealNSResult();
return nullptr; return nullptr;
} }

View File

@@ -55,7 +55,7 @@ class RTCRtpReceiver : public nsISupports, public nsWrapperCache {
// webidl // webidl
MediaStreamTrack* Track() const { return mTrack; } MediaStreamTrack* Track() const { return mTrack; }
RTCDtlsTransport* GetTransport() const; RTCDtlsTransport* GetTransport() const;
already_AddRefed<Promise> GetStats(); already_AddRefed<Promise> GetStats(ErrorResult& aError);
void GetContributingSources( void GetContributingSources(
nsTArray<dom::RTCRtpContributingSource>& aSources); nsTArray<dom::RTCRtpContributingSource>& aSources);
void GetSynchronizationSources( void GetSynchronizationSources(

View File

@@ -85,8 +85,11 @@ RTCDtlsTransport* RTCRtpSender::GetTransport() const {
RTCDTMFSender* RTCRtpSender::GetDtmf() const { return mDtmf; } RTCDTMFSender* RTCRtpSender::GetDtmf() const { return mDtmf; }
already_AddRefed<Promise> RTCRtpSender::GetStats() { already_AddRefed<Promise> RTCRtpSender::GetStats(ErrorResult& aError) {
RefPtr<Promise> promise = MakePromise(); RefPtr<Promise> promise = MakePromise(aError);
if (aError.Failed()) {
return nullptr;
}
if (NS_WARN_IF(!mPipeline)) { if (NS_WARN_IF(!mPipeline)) {
// TODO(bug 1056433): When we stop nulling this out when the PC is closed // TODO(bug 1056433): When we stop nulling this out when the PC is closed
// (or when the transceiver is stopped), we can remove this code. We // (or when the transceiver is stopped), we can remove this code. We
@@ -391,9 +394,12 @@ nsTArray<RefPtr<dom::RTCStatsPromise>> RTCRtpSender::GetStatsInternal() {
} }
already_AddRefed<Promise> RTCRtpSender::SetParameters( already_AddRefed<Promise> RTCRtpSender::SetParameters(
const dom::RTCRtpParameters& aParameters) { const dom::RTCRtpParameters& aParameters, ErrorResult& aError) {
// TODO(bug 1401592): transaction ids and other spec fixes // TODO(bug 1401592): transaction ids and other spec fixes
RefPtr<dom::Promise> p = MakePromise(); RefPtr<dom::Promise> p = MakePromise(aError);
if (aError.Failed()) {
return nullptr;
}
if (mPc->IsClosed()) { if (mPc->IsClosed()) {
p->MaybeRejectWithInvalidStateError("Peer connection is closed"); p->MaybeRejectWithInvalidStateError("Peer connection is closed");
return p.forget(); return p.forget();
@@ -515,14 +521,15 @@ class ReplaceTrackOperation final : public PeerConnectionImpl::Operation {
public: public:
ReplaceTrackOperation(PeerConnectionImpl* aPc, ReplaceTrackOperation(PeerConnectionImpl* aPc,
const RefPtr<TransceiverImpl>& aTransceiver, const RefPtr<TransceiverImpl>& aTransceiver,
const RefPtr<MediaStreamTrack>& aTrack); const RefPtr<MediaStreamTrack>& aTrack,
ErrorResult& aError);
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ReplaceTrackOperation, NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ReplaceTrackOperation,
PeerConnectionImpl::Operation) PeerConnectionImpl::Operation)
private: private:
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
RefPtr<dom::Promise> CallImpl() override; RefPtr<dom::Promise> CallImpl(ErrorResult& aError) override;
~ReplaceTrackOperation() = default; ~ReplaceTrackOperation() = default;
RefPtr<TransceiverImpl> mTransceiver; RefPtr<TransceiverImpl> mTransceiver;
RefPtr<MediaStreamTrack> mNewTrack; RefPtr<MediaStreamTrack> mNewTrack;
@@ -540,17 +547,20 @@ NS_INTERFACE_MAP_END_INHERITING(PeerConnectionImpl::Operation)
ReplaceTrackOperation::ReplaceTrackOperation( ReplaceTrackOperation::ReplaceTrackOperation(
PeerConnectionImpl* aPc, const RefPtr<TransceiverImpl>& aTransceiver, PeerConnectionImpl* aPc, const RefPtr<TransceiverImpl>& aTransceiver,
const RefPtr<MediaStreamTrack>& aTrack) const RefPtr<MediaStreamTrack>& aTrack, ErrorResult& aError)
: PeerConnectionImpl::Operation(aPc), : PeerConnectionImpl::Operation(aPc, aError),
mTransceiver(aTransceiver), mTransceiver(aTransceiver),
mNewTrack(aTrack) {} mNewTrack(aTrack) {}
RefPtr<dom::Promise> ReplaceTrackOperation::CallImpl() { RefPtr<dom::Promise> ReplaceTrackOperation::CallImpl(ErrorResult& aError) {
RefPtr<RTCRtpSender> sender = mTransceiver->Sender(); RefPtr<RTCRtpSender> sender = mTransceiver->Sender();
// If transceiver.[[Stopped]] is true, return a promise rejected with a newly // If transceiver.[[Stopped]] is true, return a promise rejected with a newly
// created InvalidStateError. // created InvalidStateError.
if (mTransceiver->Stopped()) { if (mTransceiver->Stopped()) {
RefPtr<dom::Promise> error = sender->MakePromise(); RefPtr<dom::Promise> error = sender->MakePromise(aError);
if (aError.Failed()) {
return nullptr;
}
MOZ_LOG(gSenderLog, LogLevel::Debug, MOZ_LOG(gSenderLog, LogLevel::Debug,
("%s Cannot call replaceTrack when transceiver is stopped", ("%s Cannot call replaceTrack when transceiver is stopped",
__FUNCTION__)); __FUNCTION__));
@@ -560,7 +570,10 @@ RefPtr<dom::Promise> ReplaceTrackOperation::CallImpl() {
} }
// Let p be a new promise. // Let p be a new promise.
RefPtr<dom::Promise> p = sender->MakePromise(); RefPtr<dom::Promise> p = sender->MakePromise(aError);
if (aError.Failed()) {
return nullptr;
}
if (!sender->SeamlessTrackSwitch(mNewTrack)) { if (!sender->SeamlessTrackSwitch(mNewTrack)) {
MOZ_LOG(gSenderLog, LogLevel::Info, MOZ_LOG(gSenderLog, LogLevel::Info,
@@ -586,7 +599,7 @@ RefPtr<dom::Promise> ReplaceTrackOperation::CallImpl() {
} }
already_AddRefed<dom::Promise> RTCRtpSender::ReplaceTrack( already_AddRefed<dom::Promise> RTCRtpSender::ReplaceTrack(
dom::MediaStreamTrack* aWithTrack) { dom::MediaStreamTrack* aWithTrack, ErrorResult& aError) {
// If withTrack is non-null and withTrack.kind differs from the transceiver // If withTrack is non-null and withTrack.kind differs from the transceiver
// kind of transceiver, return a promise rejected with a newly created // kind of transceiver, return a promise rejected with a newly created
// TypeError. // TypeError.
@@ -596,7 +609,10 @@ already_AddRefed<dom::Promise> RTCRtpSender::ReplaceTrack(
nsString oldKind; nsString oldKind;
mTransceiverImpl->GetKind(oldKind); mTransceiverImpl->GetKind(oldKind);
if (newKind != oldKind) { if (newKind != oldKind) {
RefPtr<dom::Promise> error = MakePromise(); RefPtr<dom::Promise> error = MakePromise(aError);
if (aError.Failed()) {
return nullptr;
}
error->MaybeRejectWithTypeError( error->MaybeRejectWithTypeError(
"Cannot replaceTrack with a different kind!"); "Cannot replaceTrack with a different kind!");
return error.forget(); return error.forget();
@@ -610,16 +626,20 @@ already_AddRefed<dom::Promise> RTCRtpSender::ReplaceTrack(
// Return the result of chaining the following steps to connection's // Return the result of chaining the following steps to connection's
// operations chain: // operations chain:
RefPtr<PeerConnectionImpl::Operation> op = RefPtr<PeerConnectionImpl::Operation> op =
new ReplaceTrackOperation(mPc, mTransceiverImpl, aWithTrack); new ReplaceTrackOperation(mPc, mTransceiverImpl, aWithTrack, aError);
if (aError.Failed()) {
return nullptr;
}
// Static analysis forces us to use a temporary. // Static analysis forces us to use a temporary.
auto pc = mPc; auto pc = mPc;
return pc->Chain(op); return pc->Chain(op, aError);
} }
nsPIDOMWindowInner* RTCRtpSender::GetParentObject() const { return mWindow; } nsPIDOMWindowInner* RTCRtpSender::GetParentObject() const { return mWindow; }
already_AddRefed<dom::Promise> RTCRtpSender::MakePromise() const { already_AddRefed<dom::Promise> RTCRtpSender::MakePromise(
return mPc->MakePromise(); ErrorResult& aError) const {
return mPc->MakePromise(aError);
} }
bool RTCRtpSender::SeamlessTrackSwitch( bool RTCRtpSender::SeamlessTrackSwitch(

View File

@@ -56,10 +56,11 @@ class RTCRtpSender : public nsISupports, public nsWrapperCache {
RTCDtlsTransport* GetTransport() const; RTCDtlsTransport* GetTransport() const;
RTCDTMFSender* GetDtmf() const; RTCDTMFSender* GetDtmf() const;
MOZ_CAN_RUN_SCRIPT MOZ_CAN_RUN_SCRIPT
already_AddRefed<Promise> ReplaceTrack(MediaStreamTrack* aWithTrack); already_AddRefed<Promise> ReplaceTrack(MediaStreamTrack* aWithTrack,
already_AddRefed<Promise> GetStats(); ErrorResult& aError);
already_AddRefed<Promise> GetStats(ErrorResult& aError);
already_AddRefed<Promise> SetParameters( already_AddRefed<Promise> SetParameters(
const dom::RTCRtpParameters& aParameters); const dom::RTCRtpParameters& aParameters, ErrorResult& aError);
void GetParameters(RTCRtpParameters& aParameters) const; void GetParameters(RTCRtpParameters& aParameters) const;
nsPIDOMWindowInner* GetParentObject() const; nsPIDOMWindowInner* GetParentObject() const;
@@ -79,7 +80,7 @@ class RTCRtpSender : public nsISupports, public nsWrapperCache {
bool HasTrack(const dom::MediaStreamTrack* aTrack) const; bool HasTrack(const dom::MediaStreamTrack* aTrack) const;
bool IsMyPc(const PeerConnectionImpl* aPc) const { return mPc.get() == aPc; } bool IsMyPc(const PeerConnectionImpl* aPc) const { return mPc.get() == aPc; }
RefPtr<MediaPipelineTransmit> GetPipeline() const; RefPtr<MediaPipelineTransmit> GetPipeline() const;
already_AddRefed<dom::Promise> MakePromise() const; already_AddRefed<dom::Promise> MakePromise(ErrorResult& aError) const;
bool SeamlessTrackSwitch(const RefPtr<MediaStreamTrack>& aWithTrack); bool SeamlessTrackSwitch(const RefPtr<MediaStreamTrack>& aWithTrack);
bool SetSenderTrackWithClosedCheck(const RefPtr<MediaStreamTrack>& aTrack); bool SetSenderTrackWithClosedCheck(const RefPtr<MediaStreamTrack>& aTrack);

View File

@@ -139,7 +139,7 @@ bool MIDIPort::SysexEnabled() const {
return mPort->SysexEnabled(); return mPort->SysexEnabled();
} }
already_AddRefed<Promise> MIDIPort::Open() { already_AddRefed<Promise> MIDIPort::Open(ErrorResult& aError) {
LOG("MIDIPort::Open"); LOG("MIDIPort::Open");
MOZ_ASSERT(mPort); MOZ_ASSERT(mPort);
RefPtr<Promise> p; RefPtr<Promise> p;
@@ -147,10 +147,9 @@ already_AddRefed<Promise> MIDIPort::Open() {
p = mOpeningPromise; p = mOpeningPromise;
return p.forget(); return p.forget();
} }
ErrorResult rv;
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(GetOwner()); nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(GetOwner());
p = Promise::Create(go, rv); p = Promise::Create(go, aError);
if (rv.Failed()) { if (aError.Failed()) {
return nullptr; return nullptr;
} }
mOpeningPromise = p; mOpeningPromise = p;
@@ -158,7 +157,7 @@ already_AddRefed<Promise> MIDIPort::Open() {
return p.forget(); return p.forget();
} }
already_AddRefed<Promise> MIDIPort::Close() { already_AddRefed<Promise> MIDIPort::Close(ErrorResult& aError) {
LOG("MIDIPort::Close"); LOG("MIDIPort::Close");
MOZ_ASSERT(mPort); MOZ_ASSERT(mPort);
RefPtr<Promise> p; RefPtr<Promise> p;
@@ -166,10 +165,9 @@ already_AddRefed<Promise> MIDIPort::Close() {
p = mClosingPromise; p = mClosingPromise;
return p.forget(); return p.forget();
} }
ErrorResult rv;
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(GetOwner()); nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(GetOwner());
p = Promise::Create(go, rv); p = Promise::Create(go, aError);
if (rv.Failed()) { if (aError.Failed()) {
return nullptr; return nullptr;
} }
mClosingPromise = p; mClosingPromise = p;

View File

@@ -54,8 +54,8 @@ class MIDIPort : public DOMEventTargetHelper,
MIDIPortDeviceState State() const; MIDIPortDeviceState State() const;
bool SysexEnabled() const; bool SysexEnabled() const;
already_AddRefed<Promise> Open(); already_AddRefed<Promise> Open(ErrorResult& aError);
already_AddRefed<Promise> Close(); already_AddRefed<Promise> Close(ErrorResult& aError);
// MIDIPorts observe the death of their parent MIDIAccess object, and delete // MIDIPorts observe the death of their parent MIDIAccess object, and delete
// their reference accordingly. // their reference accordingly.

View File

@@ -752,11 +752,9 @@ already_AddRefed<Promise> StorageManager::Estimate(ErrorResult& aRv) {
aRv); aRv);
} }
already_AddRefed<Promise> StorageManager::GetDirectory() { already_AddRefed<Promise> StorageManager::GetDirectory(ErrorResult& aRv) {
IgnoredErrorResult rv; RefPtr<Promise> promise = Promise::Create(GetParentObject(), aRv);
if (aRv.Failed()) {
RefPtr<Promise> promise = Promise::Create(GetParentObject(), rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -42,7 +42,7 @@ class StorageManager final : public nsISupports, public nsWrapperCache {
already_AddRefed<Promise> Estimate(ErrorResult& aRv); already_AddRefed<Promise> Estimate(ErrorResult& aRv);
already_AddRefed<Promise> GetDirectory(); already_AddRefed<Promise> GetDirectory(ErrorResult& aRv);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StorageManager) NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StorageManager)

View File

@@ -270,9 +270,10 @@ IOUtils::StateMutex IOUtils::sState{"IOUtils::sState"};
/* static */ /* static */
template <typename Fn> template <typename Fn>
already_AddRefed<Promise> IOUtils::WithPromiseAndState(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::WithPromiseAndState(GlobalObject& aGlobal,
ErrorResult& aError,
Fn aFn) { Fn aFn) {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess()); MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
RefPtr<Promise> promise = CreateJSPromise(aGlobal); RefPtr<Promise> promise = CreateJSPromise(aGlobal, aError);
if (!promise) { if (!promise) {
return nullptr; return nullptr;
} }
@@ -312,8 +313,10 @@ void IOUtils::DispatchAndResolve(IOUtils::EventQueue* aQueue, Promise* aPromise,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::Read(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::Read(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const ReadOptions& aOptions) { const ReadOptions& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -379,8 +382,10 @@ RefPtr<SyncReadFile> IOUtils::OpenFileForSyncReading(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::ReadUTF8(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::ReadUTF8(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const ReadUTF8Options& aOptions) { const ReadUTF8Options& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -395,15 +400,17 @@ already_AddRefed<Promise> IOUtils::ReadUTF8(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::ReadJSON(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::ReadJSON(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const ReadUTF8Options& aOptions) { const ReadUTF8Options& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
RefPtr<StrongWorkerRef> workerRef; RefPtr<StrongWorkerRef> workerRef;
if (!NS_IsMainThread()) { if (!NS_IsMainThread()) {
// We need to manually keep the worker alive until the promise returned by // We need to manually keep the worker alive until the promise
// Dispatch() resolves or rejects. // returned by Dispatch() resolves or rejects.
workerRef = StrongWorkerRef::CreateForcibly( workerRef = StrongWorkerRef::CreateForcibly(
GetCurrentThreadWorkerPrivate(), __func__); GetCurrentThreadWorkerPrivate(), __func__);
} }
@@ -415,7 +422,8 @@ already_AddRefed<Promise> IOUtils::ReadJSON(GlobalObject& aGlobal,
}) })
->Then( ->Then(
GetCurrentSerialEventTarget(), __func__, GetCurrentSerialEventTarget(), __func__,
[workerRef, promise = RefPtr{promise}, file](JsBuffer&& aBuffer) { [workerRef, promise = RefPtr{promise},
file](JsBuffer&& aBuffer) {
AutoJSAPI jsapi; AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(promise->GetGlobalObject()))) { if (NS_WARN_IF(!jsapi.Init(promise->GetGlobalObject()))) {
promise->MaybeRejectWithUnknownError( promise->MaybeRejectWithUnknownError(
@@ -425,7 +433,8 @@ already_AddRefed<Promise> IOUtils::ReadJSON(GlobalObject& aGlobal,
JSContext* cx = jsapi.cx(); JSContext* cx = jsapi.cx();
JS::Rooted<JSString*> jsonStr( JS::Rooted<JSString*> jsonStr(
cx, IOUtils::JsBuffer::IntoString(cx, std::move(aBuffer))); cx,
IOUtils::JsBuffer::IntoString(cx, std::move(aBuffer)));
if (!jsonStr) { if (!jsonStr) {
RejectJSPromise(promise, IOError(NS_ERROR_OUT_OF_MEMORY)); RejectJSPromise(promise, IOError(NS_ERROR_OUT_OF_MEMORY));
return; return;
@@ -462,13 +471,16 @@ already_AddRefed<Promise> IOUtils::ReadJSON(GlobalObject& aGlobal,
already_AddRefed<Promise> IOUtils::Write(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::Write(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const Uint8Array& aData, const Uint8Array& aData,
const WriteOptions& aOptions) { const WriteOptions& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
aData.ComputeState(); aData.ComputeState();
auto buf = Buffer<uint8_t>::CopyFrom(Span(aData.Data(), aData.Length())); auto buf =
Buffer<uint8_t>::CopyFrom(Span(aData.Data(), aData.Length()));
if (buf.isNothing()) { if (buf.isNothing()) {
promise->MaybeRejectWithOperationError( promise->MaybeRejectWithOperationError(
"Out of memory: Could not allocate buffer while writing to file"); "Out of memory: Could not allocate buffer while writing to file");
@@ -492,8 +504,10 @@ already_AddRefed<Promise> IOUtils::Write(GlobalObject& aGlobal,
already_AddRefed<Promise> IOUtils::WriteUTF8(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::WriteUTF8(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aString, const nsACString& aString,
const WriteOptions& aOptions) { const WriteOptions& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -521,8 +535,10 @@ static bool AppendJsonAsUtf8(const char16_t* aData, uint32_t aLen, void* aStr) {
already_AddRefed<Promise> IOUtils::WriteJSON(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::WriteJSON(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
JS::Handle<JS::Value> aValue, JS::Handle<JS::Value> aValue,
const WriteOptions& aOptions) { const WriteOptions& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -549,7 +565,8 @@ already_AddRefed<Promise> IOUtils::WriteJSON(GlobalObject& aGlobal,
JS_ClearPendingException(cx); JS_ClearPendingException(cx);
promise->MaybeReject(exn); promise->MaybeReject(exn);
} else { } else {
RejectJSPromise(promise, RejectJSPromise(
promise,
IOError(NS_ERROR_DOM_UNKNOWN_ERR) IOError(NS_ERROR_DOM_UNKNOWN_ERR)
.WithMessage("Could not serialize object to JSON")); .WithMessage("Could not serialize object to JSON"));
} }
@@ -569,8 +586,10 @@ already_AddRefed<Promise> IOUtils::WriteJSON(GlobalObject& aGlobal,
already_AddRefed<Promise> IOUtils::Move(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::Move(GlobalObject& aGlobal,
const nsAString& aSourcePath, const nsAString& aSourcePath,
const nsAString& aDestPath, const nsAString& aDestPath,
const MoveOptions& aOptions) { const MoveOptions& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> sourceFile = new nsLocalFile(); nsCOMPtr<nsIFile> sourceFile = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(sourceFile, aSourcePath, promise); REJECT_IF_INIT_PATH_FAILED(sourceFile, aSourcePath, promise);
@@ -589,8 +608,10 @@ already_AddRefed<Promise> IOUtils::Move(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::Remove(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::Remove(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const RemoveOptions& aOptions) { const RemoveOptions& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -606,25 +627,29 @@ already_AddRefed<Promise> IOUtils::Remove(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::MakeDirectory( already_AddRefed<Promise> IOUtils::MakeDirectory(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const MakeDirectoryOptions& aOptions) { const MakeDirectoryOptions& aOptions, ErrorResult& aError) {
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
DispatchAndResolve<Ok>( DispatchAndResolve<Ok>(state->mEventQueue, promise,
state->mEventQueue, promise, [file = std::move(file),
[file = std::move(file), createAncestors = aOptions.mCreateAncestors, createAncestors = aOptions.mCreateAncestors,
ignoreExisting = aOptions.mIgnoreExisting, ignoreExisting = aOptions.mIgnoreExisting,
permissions = aOptions.mPermissions]() { permissions = aOptions.mPermissions]() {
return MakeDirectorySync(file, createAncestors, ignoreExisting, return MakeDirectorySync(file, createAncestors,
ignoreExisting,
permissions); permissions);
}); });
}); });
} }
already_AddRefed<Promise> IOUtils::Stat(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::Stat(GlobalObject& aGlobal,
const nsAString& aPath) { const nsAString& aPath,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -638,8 +663,10 @@ already_AddRefed<Promise> IOUtils::Stat(GlobalObject& aGlobal,
already_AddRefed<Promise> IOUtils::Copy(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::Copy(GlobalObject& aGlobal,
const nsAString& aSourcePath, const nsAString& aSourcePath,
const nsAString& aDestPath, const nsAString& aDestPath,
const CopyOptions& aOptions) { const CopyOptions& aOptions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> sourceFile = new nsLocalFile(); nsCOMPtr<nsIFile> sourceFile = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(sourceFile, aSourcePath, promise); REJECT_IF_INIT_PATH_FAILED(sourceFile, aSourcePath, promise);
@@ -659,8 +686,9 @@ already_AddRefed<Promise> IOUtils::Copy(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::SetModificationTime( already_AddRefed<Promise> IOUtils::SetModificationTime(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const Optional<int64_t>& aModification) { const Optional<int64_t>& aModification, ErrorResult& aError) {
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -668,8 +696,8 @@ already_AddRefed<Promise> IOUtils::SetModificationTime(
if (aModification.WasPassed()) { if (aModification.WasPassed()) {
newTime = Some(aModification.Value()); newTime = Some(aModification.Value());
} }
DispatchAndResolve<int64_t>(state->mEventQueue, promise, DispatchAndResolve<int64_t>(
[file = std::move(file), newTime]() { state->mEventQueue, promise, [file = std::move(file), newTime]() {
return SetModificationTimeSync(file, newTime); return SetModificationTimeSync(file, newTime);
}); });
}); });
@@ -678,8 +706,9 @@ already_AddRefed<Promise> IOUtils::SetModificationTime(
/* static */ /* static */
already_AddRefed<Promise> IOUtils::GetChildren( already_AddRefed<Promise> IOUtils::GetChildren(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const GetChildrenOptions& aOptions) { const GetChildrenOptions& aOptions, ErrorResult& aError) {
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -695,8 +724,10 @@ already_AddRefed<Promise> IOUtils::GetChildren(
already_AddRefed<Promise> IOUtils::SetPermissions(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::SetPermissions(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
uint32_t aPermissions, uint32_t aPermissions,
const bool aHonorUmask) { const bool aHonorUmask,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
#if defined(XP_UNIX) && !defined(ANDROID) #if defined(XP_UNIX) && !defined(ANDROID)
if (aHonorUmask) { if (aHonorUmask) {
aPermissions &= ~nsSystemInfo::gUserUmask; aPermissions &= ~nsSystemInfo::gUserUmask;
@@ -716,8 +747,10 @@ already_AddRefed<Promise> IOUtils::SetPermissions(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::Exists(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::Exists(GlobalObject& aGlobal,
const nsAString& aPath) { const nsAString& aPath,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -728,19 +761,21 @@ already_AddRefed<Promise> IOUtils::Exists(GlobalObject& aGlobal,
} }
/* static */ /* static */
already_AddRefed<Promise> IOUtils::CreateUniqueFile( already_AddRefed<Promise> IOUtils::CreateUniqueFile(GlobalObject& aGlobal,
GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix, const nsAString& aParent,
const uint32_t aPermissions) { const nsAString& aPrefix,
const uint32_t aPermissions,
ErrorResult& aError) {
return CreateUnique(aGlobal, aParent, aPrefix, nsIFile::NORMAL_FILE_TYPE, return CreateUnique(aGlobal, aParent, aPrefix, nsIFile::NORMAL_FILE_TYPE,
aPermissions); aPermissions, aError);
} }
/* static */ /* static */
already_AddRefed<Promise> IOUtils::CreateUniqueDirectory( already_AddRefed<Promise> IOUtils::CreateUniqueDirectory(
GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix, GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix,
const uint32_t aPermissions) { const uint32_t aPermissions, ErrorResult& aError) {
return CreateUnique(aGlobal, aParent, aPrefix, nsIFile::DIRECTORY_TYPE, return CreateUnique(aGlobal, aParent, aPrefix, nsIFile::DIRECTORY_TYPE,
aPermissions); aPermissions, aError);
} }
/* static */ /* static */
@@ -748,15 +783,17 @@ already_AddRefed<Promise> IOUtils::CreateUnique(GlobalObject& aGlobal,
const nsAString& aParent, const nsAString& aParent,
const nsAString& aPrefix, const nsAString& aPrefix,
const uint32_t aFileType, const uint32_t aFileType,
const uint32_t aPermissions) { const uint32_t aPermissions,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aParent, promise); REJECT_IF_INIT_PATH_FAILED(file, aParent, promise);
if (nsresult rv = file->Append(aPrefix); NS_FAILED(rv)) { if (nsresult rv = file->Append(aPrefix); NS_FAILED(rv)) {
RejectJSPromise( RejectJSPromise(promise,
promise, IOError(rv).WithMessage(
IOError(rv).WithMessage("Could not append prefix `%s' to parent `%s'", "Could not append prefix `%s' to parent `%s'",
NS_ConvertUTF16toUTF8(aPrefix).get(), NS_ConvertUTF16toUTF8(aPrefix).get(),
file->HumanReadablePath().get())); file->HumanReadablePath().get()));
return; return;
@@ -773,16 +810,18 @@ already_AddRefed<Promise> IOUtils::CreateUnique(GlobalObject& aGlobal,
#if defined(XP_WIN) #if defined(XP_WIN)
/* static */ /* static */
already_AddRefed<Promise> IOUtils::GetWindowsAttributes( already_AddRefed<Promise> IOUtils::GetWindowsAttributes(GlobalObject& aGlobal,
GlobalObject& aGlobal, const nsAString& aPath) { const nsAString& aPath,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
RefPtr<StrongWorkerRef> workerRef; RefPtr<StrongWorkerRef> workerRef;
if (!NS_IsMainThread()) { if (!NS_IsMainThread()) {
// We need to manually keep the worker alive until the promise returned by // We need to manually keep the worker alive until the promise
// Dispatch() resolves or rejects. // returned by Dispatch() resolves or rejects.
workerRef = StrongWorkerRef::CreateForcibly( workerRef = StrongWorkerRef::CreateForcibly(
GetCurrentThreadWorkerPrivate(), __func__); GetCurrentThreadWorkerPrivate(), __func__);
} }
@@ -811,8 +850,9 @@ already_AddRefed<Promise> IOUtils::GetWindowsAttributes(
/* static */ /* static */
already_AddRefed<Promise> IOUtils::SetWindowsAttributes( already_AddRefed<Promise> IOUtils::SetWindowsAttributes(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const WindowsFileAttributes& aAttrs) { const WindowsFileAttributes& aAttrs, ErrorResult& aError) {
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -843,10 +883,10 @@ already_AddRefed<Promise> IOUtils::SetWindowsAttributes(
} }
} }
DispatchAndResolve<Ok>(state->mEventQueue, promise, DispatchAndResolve<Ok>(
state->mEventQueue, promise,
[file = std::move(file), setAttrs, clearAttrs]() { [file = std::move(file), setAttrs, clearAttrs]() {
return SetWindowsAttributesSync(file, setAttrs, return SetWindowsAttributesSync(file, setAttrs, clearAttrs);
clearAttrs);
}); });
}); });
} }
@@ -856,8 +896,10 @@ already_AddRefed<Promise> IOUtils::SetWindowsAttributes(
/* static */ /* static */
already_AddRefed<Promise> IOUtils::HasMacXAttr(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::HasMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr) { const nsACString& aAttr,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -872,8 +914,10 @@ already_AddRefed<Promise> IOUtils::HasMacXAttr(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::GetMacXAttr(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::GetMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr) { const nsACString& aAttr,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -889,8 +933,10 @@ already_AddRefed<Promise> IOUtils::GetMacXAttr(GlobalObject& aGlobal,
already_AddRefed<Promise> IOUtils::SetMacXAttr(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::SetMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr, const nsACString& aAttr,
const Uint8Array& aValue) { const Uint8Array& aValue,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
@@ -917,12 +963,15 @@ already_AddRefed<Promise> IOUtils::SetMacXAttr(GlobalObject& aGlobal,
/* static */ /* static */
already_AddRefed<Promise> IOUtils::DelMacXAttr(GlobalObject& aGlobal, already_AddRefed<Promise> IOUtils::DelMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr) { const nsACString& aAttr,
return WithPromiseAndState(aGlobal, [&](Promise* promise, auto& state) { ErrorResult& aError) {
return WithPromiseAndState(
aGlobal, aError, [&](Promise* promise, auto& state) {
nsCOMPtr<nsIFile> file = new nsLocalFile(); nsCOMPtr<nsIFile> file = new nsLocalFile();
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise); REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
DispatchAndResolve<Ok>(state->mEventQueue, promise, DispatchAndResolve<Ok>(
state->mEventQueue, promise,
[file = std::move(file), attr = nsCString(aAttr)] { [file = std::move(file), attr = nsCString(aAttr)] {
return DelMacXAttrSync(file, attr); return DelMacXAttrSync(file, attr);
}); });
@@ -932,11 +981,11 @@ already_AddRefed<Promise> IOUtils::DelMacXAttr(GlobalObject& aGlobal,
#endif #endif
/* static */ /* static */
already_AddRefed<Promise> IOUtils::CreateJSPromise(GlobalObject& aGlobal) { already_AddRefed<Promise> IOUtils::CreateJSPromise(GlobalObject& aGlobal,
ErrorResult er; ErrorResult& aError) {
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports()); nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
RefPtr<Promise> promise = Promise::Create(global, er); RefPtr<Promise> promise = Promise::Create(global, aError);
if (er.Failed()) { if (aError.Failed()) {
return nullptr; return nullptr;
} }
MOZ_ASSERT(promise); MOZ_ASSERT(promise);

View File

@@ -62,74 +62,88 @@ class IOUtils final {
static already_AddRefed<Promise> Read(GlobalObject& aGlobal, static already_AddRefed<Promise> Read(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const ReadOptions& aOptions); const ReadOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> ReadUTF8(GlobalObject& aGlobal, static already_AddRefed<Promise> ReadUTF8(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const ReadUTF8Options& aOptions); const ReadUTF8Options& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> ReadJSON(GlobalObject& aGlobal, static already_AddRefed<Promise> ReadJSON(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const ReadUTF8Options& aOptions); const ReadUTF8Options& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> Write(GlobalObject& aGlobal, static already_AddRefed<Promise> Write(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const Uint8Array& aData, const Uint8Array& aData,
const WriteOptions& aOptions); const WriteOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> WriteUTF8(GlobalObject& aGlobal, static already_AddRefed<Promise> WriteUTF8(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aString, const nsACString& aString,
const WriteOptions& aOptions); const WriteOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> WriteJSON(GlobalObject& aGlobal, static already_AddRefed<Promise> WriteJSON(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
JS::Handle<JS::Value> aValue, JS::Handle<JS::Value> aValue,
const WriteOptions& aOptions); const WriteOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> Move(GlobalObject& aGlobal, static already_AddRefed<Promise> Move(GlobalObject& aGlobal,
const nsAString& aSourcePath, const nsAString& aSourcePath,
const nsAString& aDestPath, const nsAString& aDestPath,
const MoveOptions& aOptions); const MoveOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> Remove(GlobalObject& aGlobal, static already_AddRefed<Promise> Remove(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const RemoveOptions& aOptions); const RemoveOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> MakeDirectory( static already_AddRefed<Promise> MakeDirectory(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const MakeDirectoryOptions& aOptions); const MakeDirectoryOptions& aOptions, ErrorResult& aError);
static already_AddRefed<Promise> Stat(GlobalObject& aGlobal, static already_AddRefed<Promise> Stat(GlobalObject& aGlobal,
const nsAString& aPath); const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<Promise> Copy(GlobalObject& aGlobal, static already_AddRefed<Promise> Copy(GlobalObject& aGlobal,
const nsAString& aSourcePath, const nsAString& aSourcePath,
const nsAString& aDestPath, const nsAString& aDestPath,
const CopyOptions& aOptions); const CopyOptions& aOptions,
ErrorResult& aError);
static already_AddRefed<Promise> SetModificationTime( static already_AddRefed<Promise> SetModificationTime(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const Optional<int64_t>& aModification); const Optional<int64_t>& aModification, ErrorResult& aError);
static already_AddRefed<Promise> GetChildren( static already_AddRefed<Promise> GetChildren(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const GetChildrenOptions& aOptions); const GetChildrenOptions& aOptions, ErrorResult& aError);
static already_AddRefed<Promise> SetPermissions(GlobalObject& aGlobal, static already_AddRefed<Promise> SetPermissions(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
uint32_t aPermissions, uint32_t aPermissions,
const bool aHonorUmask); const bool aHonorUmask,
ErrorResult& aError);
static already_AddRefed<Promise> Exists(GlobalObject& aGlobal, static already_AddRefed<Promise> Exists(GlobalObject& aGlobal,
const nsAString& aPath); const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<Promise> CreateUniqueFile( static already_AddRefed<Promise> CreateUniqueFile(GlobalObject& aGlobal,
GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix, const nsAString& aParent,
const uint32_t aPermissions); const nsAString& aPrefix,
const uint32_t aPermissions,
ErrorResult& aError);
static already_AddRefed<Promise> CreateUniqueDirectory( static already_AddRefed<Promise> CreateUniqueDirectory(
GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix, GlobalObject& aGlobal, const nsAString& aParent, const nsAString& aPrefix,
const uint32_t aPermissions); const uint32_t aPermissions, ErrorResult& aError);
private: private:
/** /**
@@ -139,30 +153,36 @@ class IOUtils final {
const nsAString& aParent, const nsAString& aParent,
const nsAString& aPrefix, const nsAString& aPrefix,
const uint32_t aFileType, const uint32_t aFileType,
const uint32_t aPermissions); const uint32_t aPermissions,
ErrorResult& aError);
public: public:
#if defined(XP_WIN) #if defined(XP_WIN)
static already_AddRefed<Promise> GetWindowsAttributes(GlobalObject& aGlobal, static already_AddRefed<Promise> GetWindowsAttributes(GlobalObject& aGlobal,
const nsAString& aPath); const nsAString& aPath,
ErrorResult& aError);
static already_AddRefed<Promise> SetWindowsAttributes( static already_AddRefed<Promise> SetWindowsAttributes(
GlobalObject& aGlobal, const nsAString& aPath, GlobalObject& aGlobal, const nsAString& aPath,
const mozilla::dom::WindowsFileAttributes& aAttrs); const mozilla::dom::WindowsFileAttributes& aAttrs, ErrorResult& aError);
#elif defined(XP_MACOSX) #elif defined(XP_MACOSX)
static already_AddRefed<Promise> HasMacXAttr(GlobalObject& aGlobal, static already_AddRefed<Promise> HasMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr); const nsACString& aAttr,
ErrorResult& aError);
static already_AddRefed<Promise> GetMacXAttr(GlobalObject& aGlobal, static already_AddRefed<Promise> GetMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr); const nsACString& aAttr,
ErrorResult& aError);
static already_AddRefed<Promise> SetMacXAttr(GlobalObject& aGlobal, static already_AddRefed<Promise> SetMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr, const nsACString& aAttr,
const Uint8Array& aValue); const Uint8Array& aValue,
ErrorResult& aError);
static already_AddRefed<Promise> DelMacXAttr(GlobalObject& aGlobal, static already_AddRefed<Promise> DelMacXAttr(GlobalObject& aGlobal,
const nsAString& aPath, const nsAString& aPath,
const nsACString& aAttr); const nsACString& aAttr,
ErrorResult& aError);
#endif #endif
static void GetProfileBeforeChange(GlobalObject& aGlobal, static void GetProfileBeforeChange(GlobalObject& aGlobal,
@@ -201,6 +221,7 @@ class IOUtils final {
template <typename Fn> template <typename Fn>
static already_AddRefed<Promise> WithPromiseAndState(GlobalObject& aGlobal, static already_AddRefed<Promise> WithPromiseAndState(GlobalObject& aGlobal,
ErrorResult& aError,
Fn aFn); Fn aFn);
/** /**
@@ -223,7 +244,8 @@ class IOUtils final {
* *
* @return The new promise, or |nullptr| on failure. * @return The new promise, or |nullptr| on failure.
*/ */
static already_AddRefed<Promise> CreateJSPromise(GlobalObject& aGlobal); static already_AddRefed<Promise> CreateJSPromise(GlobalObject& aGlobal,
ErrorResult& aError);
// Allow conversion of |InternalFileInfo| with |ToJSValue|. // Allow conversion of |InternalFileInfo| with |ToJSValue|.
friend bool ToJSValue(JSContext* aCx, friend bool ToJSValue(JSContext* aCx,

View File

@@ -81,15 +81,10 @@ void PublicKeyCredential::SetResponse(RefPtr<AuthenticatorResponse> aResponse) {
/* static */ /* static */
already_AddRefed<Promise> already_AddRefed<Promise>
PublicKeyCredential::IsUserVerifyingPlatformAuthenticatorAvailable( PublicKeyCredential::IsUserVerifyingPlatformAuthenticatorAvailable(
GlobalObject& aGlobal) { GlobalObject& aGlobal, ErrorResult& aError) {
nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aGlobal.Context()); RefPtr<Promise> promise =
if (NS_WARN_IF(!globalObject)) { Promise::Create(xpc::CurrentNativeGlobal(aGlobal.Context()), aError);
return nullptr; if (aError.Failed()) {
}
ErrorResult rv;
RefPtr<Promise> promise = Promise::Create(globalObject, rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -125,16 +120,11 @@ PublicKeyCredential::IsUserVerifyingPlatformAuthenticatorAvailable(
/* static */ /* static */
already_AddRefed<Promise> already_AddRefed<Promise>
PublicKeyCredential::IsExternalCTAP2SecurityKeySupported( PublicKeyCredential::IsExternalCTAP2SecurityKeySupported(GlobalObject& aGlobal,
GlobalObject& aGlobal) { ErrorResult& aError) {
nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aGlobal.Context()); RefPtr<Promise> promise =
if (NS_WARN_IF(!globalObject)) { Promise::Create(xpc::CurrentNativeGlobal(aGlobal.Context()), aError);
return nullptr; if (aError.Failed()) {
}
ErrorResult rv;
RefPtr<Promise> promise = Promise::Create(globalObject, rv);
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -42,10 +42,11 @@ class PublicKeyCredential final : public Credential {
void SetResponse(RefPtr<AuthenticatorResponse>); void SetResponse(RefPtr<AuthenticatorResponse>);
static already_AddRefed<Promise> static already_AddRefed<Promise>
IsUserVerifyingPlatformAuthenticatorAvailable(GlobalObject& aGlobal); IsUserVerifyingPlatformAuthenticatorAvailable(GlobalObject& aGlobal,
ErrorResult& aError);
static already_AddRefed<Promise> IsExternalCTAP2SecurityKeySupported( static already_AddRefed<Promise> IsExternalCTAP2SecurityKeySupported(
GlobalObject& aGlobal); GlobalObject& aGlobal, ErrorResult& aError);
void GetClientExtensionResults( void GetClientExtensionResults(
AuthenticationExtensionsClientOutputs& aResult); AuthenticationExtensionsClientOutputs& aResult);

View File

@@ -223,14 +223,13 @@ WebAuthnManager::~WebAuthnManager() {
already_AddRefed<Promise> WebAuthnManager::MakeCredential( already_AddRefed<Promise> WebAuthnManager::MakeCredential(
const PublicKeyCredentialCreationOptions& aOptions, const PublicKeyCredentialCreationOptions& aOptions,
const Optional<OwningNonNull<AbortSignal>>& aSignal) { const Optional<OwningNonNull<AbortSignal>>& aSignal, ErrorResult& aError) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent); nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent);
ErrorResult rv; RefPtr<Promise> promise = Promise::Create(global, aError);
RefPtr<Promise> promise = Promise::Create(global, rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -256,9 +255,9 @@ already_AddRefed<Promise> WebAuthnManager::MakeCredential(
nsString origin; nsString origin;
nsCString rpId; nsCString rpId;
rv = GetOrigin(mParent, origin, rpId); nsresult rv = GetOrigin(mParent, origin, rpId);
if (NS_WARN_IF(rv.Failed())) { if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(std::move(rv)); promise->MaybeReject(rv);
return promise.forget(); return promise.forget();
} }
@@ -453,14 +452,13 @@ already_AddRefed<Promise> WebAuthnManager::MakeCredential(
already_AddRefed<Promise> WebAuthnManager::GetAssertion( already_AddRefed<Promise> WebAuthnManager::GetAssertion(
const PublicKeyCredentialRequestOptions& aOptions, const PublicKeyCredentialRequestOptions& aOptions,
const Optional<OwningNonNull<AbortSignal>>& aSignal) { const Optional<OwningNonNull<AbortSignal>>& aSignal, ErrorResult& aError) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent); nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent);
ErrorResult rv; RefPtr<Promise> promise = Promise::Create(global, aError);
RefPtr<Promise> promise = Promise::Create(global, rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }
@@ -486,9 +484,9 @@ already_AddRefed<Promise> WebAuthnManager::GetAssertion(
nsString origin; nsString origin;
nsCString rpId; nsCString rpId;
rv = GetOrigin(mParent, origin, rpId); nsresult rv = GetOrigin(mParent, origin, rpId);
if (NS_WARN_IF(rv.Failed())) { if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(std::move(rv)); promise->MaybeReject(rv);
return promise.forget(); return promise.forget();
} }
@@ -535,9 +533,9 @@ already_AddRefed<Promise> WebAuthnManager::GetAssertion(
} }
nsAutoCString clientDataJSON; nsAutoCString clientDataJSON;
nsresult srv = AssembleClientData(origin, challenge, u"webauthn.get"_ns, rv = AssembleClientData(origin, challenge, u"webauthn.get"_ns,
aOptions.mExtensions, clientDataJSON); aOptions.mExtensions, clientDataJSON);
if (NS_WARN_IF(NS_FAILED(srv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR); promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget(); return promise.forget();
} }
@@ -614,8 +612,8 @@ already_AddRefed<Promise> WebAuthnManager::GetAssertion(
} }
// We need the SHA-256 hash of the appId. // We need the SHA-256 hash of the appId.
srv = HashCString(NS_ConvertUTF16toUTF8(appId), appIdHash); rv = HashCString(NS_ConvertUTF16toUTF8(appId), appIdHash);
if (NS_WARN_IF(NS_FAILED(srv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR); promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget(); return promise.forget();
} }
@@ -657,15 +655,14 @@ already_AddRefed<Promise> WebAuthnManager::GetAssertion(
return promise.forget(); return promise.forget();
} }
already_AddRefed<Promise> WebAuthnManager::Store( already_AddRefed<Promise> WebAuthnManager::Store(const Credential& aCredential,
const Credential& aCredential) { ErrorResult& aError) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent); nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent);
ErrorResult rv; RefPtr<Promise> promise = Promise::Create(global, aError);
RefPtr<Promise> promise = Promise::Create(global, rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -85,13 +85,14 @@ class WebAuthnManager final : public WebAuthnManagerBase, public AbortFollower {
already_AddRefed<Promise> MakeCredential( already_AddRefed<Promise> MakeCredential(
const PublicKeyCredentialCreationOptions& aOptions, const PublicKeyCredentialCreationOptions& aOptions,
const Optional<OwningNonNull<AbortSignal>>& aSignal); const Optional<OwningNonNull<AbortSignal>>& aSignal, ErrorResult& aError);
already_AddRefed<Promise> GetAssertion( already_AddRefed<Promise> GetAssertion(
const PublicKeyCredentialRequestOptions& aOptions, const PublicKeyCredentialRequestOptions& aOptions,
const Optional<OwningNonNull<AbortSignal>>& aSignal); const Optional<OwningNonNull<AbortSignal>>& aSignal, ErrorResult& aError);
already_AddRefed<Promise> Store(const Credential& aCredential); already_AddRefed<Promise> Store(const Credential& aCredential,
ErrorResult& aError);
// WebAuthnManagerBase // WebAuthnManagerBase

View File

@@ -319,7 +319,7 @@ partial interface Document {
// Mozilla-internal document extensions specific to error pages. // Mozilla-internal document extensions specific to error pages.
partial interface Document { partial interface Document {
[Func="Document::CallerIsTrustedAboutCertError"] [Func="Document::CallerIsTrustedAboutCertError", NewObject]
Promise<any> addCertException(boolean isTemporary); Promise<any> addCertException(boolean isTemporary);
[Func="Document::CallerIsTrustedAboutHttpsOnlyError"] [Func="Document::CallerIsTrustedAboutHttpsOnlyError"]

View File

@@ -26,10 +26,14 @@ interface FileSystemDirectoryHandle : FileSystemHandle {
FileSystemDirectoryIterator keys(); FileSystemDirectoryIterator keys();
FileSystemDirectoryIterator values(); FileSystemDirectoryIterator values();
[NewObject]
Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {}); Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {});
[NewObject]
Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {}); Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {});
[NewObject]
Promise<void> removeEntry(USVString name, optional FileSystemRemoveOptions options = {}); Promise<void> removeEntry(USVString name, optional FileSystemRemoveOptions options = {});
[NewObject]
Promise<sequence<USVString>?> resolve(FileSystemHandle possibleDescendant); Promise<sequence<USVString>?> resolve(FileSystemHandle possibleDescendant);
}; };

View File

@@ -7,5 +7,6 @@
// a natively supported `async iterable`. // a natively supported `async iterable`.
[Exposed=(Window,Worker), SecureContext, LegacyNoInterfaceObject] [Exposed=(Window,Worker), SecureContext, LegacyNoInterfaceObject]
interface FileSystemDirectoryIterator { interface FileSystemDirectoryIterator {
[NewObject]
Promise<any> next(); Promise<any> next();
}; };

View File

@@ -10,10 +10,12 @@ dictionary FileSystemCreateWritableOptions {
// TODO: Add Serializable // TODO: Add Serializable
[Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"] [Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"]
interface FileSystemFileHandle : FileSystemHandle { interface FileSystemFileHandle : FileSystemHandle {
[NewObject]
Promise<File> getFile(); Promise<File> getFile();
[NewObject]
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {}); Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {});
[Exposed=DedicatedWorker] [Exposed=DedicatedWorker, NewObject]
Promise<FileSystemSyncAccessHandle> createSyncAccessHandle(); Promise<FileSystemSyncAccessHandle> createSyncAccessHandle();
}; };

View File

@@ -14,5 +14,6 @@ interface FileSystemHandle {
readonly attribute FileSystemHandleKind kind; readonly attribute FileSystemHandleKind kind;
readonly attribute USVString name; readonly attribute USVString name;
[NewObject]
Promise<boolean> isSameEntry(FileSystemHandle other); Promise<boolean> isSameEntry(FileSystemHandle other);
}; };

View File

@@ -13,8 +13,12 @@ interface FileSystemSyncAccessHandle {
unsigned long long read(([AllowShared] ArrayBufferView or [AllowShared] ArrayBuffer) buffer, optional FileSystemReadWriteOptions options = {}); unsigned long long read(([AllowShared] ArrayBufferView or [AllowShared] ArrayBuffer) buffer, optional FileSystemReadWriteOptions options = {});
unsigned long long write(([AllowShared] ArrayBufferView or [AllowShared] ArrayBuffer) buffer, optional FileSystemReadWriteOptions options = {}); unsigned long long write(([AllowShared] ArrayBufferView or [AllowShared] ArrayBuffer) buffer, optional FileSystemReadWriteOptions options = {});
[NewObject]
Promise<void> truncate([EnforceRange] unsigned long long size); Promise<void> truncate([EnforceRange] unsigned long long size);
[NewObject]
Promise<unsigned long long> getSize(); Promise<unsigned long long> getSize();
[NewObject]
Promise<void> flush(); Promise<void> flush();
[NewObject]
Promise<void> close(); Promise<void> close();
}; };

View File

@@ -20,7 +20,10 @@ typedef (BufferSource or Blob or USVString or WriteParams) FileSystemWriteChunkT
[Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"] [Exposed=(Window,Worker), SecureContext, Pref="dom.fs.enabled"]
interface FileSystemWritableFileStream : WritableStream { interface FileSystemWritableFileStream : WritableStream {
[NewObject]
Promise<void> write(FileSystemWriteChunkType data); Promise<void> write(FileSystemWriteChunkType data);
[NewObject]
Promise<void> seek(unsigned long long position); Promise<void> seek(unsigned long long position);
[NewObject]
Promise<void> truncate(unsigned long long size); Promise<void> truncate(unsigned long long size);
}; };

View File

@@ -34,7 +34,9 @@ interface MIDIPort : EventTarget {
readonly attribute MIDIPortDeviceState state; readonly attribute MIDIPortDeviceState state;
readonly attribute MIDIPortConnectionState connection; readonly attribute MIDIPortConnectionState connection;
attribute EventHandler onstatechange; attribute EventHandler onstatechange;
[Throws]
Promise<MIDIPort> open(); Promise<MIDIPort> open();
[Throws]
Promise<MIDIPort> close(); Promise<MIDIPort> close();
}; };

View File

@@ -113,6 +113,7 @@ interface PeerConnectionImpl {
unsigned short maxTime, unsigned short maxNum, unsigned short maxTime, unsigned short maxNum,
boolean externalNegotiated, unsigned short stream); boolean externalNegotiated, unsigned short stream);
[Throws]
Promise<any> chain(ChainedOperation op); Promise<any> chain(ChainedOperation op);
void updateNegotiationNeeded(); void updateNegotiationNeeded();

View File

@@ -12,6 +12,7 @@
interface RTCRtpReceiver { interface RTCRtpReceiver {
readonly attribute MediaStreamTrack track; readonly attribute MediaStreamTrack track;
readonly attribute RTCDtlsTransport? transport; readonly attribute RTCDtlsTransport? transport;
[NewObject]
Promise<RTCStatsReport> getStats(); Promise<RTCStatsReport> getStats();
sequence<RTCRtpContributingSource> getContributingSources(); sequence<RTCRtpContributingSource> getContributingSources();
sequence<RTCRtpSynchronizationSource> getSynchronizationSources(); sequence<RTCRtpSynchronizationSource> getSynchronizationSources();

View File

@@ -12,9 +12,12 @@
interface RTCRtpSender { interface RTCRtpSender {
readonly attribute MediaStreamTrack? track; readonly attribute MediaStreamTrack? track;
readonly attribute RTCDtlsTransport? transport; readonly attribute RTCDtlsTransport? transport;
[NewObject]
Promise<void> setParameters (optional RTCRtpParameters parameters = {}); Promise<void> setParameters (optional RTCRtpParameters parameters = {});
RTCRtpParameters getParameters(); RTCRtpParameters getParameters();
[Throws]
Promise<void> replaceTrack(MediaStreamTrack? withTrack); Promise<void> replaceTrack(MediaStreamTrack? withTrack);
[NewObject]
Promise<RTCStatsReport> getStats(); Promise<RTCStatsReport> getStats();
[Pref="media.peerconnection.dtmf.enabled"] [Pref="media.peerconnection.dtmf.enabled"]
readonly attribute RTCDTMFSender? dtmf; readonly attribute RTCDTMFSender? dtmf;

View File

@@ -29,6 +29,6 @@ dictionary StorageEstimate {
[SecureContext] [SecureContext]
partial interface StorageManager { partial interface StorageManager {
[Pref="dom.fs.enabled"] [Pref="dom.fs.enabled", NewObject]
Promise<FileSystemDirectoryHandle> getDirectory(); Promise<FileSystemDirectoryHandle> getDirectory();
}; };

View File

@@ -19,9 +19,9 @@ interface PublicKeyCredential : Credential {
[SecureContext] [SecureContext]
partial interface PublicKeyCredential { partial interface PublicKeyCredential {
static Promise<boolean> isUserVerifyingPlatformAuthenticatorAvailable(); [NewObject] static Promise<boolean> isUserVerifyingPlatformAuthenticatorAvailable();
// isExternalCTAP2SecurityKeySupported is non-standard; see Bug 1526023 // isExternalCTAP2SecurityKeySupported is non-standard; see Bug 1526023
static Promise<boolean> isExternalCTAP2SecurityKeySupported(); [NewObject] static Promise<boolean> isExternalCTAP2SecurityKeySupported();
}; };
[SecureContext, Pref="security.webauth.webauthn", [SecureContext, Pref="security.webauth.webauthn",

View File

@@ -71,10 +71,9 @@ JSObject* FluentBundleAsyncIterator::WrapObject(
return FluentBundleAsyncIterator_Binding::Wrap(aCx, this, aGivenProto); return FluentBundleAsyncIterator_Binding::Wrap(aCx, this, aGivenProto);
} }
already_AddRefed<Promise> FluentBundleAsyncIterator::Next() { already_AddRefed<Promise> FluentBundleAsyncIterator::Next(ErrorResult& aError) {
ErrorResult rv; RefPtr<Promise> promise = Promise::Create(mGlobal, aError);
RefPtr<Promise> promise = Promise::Create(mGlobal, rv); if (aError.Failed()) {
if (rv.Failed()) {
return nullptr; return nullptr;
} }

View File

@@ -37,7 +37,7 @@ class FluentBundleAsyncIterator final : public nsWrapperCache {
nsIGlobalObject* GetParentObject() const { return mGlobal; } nsIGlobalObject* GetParentObject() const { return mGlobal; }
// WebIDL // WebIDL
already_AddRefed<dom::Promise> Next(); already_AddRefed<dom::Promise> Next(ErrorResult& aError);
already_AddRefed<FluentBundleAsyncIterator> Values(); already_AddRefed<FluentBundleAsyncIterator> Values();
protected: protected: