mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:02:44 +00:00 
			
		
		
		
	 b75b7f0c0d
			
		
	
	
		b75b7f0c0d
		
	
	
	
	
		
			
			Callers that are already in a fallible context will now TRY to allocate cells. Callers in infallible contexts get a FIXME.
		
			
				
	
	
		
			61 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibJS/Runtime/Realm.h>
 | |
| #include <LibWeb/Bindings/Intrinsics.h>
 | |
| #include <LibWeb/Bindings/LegacyPlatformObject.h>
 | |
| #include <LibWeb/FileAPI/FileList.h>
 | |
| 
 | |
| namespace Web::FileAPI {
 | |
| 
 | |
| 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();
 | |
| }
 | |
| 
 | |
| FileList::FileList(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)
 | |
|     : Bindings::LegacyPlatformObject(realm)
 | |
|     , m_files(move(files))
 | |
| {
 | |
| }
 | |
| 
 | |
| FileList::~FileList() = default;
 | |
| 
 | |
| JS::ThrowCompletionOr<void> FileList::initialize(JS::Realm& realm)
 | |
| {
 | |
|     MUST_OR_THROW_OOM(Base::initialize(realm));
 | |
|     set_prototype(&Bindings::ensure_web_prototype<Bindings::FileListPrototype>(realm, "FileList"));
 | |
| 
 | |
|     return {};
 | |
| }
 | |
| 
 | |
| // https://w3c.github.io/FileAPI/#dfn-item
 | |
| bool FileList::is_supported_property_index(u32 index) const
 | |
| {
 | |
|     // Supported property indices are the numbers in the range zero to one less than the number of File objects represented by the FileList object.
 | |
|     // If there are no such File objects, then there are no supported property indices.
 | |
|     if (m_files.is_empty())
 | |
|         return false;
 | |
| 
 | |
|     return m_files.size() < index;
 | |
| }
 | |
| 
 | |
| JS::Value FileList::item_value(size_t index) const
 | |
| {
 | |
|     if (index >= m_files.size())
 | |
|         return JS::js_undefined();
 | |
| 
 | |
|     return m_files[index].ptr();
 | |
| }
 | |
| 
 | |
| void FileList::visit_edges(Cell::Visitor& visitor)
 | |
| {
 | |
|     Base::visit_edges(visitor);
 | |
|     for (auto file : m_files)
 | |
|         visitor.visit(file);
 | |
| }
 | |
| 
 | |
| }
 |