From e21a14316a792bbb3c8869c11773415dc10e67ea Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Mon, 17 Jul 2023 16:49:55 -0700 Subject: [PATCH 1/2] Use ReadAs* data argument as JSValueObject --- vnext/Shared/Modules/FileReaderModule.cpp | 41 ++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/vnext/Shared/Modules/FileReaderModule.cpp b/vnext/Shared/Modules/FileReaderModule.cpp index 09db7bdd4fd..4be2abb0194 100644 --- a/vnext/Shared/Modules/FileReaderModule.cpp +++ b/vnext/Shared/Modules/FileReaderModule.cpp @@ -126,21 +126,26 @@ void FileReaderTurboModule::Initialize(msrn::ReactContext const &reactContext) n } /// -/// -/// Array of arguments passed from the JavaScript layer. -/// [0] - dynamic blob object { blobId, offset, size[, type] } +/// +/// Blob object with the following fields: +/// - blobId +/// - offset +/// - size +/// - type (optional) +/// +/// +/// Either resolves or rejects the current method with a given text message. /// /// void FileReaderTurboModule::ReadAsDataUrl(msrn::JSValue &&data, msrn::ReactPromise &&result) noexcept { - auto &array = data.AsArray(); - auto &blob = data[0].AsObject(); + auto &blob = data.AsObject(); auto blobId = blob["blobId"].AsString(); auto offset = blob["offset"].AsInt64(); auto size = blob["size"].AsInt64(); auto typeItr = blob.find("type"); string type{}; - if (typeItr == blob.end()) { // TODO: .items() ? + if (typeItr == blob.end()) { type = "application/octet-stream"; } else { type = (*typeItr).second.AsString(); @@ -155,20 +160,26 @@ void FileReaderTurboModule::ReadAsDataUrl(msrn::JSValue &&data, msrn::ReactPromi [&result](string &&message) { result.Reject(winrt::to_hstring(std::move(message)).c_str()); }); } -/// TODO: update (folly not used) -/// -/// Array of arguments passed from the JavaScript layer. -/// [0] - dynamic blob object { blobId, offset, size } -/// [1] - string encoding -/// +/// +/// +/// Blob object with the following fields: +/// - blobId +/// - offset +/// - size +/// - type (optional) +/// +/// +/// Text encoding to proces data with. +/// +/// +/// Either resolves or rejects the current method with a given text message. +/// /// void FileReaderTurboModule::ReadAsText( msrn::JSValue &&data, string &&encoding, msrn::ReactPromise &&result) noexcept { - auto &args = data.AsArray(); - auto &blob = args[0].AsObject(); - + auto &blob = data.AsObject(); auto blobId = blob["blobId"].AsString(); auto offset = blob["offset"].AsInt64(); auto size = blob["size"].AsInt64(); From 75ba17060b25da74d86f2e9e17eb14eaf8a5825e Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Mon, 17 Jul 2023 16:51:47 -0700 Subject: [PATCH 2/2] Change files --- ...ative-windows-ea809b99-bf6d-4902-9c4f-5b35c6a7996f.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-ea809b99-bf6d-4902-9c4f-5b35c6a7996f.json diff --git a/change/react-native-windows-ea809b99-bf6d-4902-9c4f-5b35c6a7996f.json b/change/react-native-windows-ea809b99-bf6d-4902-9c4f-5b35c6a7996f.json new file mode 100644 index 00000000000..2f693b64b96 --- /dev/null +++ b/change/react-native-windows-ea809b99-bf6d-4902-9c4f-5b35c6a7996f.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Use correct data types in FileReaderTurboModule::ReadAs*", + "packageName": "react-native-windows", + "email": "julio.rocha@microsoft.com", + "dependentChangeType": "patch" +}