Commit 6a2da364 authored by Randell Jesup's avatar Randell Jesup
Browse files

Bug 1751681f - Add Serializable to OPFS interfaces. r=dom-storage-reviewers,janv,jari,asuth

parent 2d65dbd8
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -210,7 +210,10 @@ void AssertTagValues() {
                    SCTAG_DOM_DOMMATRIX == 0xffff8013 &&
                    SCTAG_DOM_URLSEARCHPARAMS == 0xffff8014 &&
                    SCTAG_DOM_DOMMATRIXREADONLY == 0xffff8015 &&
                    SCTAG_DOM_STRUCTUREDCLONETESTER == 0xffff8018,
                    SCTAG_DOM_STRUCTUREDCLONETESTER == 0xffff8018 &&
                    SCTAG_DOM_FILESYSTEMHANDLE == 0xffff8019 &&
                    SCTAG_DOM_FILESYSTEMFILEHANDLE == 0xffff801a &&
                    SCTAG_DOM_FILESYSTEMDIRECTORYHANDLE == 0xffff801b,
                "Something has changed the sctag values. This is wrong!");
}

+13 −1
Original line number Diff line number Diff line
@@ -105,8 +105,20 @@ enum StructuredCloneTags : uint32_t {
  // IDB.
  SCTAG_DOM_STRUCTUREDCLONETESTER,

  // IMPORTANT: Don't change the order of these enum values. You could break
  // IDB.
  SCTAG_DOM_FILESYSTEMHANDLE,

  // IMPORTANT: Don't change the order of these enum values. You could break
  // IDB.
  SCTAG_DOM_FILESYSTEMFILEHANDLE,

  // IMPORTANT: Don't change the order of these enum values. You could break
  // IDB.
  SCTAG_DOM_FILESYSTEMDIRECTORYHANDLE,

  // If you are planning to add new tags which could be used by IndexedDB,
  // consider to use empty slots. See EMPTY_SLOT_x
  // consider to use an empty slot. See EMPTY_SLOT_x

  // Please update the static assertions in StructuredCloneHolder.cpp and in
  // IDBObjectStore.cpp, method CommonStructuredCloneReadCallback.
+30 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@

#include "FileSystemDirectoryIteratorFactory.h"
#include "fs/FileSystemRequestHandler.h"
#include "js/StructuredClone.h"
#include "js/TypeDecls.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FileSystemDirectoryHandleBinding.h"
#include "mozilla/dom/FileSystemDirectoryIterator.h"
@@ -16,6 +18,7 @@
#include "mozilla/dom/PFileSystemManager.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/StorageManager.h"
#include "nsJSUtils.h"

namespace mozilla::dom {

@@ -137,4 +140,31 @@ already_AddRefed<Promise> FileSystemDirectoryHandle::Resolve(
  return promise.forget();
}

// [Serializable] implementation

// static
already_AddRefed<FileSystemDirectoryHandle>
FileSystemDirectoryHandle::ReadStructuredClone(
    JSContext* aCx, nsIGlobalObject* aGlobal,
    JSStructuredCloneReader* aReader) {
  uint32_t kind = static_cast<uint32_t>(FileSystemHandleKind::EndGuard_);

  if (!JS_ReadBytes(aReader, reinterpret_cast<void*>(&kind),
                    sizeof(uint32_t))) {
    return nullptr;
  }

  if (kind != static_cast<uint32_t>(FileSystemHandleKind::Directory)) {
    return nullptr;
  }

  RefPtr<FileSystemDirectoryHandle> result =
      FileSystemHandle::ConstructDirectoryHandle(aCx, aGlobal, aReader);
  if (!result) {
    return nullptr;
  }

  return result.forget();
}

}  // namespace mozilla::dom
+5 −0
Original line number Diff line number Diff line
@@ -69,6 +69,11 @@ class FileSystemDirectoryHandle final : public FileSystemHandle {
  already_AddRefed<Promise> Resolve(FileSystemHandle& aPossibleDescendant,
                                    ErrorResult& aError);

  // [Serializable]
  static already_AddRefed<FileSystemDirectoryHandle> ReadStructuredClone(
      JSContext* aCx, nsIGlobalObject* aGlobal,
      JSStructuredCloneReader* aReader);

 private:
  ~FileSystemDirectoryHandle() = default;
};
+29 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@
#include "FileSystemFileHandle.h"
#include "fs/FileSystemRequestHandler.h"

#include "js/StructuredClone.h"
#include "js/TypeDecls.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/FileSystemFileHandleBinding.h"
#include "mozilla/dom/FileSystemHandleBinding.h"
@@ -80,4 +82,31 @@ already_AddRefed<Promise> FileSystemFileHandle::CreateSyncAccessHandle(
  return promise.forget();
}

// [Serializable] implementation

// static
already_AddRefed<FileSystemFileHandle>
FileSystemFileHandle::ReadStructuredClone(JSContext* aCx,
                                          nsIGlobalObject* aGlobal,
                                          JSStructuredCloneReader* aReader) {
  uint32_t kind = static_cast<uint32_t>(FileSystemHandleKind::EndGuard_);

  if (!JS_ReadBytes(aReader, reinterpret_cast<void*>(&kind),
                    sizeof(uint32_t))) {
    return nullptr;
  }

  if (kind != static_cast<uint32_t>(FileSystemHandleKind::File)) {
    return nullptr;
  }

  RefPtr<FileSystemFileHandle> result =
      FileSystemHandle::ConstructFileHandle(aCx, aGlobal, aReader);
  if (!result) {
    return nullptr;
  }

  return result.forget();
}

}  // namespace mozilla::dom
Loading