@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +552 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +944 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// swift-tools-version:5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
// Hand-written, and deliberately so: React Native treats a dependency that
|
|
5
|
+
// ships its own Package.swift as "self-managed" and references this directory
|
|
6
|
+
// directly instead of scaffolding one. Four things here are load-bearing and
|
|
7
|
+
// non-obvious; see docs/design/plans for the spike that established them.
|
|
8
|
+
//
|
|
9
|
+
// 1. The product name must equal the `spm.name` pinned in
|
|
10
|
+
// react-native.config.js. toSwiftName('@bugsee/react-native') yields
|
|
11
|
+
// 'ReactNative', which is reserved, so the autolinker would otherwise
|
|
12
|
+
// rename us and look for a product that does not exist.
|
|
13
|
+
//
|
|
14
|
+
// 2. The relative `path:` values resolve through the symlink the autolinker
|
|
15
|
+
// creates at <app>/ios/build/generated/autolinking/libs/<SwiftName>, not
|
|
16
|
+
// through this file's realpath. They are the same for a root-level and an
|
|
17
|
+
// ios/ layout precisely because of that indirection.
|
|
18
|
+
//
|
|
19
|
+
// 3. DEBUG/NDEBUG are mandatory, not cosmetic. NDEBUG changes ShadowNode
|
|
20
|
+
// layout in the prebuilt React.framework, so omitting them links fine in
|
|
21
|
+
// Debug and fails in Release.
|
|
22
|
+
//
|
|
23
|
+
// 4. There is no prefix header under SPM; react-native-spm-prefix.h is
|
|
24
|
+
// force-included to replace the .pch CocoaPods generates.
|
|
25
|
+
//
|
|
26
|
+
// 5. cxxLanguageStandard must be set. SwiftPM defaults a C++ target to
|
|
27
|
+
// gnu++14, and React Native's headers are C++20 — without it the build
|
|
28
|
+
// fails deep inside RCTConvertHelpers.h with "no template named 'optional'
|
|
29
|
+
// in namespace 'std'", which reads like a broken toolchain rather than a
|
|
30
|
+
// missing setting. CocoaPods does not hit this because RN's post-install
|
|
31
|
+
// sets CLANG_CXX_LANGUAGE_STANDARD on every pod.
|
|
32
|
+
let package = Package(
|
|
33
|
+
name: "BugseeReactNative",
|
|
34
|
+
// 15.0 is React Native's floor. This target consumes React-GeneratedCode,
|
|
35
|
+
// whose manifest declares .iOS(.v15), and SwiftPM refuses the graph rather
|
|
36
|
+
// than resolve it: "The package product 'X' requires minimum platform
|
|
37
|
+
// version 15.0 for the iOS platform, but this target supports 13.0".
|
|
38
|
+
// Reproduced; do not lower it.
|
|
39
|
+
platforms: [.iOS(.v15)],
|
|
40
|
+
products: [
|
|
41
|
+
.library(name: "BugseeReactNative", targets: ["BugseeReactNative"])
|
|
42
|
+
],
|
|
43
|
+
dependencies: [
|
|
44
|
+
.package(name: "ReactNative", path: "../../../../xcframeworks"),
|
|
45
|
+
.package(name: "React-GeneratedCode", path: "../../../ios"),
|
|
46
|
+
.package(path: "Support"),
|
|
47
|
+
],
|
|
48
|
+
targets: [
|
|
49
|
+
.target(
|
|
50
|
+
name: "BugseeReactNative",
|
|
51
|
+
dependencies: [
|
|
52
|
+
.product(name: "ReactHeaders", package: "ReactNative"),
|
|
53
|
+
.product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
|
|
54
|
+
.product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
|
|
55
|
+
.product(name: "BugseeRNSupport", package: "Support"),
|
|
56
|
+
],
|
|
57
|
+
path: ".",
|
|
58
|
+
exclude: ["Support", "react-native-spm-prefix.h"],
|
|
59
|
+
publicHeadersPath: ".",
|
|
60
|
+
cSettings: [
|
|
61
|
+
.unsafeFlags(["-include", "react-native-spm-prefix.h"])
|
|
62
|
+
],
|
|
63
|
+
cxxSettings: [
|
|
64
|
+
.define("DEBUG", .when(configuration: .debug)),
|
|
65
|
+
.define("NDEBUG", .when(configuration: .release)),
|
|
66
|
+
.unsafeFlags(["-include", "react-native-spm-prefix.h"]),
|
|
67
|
+
]
|
|
68
|
+
)
|
|
69
|
+
],
|
|
70
|
+
cxxLanguageStandard: .cxx20
|
|
71
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pins" : [
|
|
3
|
+
{
|
|
4
|
+
"identity" : "spm",
|
|
5
|
+
"kind" : "remoteSourceControl",
|
|
6
|
+
"location" : "https://github.com/bugsee/spm",
|
|
7
|
+
"state" : {
|
|
8
|
+
"revision" : "73ed98341d1243ffa7985f871417adcd0ad19799",
|
|
9
|
+
"version" : "7.0.0-beta7"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"version" : 2
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// swift-tools-version:5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
/// Pure marshalling shared by the iOS bridge.
|
|
5
|
+
///
|
|
6
|
+
/// A package of its own so its tests can exercise it against the real Bugsee
|
|
7
|
+
/// framework without React Native, codegen or a device.
|
|
8
|
+
///
|
|
9
|
+
/// Run them with:
|
|
10
|
+
///
|
|
11
|
+
/// xcodebuild test -scheme BugseeRNSupport \
|
|
12
|
+
/// -destination 'platform=iOS Simulator,name=iPhone 16,OS=latest'
|
|
13
|
+
///
|
|
14
|
+
/// NOT `swift test`: that builds for arm64-apple-macosx, and the xcframework
|
|
15
|
+
/// ships no macOS slice, so it fails with "'Bugsee/Bugsee.h' file not found".
|
|
16
|
+
/// An earlier version of this comment claimed `swift test` worked; it never
|
|
17
|
+
/// did, and CI ran these tests nowhere at all.
|
|
18
|
+
let package = Package(
|
|
19
|
+
name: "BugseeRNSupport",
|
|
20
|
+
// 15.0: the SDK's own floor (7.0.0-beta2 raised it from 13.0, and the
|
|
21
|
+
// bugsee/spm manifest declares .iOS(.v15)), and the rest of the wrapper's.
|
|
22
|
+
// SwiftPM refuses a package that sits below a product it consumes, so this
|
|
23
|
+
// cannot go lower; React Native, at 15.1 since 0.76, could not use it if it
|
|
24
|
+
// did.
|
|
25
|
+
platforms: [.iOS(.v15)],
|
|
26
|
+
products: [
|
|
27
|
+
.library(name: "BugseeRNSupport", targets: ["BugseeRNSupport"])
|
|
28
|
+
],
|
|
29
|
+
dependencies: [
|
|
30
|
+
// Exact, not a range: SwiftPM will not admit a prerelease into one.
|
|
31
|
+
.package(url: "https://github.com/bugsee/spm", exact: "7.0.0-beta7")
|
|
32
|
+
],
|
|
33
|
+
targets: [
|
|
34
|
+
.target(
|
|
35
|
+
name: "BugseeRNSupport",
|
|
36
|
+
dependencies: [.product(name: "Bugsee", package: "spm")],
|
|
37
|
+
publicHeadersPath: "include"
|
|
38
|
+
),
|
|
39
|
+
.testTarget(
|
|
40
|
+
name: "BugseeRNSupportTests",
|
|
41
|
+
dependencies: ["BugseeRNSupport"]
|
|
42
|
+
),
|
|
43
|
+
]
|
|
44
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#import "include/BGSRNAttributes.h"
|
|
2
|
+
|
|
3
|
+
const NSInteger BGSRNAttributeArchiveLimit = 1124;
|
|
4
|
+
|
|
5
|
+
@implementation BGSRNAttributes
|
|
6
|
+
|
|
7
|
+
+ (BOOL)setValue:(id)value
|
|
8
|
+
forKey:(NSString *)key
|
|
9
|
+
setter:(BOOL (^)(NSString *key, id value))setter
|
|
10
|
+
getter:(id _Nullable (^)(NSString *key))getter {
|
|
11
|
+
if (!setter(key, value)) {
|
|
12
|
+
return NO;
|
|
13
|
+
}
|
|
14
|
+
id stored = getter(key);
|
|
15
|
+
return stored != nil && [stored isEqual:value];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
+ (NSDictionary<NSString *, id> *)readable:(nullable NSDictionary *)raw {
|
|
19
|
+
NSMutableDictionary<NSString *, id> *result = [NSMutableDictionary dictionary];
|
|
20
|
+
if (raw == nil) {
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
[raw enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
|
|
24
|
+
if (![key isKindOfClass:NSString.class]) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
NSString *name = (NSString *)key;
|
|
28
|
+
if ([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class]) {
|
|
29
|
+
// Kept as the same object -- not re-boxed -- so a CFBoolean's identity
|
|
30
|
+
// survives the round trip; the SDK's own JSON writer decides
|
|
31
|
+
// true/false vs. a number by that identity, not by value.
|
|
32
|
+
result[name] = value;
|
|
33
|
+
} else if ([value isKindOfClass:NSArray.class]) {
|
|
34
|
+
NSMutableArray<NSString *> *strings = [NSMutableArray array];
|
|
35
|
+
for (id element in (NSArray *)value) {
|
|
36
|
+
if ([element isKindOfClass:NSString.class]) {
|
|
37
|
+
[strings addObject:element];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
result[name] = strings;
|
|
41
|
+
}
|
|
42
|
+
// Anything else -- NSDate, NSData, a nested collection, ... -- has no JS
|
|
43
|
+
// representation and is silently dropped.
|
|
44
|
+
}];
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
+ (nullable NSString *)identifier:(nullable NSString *)raw {
|
|
49
|
+
return (raw == nil || raw.length == 0) ? nil : raw;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@end
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#import "BGSRNCreatedReportOps.h"
|
|
2
|
+
#import "BGSRNErrorMessage.h"
|
|
3
|
+
#import "BGSRNJSON.h"
|
|
4
|
+
#import "BGSRNReportOps.h"
|
|
5
|
+
|
|
6
|
+
const NSUInteger BGSRNCreatedReportAttachmentMaxCount = 3;
|
|
7
|
+
const NSUInteger BGSRNCreatedReportAttachmentMaxBytes = 3u * 1024u * 1024u;
|
|
8
|
+
|
|
9
|
+
/// Hands `made` to the caller's out-parameter. Every error this file makes is
|
|
10
|
+
/// built inline, with a string-literal description, so the scanner
|
|
11
|
+
/// (`scripts/raw-messages.ts`) can see that no value goes into it.
|
|
12
|
+
static BOOL Fail(NSError **out, NSError *made) {
|
|
13
|
+
if (out != NULL) {
|
|
14
|
+
*out = made;
|
|
15
|
+
}
|
|
16
|
+
return NO;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// The one count check. Upload drops anything past `ATTACHMENTS_LIMIT` and
|
|
20
|
+
/// still succeeds; rejecting here is the only way JS hears about it.
|
|
21
|
+
static BOOL AtAttachmentLimit(BugseeExtendedReport *report) {
|
|
22
|
+
return report.attachments.count >= BGSRNCreatedReportAttachmentMaxCount;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@implementation BGSRNCreatedReportOps
|
|
26
|
+
|
|
27
|
+
+ (NSDictionary<NSString *, id> *)readReport:(BugseeExtendedReport *)report {
|
|
28
|
+
NSMutableDictionary<NSString *, id> *result = [NSMutableDictionary dictionary];
|
|
29
|
+
|
|
30
|
+
NSString *summary = report.summary;
|
|
31
|
+
if ([summary isKindOfClass:NSString.class]) {
|
|
32
|
+
result[@"summary"] = summary;
|
|
33
|
+
}
|
|
34
|
+
NSString *description = report.reportDescription;
|
|
35
|
+
if ([description isKindOfClass:NSString.class]) {
|
|
36
|
+
result[@"description"] = description;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
result[@"severity"] = @((NSInteger)report.severity);
|
|
40
|
+
|
|
41
|
+
NSMutableArray<NSString *> *labels = [NSMutableArray array];
|
|
42
|
+
for (id label in report.labels) {
|
|
43
|
+
if ([label isKindOfClass:NSString.class]) {
|
|
44
|
+
[labels addObject:label];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
result[@"labels"] = labels;
|
|
48
|
+
|
|
49
|
+
NSMutableDictionary<NSString *, id> *attributes = [NSMutableDictionary dictionary];
|
|
50
|
+
[report.attributes enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
|
|
51
|
+
if ([key isKindOfClass:NSString.class] &&
|
|
52
|
+
([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class])) {
|
|
53
|
+
attributes[key] = value;
|
|
54
|
+
}
|
|
55
|
+
}];
|
|
56
|
+
result[@"attributes"] = attributes;
|
|
57
|
+
|
|
58
|
+
// One display. The extended report has a screenshot or it does not; the
|
|
59
|
+
// wire shape is still the handler's list of display ids.
|
|
60
|
+
result[@"screenshotDisplayIds"] = report.screenshot != nil ? @[ @0 ] : @[];
|
|
61
|
+
|
|
62
|
+
NSMutableArray<NSString *> *attachmentNames = [NSMutableArray array];
|
|
63
|
+
for (BugseeAttachment *attachment in report.attachments) {
|
|
64
|
+
NSString *name = attachment.name;
|
|
65
|
+
if ([name isKindOfClass:NSString.class]) {
|
|
66
|
+
[attachmentNames addObject:name];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
result[@"attachmentNames"] = attachmentNames;
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
+ (BOOL)applyPatchJSON:(NSString *)json
|
|
74
|
+
toReport:(BugseeExtendedReport *)report
|
|
75
|
+
error:(NSError **)error {
|
|
76
|
+
NSError *parseError = nil;
|
|
77
|
+
NSDictionary *patch = BGSRNJSONObject(json, &parseError);
|
|
78
|
+
if (patch == nil) {
|
|
79
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
80
|
+
code:BGSRNReportErrorBadArgument
|
|
81
|
+
userInfo:@{
|
|
82
|
+
NSLocalizedDescriptionKey : @"update() patch is not a JSON object",
|
|
83
|
+
NSUnderlyingErrorKey : parseError ?: NSNull.null,
|
|
84
|
+
}]);
|
|
85
|
+
}
|
|
86
|
+
NSDictionary<NSString *, id> *valid = [BGSRNReportOps validatedPatch:patch error:error];
|
|
87
|
+
if (valid == nil) {
|
|
88
|
+
return NO;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
id summary = valid[@"summary"];
|
|
92
|
+
if (summary != nil) {
|
|
93
|
+
[report setSummary:summary == NSNull.null ? nil : summary];
|
|
94
|
+
}
|
|
95
|
+
id description = valid[@"description"];
|
|
96
|
+
if (description != nil) {
|
|
97
|
+
[report setDescription:description == NSNull.null ? nil : description];
|
|
98
|
+
}
|
|
99
|
+
id severity = valid[@"severity"];
|
|
100
|
+
if (severity != nil) {
|
|
101
|
+
[report setSeverity:(BugseeSeverityLevel)[severity integerValue]];
|
|
102
|
+
}
|
|
103
|
+
id labels = valid[@"labels"];
|
|
104
|
+
if (labels != nil) {
|
|
105
|
+
// Assignment replaces. There is no clear-then-add on this class.
|
|
106
|
+
report.labels = labels;
|
|
107
|
+
}
|
|
108
|
+
if (valid[@"clearAttributes"] != nil) {
|
|
109
|
+
[report clearAllAttributes];
|
|
110
|
+
}
|
|
111
|
+
[valid[@"attributes"] enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
|
|
112
|
+
if (value == NSNull.null) {
|
|
113
|
+
[report clearAttribute:key];
|
|
114
|
+
} else {
|
|
115
|
+
[report setAttribute:key withValue:value];
|
|
116
|
+
}
|
|
117
|
+
}];
|
|
118
|
+
return YES;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
+ (BOOL)attachData:(NSData *)data
|
|
122
|
+
name:(NSString *)name
|
|
123
|
+
toReport:(BugseeExtendedReport *)report
|
|
124
|
+
error:(NSError **)error {
|
|
125
|
+
if (AtAttachmentLimit(report)) {
|
|
126
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
127
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
128
|
+
userInfo:@{NSLocalizedDescriptionKey : @"a created report holds at most 3 attachments"}]);
|
|
129
|
+
}
|
|
130
|
+
if (data.length == 0 || data.length > BGSRNCreatedReportAttachmentMaxBytes) {
|
|
131
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
132
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
133
|
+
userInfo:@{NSLocalizedDescriptionKey : @"a created-report attachment must be non-empty and at most 3 MiB"}]);
|
|
134
|
+
}
|
|
135
|
+
BugseeAttachment *attachment = [BugseeAttachment attachmentWithName:name filename:name data:data];
|
|
136
|
+
if (attachment == nil) {
|
|
137
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
138
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
139
|
+
userInfo:@{NSLocalizedDescriptionKey : @"The SDK declined the attachment"}]);
|
|
140
|
+
}
|
|
141
|
+
[report setAttachment:attachment];
|
|
142
|
+
return YES;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
+ (BOOL)addData:(NSString *)base64
|
|
146
|
+
name:(NSString *)name
|
|
147
|
+
toReport:(BugseeExtendedReport *)report
|
|
148
|
+
error:(NSError **)error {
|
|
149
|
+
if (![base64 isKindOfClass:NSString.class]) {
|
|
150
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
151
|
+
code:BGSRNReportErrorBadArgument
|
|
152
|
+
userInfo:@{NSLocalizedDescriptionKey : @"data must be base64-encoded"}]);
|
|
153
|
+
}
|
|
154
|
+
// An empty string decodes to empty data, which the SDK drops at upload.
|
|
155
|
+
// Reject it as an attachment, not as bad base64: the encoding is valid.
|
|
156
|
+
if (base64.length == 0) {
|
|
157
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
158
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
159
|
+
userInfo:@{NSLocalizedDescriptionKey : @"a created-report attachment must be non-empty and at most 3 MiB"}]);
|
|
160
|
+
}
|
|
161
|
+
// 3145728 is divisible by 3, so its base64 form is exactly 4/3 with no
|
|
162
|
+
// padding. Reject a longer string before decoding it: this runs on the main
|
|
163
|
+
// thread, and the decoded bytes are checked again in `attachData`.
|
|
164
|
+
const NSUInteger maxBase64Chars = (BGSRNCreatedReportAttachmentMaxBytes / 3) * 4;
|
|
165
|
+
if (base64.length > maxBase64Chars) {
|
|
166
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
167
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
168
|
+
userInfo:@{NSLocalizedDescriptionKey : @"a created-report attachment must be non-empty and at most 3 MiB"}]);
|
|
169
|
+
}
|
|
170
|
+
NSData *data = [[NSData alloc] initWithBase64EncodedString:base64 options:0];
|
|
171
|
+
if (data == nil) {
|
|
172
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
173
|
+
code:BGSRNReportErrorBadArgument
|
|
174
|
+
userInfo:@{NSLocalizedDescriptionKey : @"data must be base64-encoded"}]);
|
|
175
|
+
}
|
|
176
|
+
return [self attachData:data name:name toReport:report error:error];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
+ (BOOL)addFileAtPath:(NSString *)path
|
|
180
|
+
name:(NSString *)name
|
|
181
|
+
toReport:(BugseeExtendedReport *)report
|
|
182
|
+
error:(NSError **)error {
|
|
183
|
+
if (AtAttachmentLimit(report)) {
|
|
184
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
185
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
186
|
+
userInfo:@{NSLocalizedDescriptionKey : @"a created report holds at most 3 attachments"}]);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// The link's own length is the target path, not the file. Resolve first,
|
|
190
|
+
// then take that size, so a short symlink cannot admit a target over 3 MiB
|
|
191
|
+
// and the bytes we then read are the file we measured.
|
|
192
|
+
NSString *resolved = path.stringByResolvingSymlinksInPath;
|
|
193
|
+
if (resolved.length == 0) {
|
|
194
|
+
resolved = path;
|
|
195
|
+
}
|
|
196
|
+
NSError *attrError = nil;
|
|
197
|
+
NSDictionary *attributes = [NSFileManager.defaultManager attributesOfItemAtPath:resolved error:&attrError];
|
|
198
|
+
if (attributes == nil) {
|
|
199
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
200
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
201
|
+
userInfo:@{NSLocalizedDescriptionKey : @"the file is missing or unreadable"}]);
|
|
202
|
+
}
|
|
203
|
+
if (![attributes[NSFileType] isEqualToString:NSFileTypeRegular]) {
|
|
204
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
205
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
206
|
+
userInfo:@{NSLocalizedDescriptionKey : @"the file is missing or unreadable"}]);
|
|
207
|
+
}
|
|
208
|
+
const unsigned long long size = [attributes[NSFileSize] unsignedLongLongValue];
|
|
209
|
+
if (size == 0 || size > (unsigned long long)BGSRNCreatedReportAttachmentMaxBytes) {
|
|
210
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
211
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
212
|
+
userInfo:@{NSLocalizedDescriptionKey : @"a created-report attachment must be non-empty and at most 3 MiB"}]);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Cap the read. The size above can grow between the stat and this read, and
|
|
216
|
+
// `dataWithContentsOfFile:` would then take the whole file on the main thread.
|
|
217
|
+
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:resolved];
|
|
218
|
+
if (file == nil) {
|
|
219
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
220
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
221
|
+
userInfo:@{NSLocalizedDescriptionKey : @"the file is missing or unreadable"}]);
|
|
222
|
+
}
|
|
223
|
+
NSData *read = [file readDataOfLength:BGSRNCreatedReportAttachmentMaxBytes + 1];
|
|
224
|
+
[file closeFile];
|
|
225
|
+
if (read == nil) {
|
|
226
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
227
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
228
|
+
userInfo:@{NSLocalizedDescriptionKey : @"the file is missing or unreadable"}]);
|
|
229
|
+
}
|
|
230
|
+
// Own the bytes. The file is the app's; overwriting it later must not
|
|
231
|
+
// change what the report will upload.
|
|
232
|
+
NSData *owned = [NSData dataWithBytes:read.bytes length:read.length];
|
|
233
|
+
return [self attachData:owned name:name toReport:report error:error];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@end
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#import "BGSRNCreatedReports.h"
|
|
2
|
+
|
|
3
|
+
#import <os/lock.h>
|
|
4
|
+
|
|
5
|
+
@implementation BGSRNCreatedReports {
|
|
6
|
+
os_unfair_lock _lock;
|
|
7
|
+
/// Set by `reserve`, cleared when that reservation is fulfilled or when
|
|
8
|
+
/// `clear` runs before `beginCreate:`. A held report keeps the slot on its
|
|
9
|
+
/// own. After `beginCreate:`, `clear` leaves this set until `fulfil`.
|
|
10
|
+
BOOL _creating;
|
|
11
|
+
/// Token of the open reservation. 0 is never live. Stays set across `clear`
|
|
12
|
+
/// once `beginCreate:` has run, so that completion can still free the slot.
|
|
13
|
+
NSUInteger _reservation;
|
|
14
|
+
/// Set by `beginCreate:`. `clear` then keeps the slot until `fulfil`.
|
|
15
|
+
BOOL _createStarted;
|
|
16
|
+
/// Set by `clear` after `beginCreate:`. `fulfil` frees the slot and does
|
|
17
|
+
/// not publish a handle.
|
|
18
|
+
BOOL _abandoned;
|
|
19
|
+
NSUInteger _nextReservation;
|
|
20
|
+
NSString *_handle;
|
|
21
|
+
BugseeExtendedReport *_report;
|
|
22
|
+
NSUInteger _nextHandle;
|
|
23
|
+
/// Set by `detachForUpload:` until `endUpload:` for that generation. The
|
|
24
|
+
/// handle is already gone; the slot stays taken so a second `createReport`
|
|
25
|
+
/// cannot construct another `BugseeExtendedReport` while `uploadReport:` is
|
|
26
|
+
/// still copying this one. beta3 keeps attributes in a file-scope global.
|
|
27
|
+
BOOL _uploading;
|
|
28
|
+
/// Generation of the in-flight upload. 0 is never live. `clear` moves it so
|
|
29
|
+
/// a completion from the upload `clear` abandoned cannot end a later one.
|
|
30
|
+
NSUInteger _uploadGeneration;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (instancetype)init {
|
|
34
|
+
if ((self = [super init])) {
|
|
35
|
+
_lock = OS_UNFAIR_LOCK_INIT;
|
|
36
|
+
_nextReservation = 1;
|
|
37
|
+
_nextHandle = 1;
|
|
38
|
+
}
|
|
39
|
+
return self;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
+ (BGSRNCreatedReports *)shared {
|
|
43
|
+
static BGSRNCreatedReports *shared;
|
|
44
|
+
static dispatch_once_t once;
|
|
45
|
+
dispatch_once(&once, ^{
|
|
46
|
+
shared = [self new];
|
|
47
|
+
});
|
|
48
|
+
return shared;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (NSUInteger)reserve {
|
|
52
|
+
os_unfair_lock_lock(&_lock);
|
|
53
|
+
NSUInteger token = 0;
|
|
54
|
+
if (!_creating && _report == nil && !_uploading) {
|
|
55
|
+
_creating = YES;
|
|
56
|
+
if (_nextReservation == 0) {
|
|
57
|
+
_nextReservation = 1;
|
|
58
|
+
}
|
|
59
|
+
token = _nextReservation;
|
|
60
|
+
_reservation = token;
|
|
61
|
+
_nextReservation += 1;
|
|
62
|
+
if (_nextReservation == 0) {
|
|
63
|
+
_nextReservation = 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
os_unfair_lock_unlock(&_lock);
|
|
67
|
+
return token;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
- (BOOL)reservationIsOpen:(NSUInteger)reservation {
|
|
71
|
+
os_unfair_lock_lock(&_lock);
|
|
72
|
+
const BOOL open = _creating && !_abandoned && reservation != 0 && reservation == _reservation;
|
|
73
|
+
os_unfair_lock_unlock(&_lock);
|
|
74
|
+
return open;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
- (BOOL)beginCreate:(NSUInteger)reservation {
|
|
78
|
+
os_unfair_lock_lock(&_lock);
|
|
79
|
+
const BOOL started = _creating && !_abandoned && !_createStarted && reservation != 0 &&
|
|
80
|
+
reservation == _reservation;
|
|
81
|
+
if (started) {
|
|
82
|
+
_createStarted = YES;
|
|
83
|
+
}
|
|
84
|
+
os_unfair_lock_unlock(&_lock);
|
|
85
|
+
return started;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
- (nullable NSString *)fulfil:(nullable BugseeExtendedReport *)report
|
|
89
|
+
reservation:(NSUInteger)reservation {
|
|
90
|
+
os_unfair_lock_lock(&_lock);
|
|
91
|
+
NSString *handle = nil;
|
|
92
|
+
// A late completion still runs after `clear` or after this reservation
|
|
93
|
+
// already ended. It must not mint a handle on the next runtime's slot, and
|
|
94
|
+
// a nil must not drop a report that slot already holds.
|
|
95
|
+
if (_creating && reservation != 0 && reservation == _reservation) {
|
|
96
|
+
const BOOL publish = !_abandoned && report != nil;
|
|
97
|
+
_creating = NO;
|
|
98
|
+
_reservation = 0;
|
|
99
|
+
_createStarted = NO;
|
|
100
|
+
_abandoned = NO;
|
|
101
|
+
if (publish) {
|
|
102
|
+
handle = [NSString stringWithFormat:@"cr-%lu", (unsigned long)_nextHandle];
|
|
103
|
+
_nextHandle += 1;
|
|
104
|
+
_handle = handle;
|
|
105
|
+
_report = report;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
os_unfair_lock_unlock(&_lock);
|
|
109
|
+
return handle;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
- (nullable BugseeExtendedReport *)reportFor:(NSString *)handleId {
|
|
113
|
+
os_unfair_lock_lock(&_lock);
|
|
114
|
+
BugseeExtendedReport *report = [_handle isEqualToString:handleId] ? _report : nil;
|
|
115
|
+
os_unfair_lock_unlock(&_lock);
|
|
116
|
+
return report;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (nullable BugseeExtendedReport *)take:(NSString *)handleId {
|
|
120
|
+
os_unfair_lock_lock(&_lock);
|
|
121
|
+
BugseeExtendedReport *report = nil;
|
|
122
|
+
if ([_handle isEqualToString:handleId]) {
|
|
123
|
+
report = _report;
|
|
124
|
+
_report = nil;
|
|
125
|
+
_handle = nil;
|
|
126
|
+
}
|
|
127
|
+
os_unfair_lock_unlock(&_lock);
|
|
128
|
+
return report;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
- (nullable BugseeExtendedReport *)detachForUpload:(NSString *)handleId
|
|
132
|
+
generation:(NSUInteger *)generationOut {
|
|
133
|
+
os_unfair_lock_lock(&_lock);
|
|
134
|
+
BugseeExtendedReport *report = nil;
|
|
135
|
+
NSUInteger generation = 0;
|
|
136
|
+
if ([_handle isEqualToString:handleId] && _report != nil) {
|
|
137
|
+
report = _report;
|
|
138
|
+
_report = nil;
|
|
139
|
+
_handle = nil;
|
|
140
|
+
_uploading = YES;
|
|
141
|
+
_uploadGeneration += 1;
|
|
142
|
+
if (_uploadGeneration == 0) {
|
|
143
|
+
_uploadGeneration = 1;
|
|
144
|
+
}
|
|
145
|
+
generation = _uploadGeneration;
|
|
146
|
+
}
|
|
147
|
+
os_unfair_lock_unlock(&_lock);
|
|
148
|
+
if (generationOut != NULL) {
|
|
149
|
+
*generationOut = generation;
|
|
150
|
+
}
|
|
151
|
+
return report;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
- (void)endUpload:(NSUInteger)generation {
|
|
155
|
+
os_unfair_lock_lock(&_lock);
|
|
156
|
+
if (generation != 0 && generation == _uploadGeneration) {
|
|
157
|
+
_uploading = NO;
|
|
158
|
+
}
|
|
159
|
+
os_unfair_lock_unlock(&_lock);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
- (void)clear {
|
|
163
|
+
os_unfair_lock_lock(&_lock);
|
|
164
|
+
_report = nil;
|
|
165
|
+
_handle = nil;
|
|
166
|
+
if (_createStarted) {
|
|
167
|
+
// `createReportWithCompletion:` already started. Its `-init` resets the
|
|
168
|
+
// file-scope attributes beta3 shares, so the slot stays taken until that
|
|
169
|
+
// completion's `fulfil`. The handle is not published: this runtime's JS
|
|
170
|
+
// is gone.
|
|
171
|
+
_abandoned = YES;
|
|
172
|
+
} else {
|
|
173
|
+
_creating = NO;
|
|
174
|
+
_reservation = 0;
|
|
175
|
+
}
|
|
176
|
+
// An upload still in flight keeps the slot. `uploadReport:` copies attributes
|
|
177
|
+
// after it returns, and beta3 keeps those in a file-scope global. Clearing
|
|
178
|
+
// `_uploading` here would let the next runtime `-init` another
|
|
179
|
+
// `BugseeExtendedReport` and wipe the report being uploaded. `endUpload:`
|
|
180
|
+
// for this generation is what frees the slot.
|
|
181
|
+
os_unfair_lock_unlock(&_lock);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@end
|