Backed out changeset 83ce34cabf08 (bug 1257180)

This commit is contained in:
Sebastian Hengst 2016-04-12 17:56:08 +02:00
Родитель 08c222b359
Коммит da254cafcc
5 изменённых файлов: 7 добавлений и 119 удалений

Просмотреть файл

@ -11,7 +11,6 @@
#include "mozilla/dom/BlobBinding.h" #include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/CryptoKey.h" #include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/Directory.h" #include "mozilla/dom/Directory.h"
#include "mozilla/dom/DirectoryBinding.h"
#include "mozilla/dom/File.h" #include "mozilla/dom/File.h"
#include "mozilla/dom/FileList.h" #include "mozilla/dom/FileList.h"
#include "mozilla/dom/FileListBinding.h" #include "mozilla/dom/FileListBinding.h"
@ -659,7 +658,7 @@ ReadBlob(JSContext* aCx,
MOZ_ASSERT(blobImpl); MOZ_ASSERT(blobImpl);
// RefPtr<File> needs to go out of scope before toObject() is // RefPtr<File> needs to go out of scope before toObjectOrNull() is
// called because the static analysis thinks dereferencing XPCOM objects // called because the static analysis thinks dereferencing XPCOM objects
// can GC (because in some cases it can!), and a return statement with a // can GC (because in some cases it can!), and a return statement with a
// JSObject* type means that JSObject* is on the stack as a raw pointer // JSObject* type means that JSObject* is on the stack as a raw pointer
@ -706,80 +705,6 @@ WriteBlob(JSStructuredCloneWriter* aWriter,
return false; return false;
} }
// A directory is serialized as:
// - pair of ints: SCTAG_DOM_DIRECTORY, 0
// - pair of ints: type (eDOMRootDirectory/eDOMNotRootDirectory) - path length
// - path as string
bool
WriteDirectory(JSStructuredCloneWriter* aWriter,
Directory* aDirectory)
{
MOZ_ASSERT(aWriter);
MOZ_ASSERT(aDirectory);
nsAutoString path;
aDirectory->GetFullRealPath(path);
size_t charSize = sizeof(nsString::char_type);
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_DIRECTORY, 0) &&
JS_WriteUint32Pair(aWriter, (uint32_t)aDirectory->Type(),
path.Length()) &&
JS_WriteBytes(aWriter, path.get(), path.Length() * charSize);
}
JSObject*
ReadDirectory(JSContext* aCx,
JSStructuredCloneReader* aReader,
uint32_t aZero,
StructuredCloneHolder* aHolder)
{
MOZ_ASSERT(aCx);
MOZ_ASSERT(aReader);
MOZ_ASSERT(aHolder);
MOZ_ASSERT(aZero == 0);
uint32_t directoryType, lengthOfString;
if (!JS_ReadUint32Pair(aReader, &directoryType, &lengthOfString)) {
return nullptr;
}
MOZ_ASSERT(directoryType == Directory::eDOMRootDirectory ||
directoryType == Directory::eNotDOMRootDirectory);
nsAutoString path;
path.SetLength(lengthOfString);
size_t charSize = sizeof(nsString::char_type);
if (!JS_ReadBytes(aReader, (void*) path.BeginWriting(),
lengthOfString * charSize)) {
return nullptr;
}
nsCOMPtr<nsIFile> file;
nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(path), true,
getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
// RefPtr<Directory> needs to go out of scope before toObject() is
// called because the static analysis thinks dereferencing XPCOM objects
// can GC (because in some cases it can!), and a return statement with a
// JSObject* type means that JSObject* is on the stack as a raw pointer
// while destructors are running.
JS::Rooted<JS::Value> val(aCx);
{
RefPtr<Directory> directory =
Directory::Create(aHolder->ParentDuringRead(), file,
(Directory::DirectoryType) directoryType);
if (!ToJSValue(aCx, directory, &val)) {
return nullptr;
}
}
return &val.toObject();
}
// Read the WriteFileList for the format. // Read the WriteFileList for the format.
JSObject* JSObject*
ReadFileList(JSContext* aCx, ReadFileList(JSContext* aCx,
@ -1077,10 +1002,6 @@ StructuredCloneHolder::CustomReadHandler(JSContext* aCx,
return ReadBlob(aCx, aIndex, this); return ReadBlob(aCx, aIndex, this);
} }
if (aTag == SCTAG_DOM_DIRECTORY) {
return ReadDirectory(aCx, aReader, aIndex, this);
}
if (aTag == SCTAG_DOM_FILELIST) { if (aTag == SCTAG_DOM_FILELIST) {
return ReadFileList(aCx, aReader, aIndex, this); return ReadFileList(aCx, aReader, aIndex, this);
} }
@ -1121,14 +1042,6 @@ StructuredCloneHolder::CustomWriteHandler(JSContext* aCx,
} }
} }
// See if this is a Directory object.
{
Directory* directory = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Directory, aObj, directory))) {
return WriteDirectory(aWriter, directory);
}
}
// See if this is a FileList object. // See if this is a FileList object.
{ {
FileList* fileList = nullptr; FileList* fileList = nullptr;

Просмотреть файл

@ -17,6 +17,7 @@ namespace dom {
enum StructuredCloneTags { enum StructuredCloneTags {
SCTAG_BASE = JS_SCTAG_USER_MIN, SCTAG_BASE = JS_SCTAG_USER_MIN,
// These tags are used only for main thread structured clone.
SCTAG_DOM_BLOB, SCTAG_DOM_BLOB,
// This tag is obsolete and exists only for backwards compatibility with // This tag is obsolete and exists only for backwards compatibility with
@ -52,8 +53,6 @@ enum StructuredCloneTags {
SCTAG_DOM_EXPANDED_PRINCIPAL, SCTAG_DOM_EXPANDED_PRINCIPAL,
SCTAG_DOM_DIRECTORY,
SCTAG_DOM_MAX SCTAG_DOM_MAX
}; };

Просмотреть файл

@ -114,34 +114,6 @@ function create_fileList_forDir() {
script.sendAsyncMessage("dir.open"); script.sendAsyncMessage("dir.open");
} }
function create_directory() {
if (navigator.userAgent.toLowerCase().indexOf('Android') != -1) {
next();
return;
}
var url = SimpleTest.getTestFileURL("script_postmessages_fileList.js");
var script = SpecialPowers.loadChromeScript(url);
function onOpened(message) {
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
fileList.getFilesAndDirectories().then(function(list) {
// Just a simple test
is(list.length, 1, "This list has 1 element");
ok(list[0] instanceof Directory, "We have a directory.");
clonableObjects.push(list[0]);
script.destroy();
next();
});
}
script.addMessageListener("dir.opened", onOpened);
script.sendAsyncMessage("dir.open");
}
function runTests(obj) { function runTests(obj) {
ok(('clonableObjects' in obj) && ok(('clonableObjects' in obj) &&
('transferableObjects' in obj) && ('transferableObjects' in obj) &&
@ -550,7 +522,6 @@ function test_messagePort_inWorkers() {
var tests = [ var tests = [
create_fileList_forFile, create_fileList_forFile,
create_fileList_forDir, create_fileList_forDir,
create_directory,
test_windowToWindow, test_windowToWindow,
test_windowToIframe, test_windowToIframe,

Просмотреть файл

@ -72,6 +72,7 @@ GetDirectoryListingTaskChild::GetDirectoryListingTaskChild(FileSystemBase* aFile
GetDirectoryListingTaskChild::~GetDirectoryListingTaskChild() GetDirectoryListingTaskChild::~GetDirectoryListingTaskChild()
{ {
MOZ_ASSERT(NS_IsMainThread());
mFileSystem->AssertIsOnOwningThread(); mFileSystem->AssertIsOnOwningThread();
} }

Просмотреть файл

@ -59,6 +59,7 @@ nsISupports*
OSFileSystem::GetParentObject() const OSFileSystem::GetParentObject() const
{ {
AssertIsOnOwningThread(); AssertIsOnOwningThread();
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
return mParent; return mParent;
} }
@ -93,6 +94,8 @@ void
OSFileSystem::Unlink() OSFileSystem::Unlink()
{ {
AssertIsOnOwningThread(); AssertIsOnOwningThread();
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
mParent = nullptr; mParent = nullptr;
} }
@ -100,6 +103,7 @@ void
OSFileSystem::Traverse(nsCycleCollectionTraversalCallback &cb) OSFileSystem::Traverse(nsCycleCollectionTraversalCallback &cb)
{ {
AssertIsOnOwningThread(); AssertIsOnOwningThread();
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
OSFileSystem* tmp = this; OSFileSystem* tmp = this;
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent); NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent);