Bug 1632128 - De-virtualize IDBFileRequest::SetResult(Callback). r=dom-workers-and-storage-reviewers,janv

Differential Revision: https://phabricator.services.mozilla.com/D74875
This commit is contained in:
Simon Giesecke 2020-05-14 09:42:21 +00:00
Родитель 5f4d07aff0
Коммит 9ee13d3ec4
3 изменённых файлов: 25 добавлений и 39 удалений

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

@ -895,8 +895,7 @@ class MOZ_STACK_CLASS AutoSetCurrentFileHandle final {
IDBFileHandle* FileHandle() const { return mFileHandle; }
};
class MOZ_STACK_CLASS FileHandleResultHelper final
: public IDBFileRequest::ResultCallback {
class MOZ_STACK_CLASS FileHandleResultHelper final {
IDBFileRequest* const mFileRequest;
AutoSetCurrentFileHandle mAutoFileHandle;
@ -920,8 +919,8 @@ class MOZ_STACK_CLASS FileHandleResultHelper final
IDBFileHandle* FileHandle() const { return mAutoFileHandle.FileHandle(); }
virtual nsresult GetResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aResult) override {
nsresult operator()(JSContext* aCx,
JS::MutableHandle<JS::Value> aResult) const {
MOZ_ASSERT(aCx);
MOZ_ASSERT(mFileRequest);
@ -949,7 +948,7 @@ class MOZ_STACK_CLASS FileHandleResultHelper final
}
nsresult GetResult(JSContext* aCx, const nsCString* aString,
JS::MutableHandle<JS::Value> aResult) {
JS::MutableHandle<JS::Value> aResult) const {
const nsCString& data = *aString;
nsresult rv;
@ -1064,7 +1063,7 @@ void DispatchFileHandleSuccessEvent(FileHandleResultHelper* aResultHelper) {
MOZ_ASSERT(fileHandle->IsOpen());
fileRequest->SetResultCallback(aResultHelper);
fileRequest->SetResult(*aResultHelper);
MOZ_ASSERT(fileHandle->IsOpen() || fileHandle->IsAborted());
}

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

@ -64,27 +64,6 @@ void IDBFileRequest::FireProgressEvent(uint64_t aLoaded, uint64_t aTotal) {
DispatchTrustedEvent(event);
}
void IDBFileRequest::SetResultCallback(ResultCallback* aCallback) {
AssertIsOnOwningThread();
MOZ_ASSERT(aCallback);
AutoJSAPI autoJS;
if (NS_WARN_IF(!autoJS.Init(GetOwnerGlobal()))) {
FireError(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
return;
}
JSContext* cx = autoJS.cx();
JS::Rooted<JS::Value> result(cx);
nsresult rv = aCallback->GetResult(cx, &result);
if (NS_WARN_IF(NS_FAILED(rv))) {
FireError(rv);
} else {
FireSuccess(result);
}
}
NS_IMPL_ADDREF_INHERITED(IDBFileRequest, DOMRequest)
NS_IMPL_RELEASE_INHERITED(IDBFileRequest, DOMRequest)

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

@ -30,8 +30,6 @@ class IDBFileRequest final : public DOMRequest {
bool mHasEncoding;
public:
class ResultCallback;
[[nodiscard]] static RefPtr<IDBFileRequest> Create(IDBFileHandle* aFileHandle,
bool aWrapAsDOMRequest);
@ -46,7 +44,26 @@ class IDBFileRequest final : public DOMRequest {
void FireProgressEvent(uint64_t aLoaded, uint64_t aTotal);
void SetResultCallback(ResultCallback* aCallback);
template <typename ResultCallback>
void SetResult(const ResultCallback& aCallback) {
AssertIsOnOwningThread();
AutoJSAPI autoJS;
if (NS_WARN_IF(!autoJS.Init(GetOwnerGlobal()))) {
FireError(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
return;
}
JSContext* cx = autoJS.cx();
JS::Rooted<JS::Value> result(cx);
nsresult rv = aCallback(cx, &result);
if (NS_WARN_IF(NS_FAILED(rv))) {
FireError(rv);
} else {
FireSuccess(result);
}
}
// WebIDL
IDBFileHandle* GetFileHandle() const {
@ -81,15 +98,6 @@ class IDBFileRequest final : public DOMRequest {
~IDBFileRequest();
};
class NS_NO_VTABLE IDBFileRequest::ResultCallback {
public:
virtual nsresult GetResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aResult) = 0;
protected:
ResultCallback() = default;
};
} // namespace dom
} // namespace mozilla