浏览代码

LibWeb: Make factory method of FileAPI::FileList fallible

Kenneth Myhra 2 年之前
父节点
当前提交
6688f89ad3

+ 2 - 2
Userland/Libraries/LibWeb/FileAPI/FileList.cpp

@@ -11,9 +11,9 @@
 
 
 namespace Web::FileAPI {
 namespace Web::FileAPI {
 
 
-JS::NonnullGCPtr<FileList> FileList::create(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<FileList>> FileList::create(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)
 {
 {
-    return realm.heap().allocate<FileList>(realm, realm, move(files)).release_allocated_value_but_fixme_should_propagate_errors();
+    return MUST_OR_THROW_OOM(realm.heap().allocate<FileList>(realm, realm, move(files)));
 }
 }
 
 
 FileList::FileList(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)
 FileList::FileList(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)

+ 1 - 1
Userland/Libraries/LibWeb/FileAPI/FileList.h

@@ -17,7 +17,7 @@ class FileList : public Bindings::LegacyPlatformObject {
     WEB_PLATFORM_OBJECT(FileList, Bindings::LegacyPlatformObject);
     WEB_PLATFORM_OBJECT(FileList, Bindings::LegacyPlatformObject);
 
 
 public:
 public:
-    static JS::NonnullGCPtr<FileList> create(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
+    static WebIDL::ExceptionOr<JS::NonnullGCPtr<FileList>> create(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
     virtual ~FileList() override;
     virtual ~FileList() override;
 
 
     // https://w3c.github.io/FileAPI/#dfn-length
     // https://w3c.github.io/FileAPI/#dfn-length

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp

@@ -110,7 +110,7 @@ JS::GCPtr<FileAPI::FileList> HTMLInputElement::files()
         return nullptr;
         return nullptr;
 
 
     if (!m_selected_files)
     if (!m_selected_files)
-        m_selected_files = FileAPI::FileList::create(realm(), {});
+        m_selected_files = FileAPI::FileList::create(realm(), {}).release_value_but_fixme_should_propagate_errors();
     return m_selected_files;
     return m_selected_files;
 }
 }
 
 
@@ -756,7 +756,7 @@ void HTMLInputElement::reset_algorithm()
     m_checked = has_attribute(AttributeNames::checked);
     m_checked = has_attribute(AttributeNames::checked);
 
 
     // empty the list of selected files,
     // empty the list of selected files,
-    m_selected_files = FileAPI::FileList::create(realm(), {});
+    m_selected_files = FileAPI::FileList::create(realm(), {}).release_value_but_fixme_should_propagate_errors();
 
 
     // and then invoke the value sanitization algorithm, if the type attribute's current state defines one.
     // and then invoke the value sanitization algorithm, if the type attribute's current state defines one.
     m_value = value_sanitization_algorithm(m_value);
     m_value = value_sanitization_algorithm(m_value);