From 5f7cc5cffa26801e48245e6cc96dbc0cbcc3886c Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Sun, 20 Mar 2016 11:56:10 +0100 Subject: [PATCH] Bug 1173320 - patch 6/8 - Make FileList clonable to workers if it doesn't contain Directories, r=smaug --- dom/base/FileList.cpp | 12 ++++++++++++ dom/base/FileList.h | 2 ++ dom/base/StructuredCloneHolder.cpp | 7 ++++--- dom/base/test/test_postMessages.html | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dom/base/FileList.cpp b/dom/base/FileList.cpp index 854c13ebdacd..4018dc1e53a7 100644 --- a/dom/base/FileList.cpp +++ b/dom/base/FileList.cpp @@ -111,5 +111,17 @@ FileList::ToSequence(Sequence& aSequence, } } +bool +FileList::ClonableToDifferentThreadOrProcess() const +{ + for (uint32_t i = 0; i < mFilesOrDirectories.Length(); ++i) { + if (mFilesOrDirectories[i].IsDirectory()) { + return false; + } + } + + return true; +} + } // namespace dom } // namespace mozilla diff --git a/dom/base/FileList.h b/dom/base/FileList.h index ca63f57a5fc0..b6aeeb7940a2 100644 --- a/dom/base/FileList.h +++ b/dom/base/FileList.h @@ -97,6 +97,8 @@ public: void ToSequence(Sequence& aSequence, ErrorResult& aRv) const; + bool ClonableToDifferentThreadOrProcess() const; + private: ~FileList() {} diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index 9b734368edaa..1313e5325149 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -1008,7 +1008,6 @@ StructuredCloneHolder::CustomReadHandler(JSContext* aCx, } if (aTag == SCTAG_DOM_FILELIST) { - MOZ_ASSERT(mSupportedContext == SameProcessSameThread); return ReadFileList(aCx, aReader, aIndex, this); } @@ -1049,9 +1048,11 @@ StructuredCloneHolder::CustomWriteHandler(JSContext* aCx, } // See if this is a FileList object. - if (mSupportedContext == SameProcessSameThread) { + { FileList* fileList = nullptr; - if (NS_SUCCEEDED(UNWRAP_OBJECT(FileList, aObj, fileList))) { + if (NS_SUCCEEDED(UNWRAP_OBJECT(FileList, aObj, fileList)) && + (mSupportedContext == SameProcessSameThread || + fileList->ClonableToDifferentThreadOrProcess())) { return WriteFileList(aWriter, fileList, this); } } diff --git a/dom/base/test/test_postMessages.html b/dom/base/test/test_postMessages.html index f90a80660d52..50d70464c6b3 100644 --- a/dom/base/test/test_postMessages.html +++ b/dom/base/test/test_postMessages.html @@ -84,7 +84,7 @@ function create_fileList() { var domFile = fileList.files[0]; is(domFile.name, "prefs.js", "fileName should be prefs.js"); - clonableObjects.push({ crossThreads: false, data: fileList.files }); + clonableObjects.push({ crossThreads: true, data: fileList.files }); script.destroy(); next(); }