2015-07-22 19:03:07 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
#include "mozilla/dom/Directory.h"
|
2015-07-22 19:03:07 +03:00
|
|
|
#include "mozilla/dom/FileList.h"
|
|
|
|
#include "mozilla/dom/FileListBinding.h"
|
2015-09-29 07:31:56 +03:00
|
|
|
#include "mozilla/dom/File.h"
|
2015-07-22 19:03:07 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-04-12 15:51:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileList, mFiles, mParent)
|
2015-07-22 19:03:07 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2018-03-16 22:55:32 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2015-07-22 19:03:07 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(FileList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(FileList)
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
FileList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return mozilla::dom::FileList_Binding::Wrap(aCx, this, aGivenProto);
|
2015-07-22 19:03:07 +03:00
|
|
|
}
|
|
|
|
|
2016-04-12 15:51:52 +03:00
|
|
|
File*
|
|
|
|
FileList::Item(uint32_t aIndex) const
|
2016-03-20 13:56:10 +03:00
|
|
|
{
|
2016-04-12 15:51:52 +03:00
|
|
|
if (aIndex >= mFiles.Length()) {
|
|
|
|
return nullptr;
|
2016-03-20 13:56:10 +03:00
|
|
|
}
|
|
|
|
|
2016-04-12 15:51:52 +03:00
|
|
|
return mFiles[aIndex];
|
2016-03-20 13:56:10 +03:00
|
|
|
}
|
|
|
|
|
2016-04-12 15:51:52 +03:00
|
|
|
File*
|
|
|
|
FileList::IndexedGetter(uint32_t aIndex, bool& aFound) const
|
2016-03-20 13:56:10 +03:00
|
|
|
{
|
2016-04-12 15:51:52 +03:00
|
|
|
aFound = aIndex < mFiles.Length();
|
|
|
|
return Item(aIndex);
|
2016-03-20 13:56:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-12 15:51:52 +03:00
|
|
|
FileList::ToSequence(Sequence<RefPtr<File>>& aSequence,
|
2016-03-20 13:56:10 +03:00
|
|
|
ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSequence.IsEmpty());
|
2016-04-12 15:51:52 +03:00
|
|
|
if (mFiles.IsEmpty()) {
|
2016-03-20 13:56:10 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-12 15:51:52 +03:00
|
|
|
if (!aSequence.SetLength(mFiles.Length(),
|
2016-03-20 13:56:10 +03:00
|
|
|
mozilla::fallible_t())) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-12 15:51:52 +03:00
|
|
|
for (uint32_t i = 0; i < mFiles.Length(); ++i) {
|
|
|
|
aSequence[i] = mFiles[i];
|
2016-03-20 13:56:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 19:03:07 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|