@cloudcare/browser-rum 3.3.5 → 3.3.7
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/README.md +24 -3
- package/README.zh.md +19 -3
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/buildEnv.js.map +1 -1
- package/cjs/boot/perStartRum.js +42 -6
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +190 -195
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/recorderApiStub.js +3 -29
- package/cjs/boot/recorderApiStub.js.map +1 -1
- package/cjs/boot/rum.entry.js.map +1 -1
- package/cjs/boot/rum.js +8 -0
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/boot/rum.slim.entry.js.map +1 -1
- package/cjs/boot/rumEntryFactory.js.map +1 -1
- package/cjs/boot/rumPublicApi.js +36 -3
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/boot/rumRecorderApiStub.js.map +1 -1
- package/cjs/boot/rumSlimConfiguration.js.map +1 -1
- package/cjs/boot/sessionReplayPublicApi.js +14 -27
- package/cjs/boot/sessionReplayPublicApi.js.map +1 -1
- package/cjs/boot/startRecording.js +333 -108
- package/cjs/boot/startRecording.js.map +1 -1
- package/cjs/constants.js.map +1 -1
- package/cjs/domain/assembly.js +1 -7
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/configuration.js +38 -43
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/contexts/commonContext.js.map +1 -1
- package/cjs/domain/contexts/displayContext.js.map +1 -1
- package/cjs/domain/contexts/foregroundContexts.js.map +1 -1
- package/cjs/domain/contexts/internalContext.js.map +1 -1
- package/cjs/domain/contexts/pageStateHistory.js.map +1 -1
- package/cjs/domain/contexts/urlContexts.js +20 -2
- package/cjs/domain/contexts/urlContexts.js.map +1 -1
- package/cjs/domain/contexts/viewContexts.js +2 -2
- package/cjs/domain/contexts/viewContexts.js.map +1 -1
- package/cjs/domain/deflate/deflateEncoder.js +517 -39
- package/cjs/domain/deflate/deflateEncoder.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +194 -115
- package/cjs/domain/deflate/deflateWorker.js.map +1 -1
- package/cjs/domain/deflate/index.js.map +1 -1
- package/cjs/domain/domMutationObservable.js.map +1 -1
- package/cjs/domain/encoderStreamId.js.map +1 -1
- package/cjs/domain/firstInputPolyfill.js.map +1 -1
- package/cjs/domain/initViewportObservable.js.map +1 -1
- package/cjs/domain/locationChangeObservable.js.map +1 -1
- package/cjs/domain/performanceObservable.js.map +1 -1
- package/cjs/domain/performanceUtils.js.map +1 -1
- package/cjs/domain/plugins.js +67 -0
- package/cjs/domain/plugins.js.map +1 -0
- package/cjs/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
- package/cjs/domain/replay/record/canvasCommandCapture.js +968 -167
- package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -1
- package/cjs/domain/replay/record/canvasCommandObserver.js +1058 -119
- package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -1
- package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +61 -37
- package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
- package/cjs/domain/replay/record/canvasContext.js +63 -0
- package/cjs/domain/replay/record/canvasContext.js.map +1 -0
- package/cjs/domain/replay/record/canvasContinuousScheduler.js +246 -118
- package/cjs/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
- package/cjs/domain/replay/record/canvasEncodeBridge.js +539 -87
- package/cjs/domain/replay/record/canvasEncodeBridge.js.map +1 -1
- package/cjs/domain/replay/record/canvasEncodeWorker.js +50 -32
- package/cjs/domain/replay/record/canvasEncodeWorker.js.map +1 -1
- package/cjs/domain/replay/record/canvasFrameSignature.js +49 -17
- package/cjs/domain/replay/record/canvasFrameSignature.js.map +1 -1
- package/cjs/domain/replay/record/canvasMutationRecord.js.map +1 -1
- package/cjs/domain/replay/record/canvasObserver.js +295 -59
- package/cjs/domain/replay/record/canvasObserver.js.map +1 -1
- package/cjs/domain/replay/record/canvasSerializeArgs.js.map +1 -1
- package/cjs/domain/replay/record/canvasWebGLPluginHost.js +33 -0
- package/cjs/domain/replay/record/canvasWebGLPluginHost.js.map +1 -0
- package/cjs/domain/replay/record/elementsScrollPositions.js +3 -0
- package/cjs/domain/replay/record/elementsScrollPositions.js.map +1 -1
- package/cjs/domain/replay/record/index.js.map +1 -1
- package/cjs/domain/replay/record/mutationBatch.js +542 -25
- package/cjs/domain/replay/record/mutationBatch.js.map +1 -1
- package/cjs/domain/replay/record/mutationObserver.js +1900 -191
- package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
- package/cjs/domain/replay/record/mutationResourceBudget.js +144 -0
- package/cjs/domain/replay/record/mutationResourceBudget.js.map +1 -0
- package/cjs/domain/replay/record/observers.js +222 -53
- package/cjs/domain/replay/record/observers.js.map +1 -1
- package/cjs/domain/replay/record/privacy.js +31 -8
- package/cjs/domain/replay/record/privacy.js.map +1 -1
- package/cjs/domain/replay/record/record.js +3083 -321
- package/cjs/domain/replay/record/record.js.map +1 -1
- package/cjs/domain/replay/record/serializationUtils.js +426 -26
- package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
- package/cjs/domain/replay/record/serialize.js +259 -49
- package/cjs/domain/replay/record/serialize.js.map +1 -1
- package/cjs/domain/replay/record/shadowRootsController.js +875 -21
- package/cjs/domain/replay/record/shadowRootsController.js.map +1 -1
- package/cjs/domain/replay/record/utils.js.map +1 -1
- package/cjs/domain/replay/record/viewports.js.map +1 -1
- package/cjs/domain/replay/replayStats.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/index.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segment.js +315 -11
- package/cjs/domain/replay/segmentCollection/segment.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +956 -71
- package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/cjs/domain/replay/startRecordBridge.js.map +1 -1
- package/cjs/domain/requestCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
- package/cjs/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/cjs/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +56 -0
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js +196 -0
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- package/cjs/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js +8 -3
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +31 -12
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/cjs/domain/rumSessionManager.js +23 -3
- package/cjs/domain/rumSessionManager.js.map +1 -1
- package/cjs/domain/tracing/ddtraceTracer.js.map +1 -1
- package/cjs/domain/tracing/getDocumentTraceId.js.map +1 -1
- package/cjs/domain/tracing/jaegerTracer.js.map +1 -1
- package/cjs/domain/tracing/sampler.js.map +1 -1
- package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
- package/cjs/domain/tracing/traceIdentifier.js.map +1 -1
- package/cjs/domain/tracing/tracer.js +2 -2
- package/cjs/domain/tracing/tracer.js.map +1 -1
- package/cjs/domain/tracing/w3cTraceParentTracer.js.map +1 -1
- package/cjs/domain/tracing/zipkinMultiTracer.js.map +1 -1
- package/cjs/domain/tracing/zipkinSingleTracer.js.map +1 -1
- package/cjs/domain/trackEventCounts.js.map +1 -1
- package/cjs/domain/usr/index.js.map +1 -1
- package/cjs/domain/waitPageActivityEnd.js.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/transport/startRumBatch.js +3 -1
- package/cjs/transport/startRumBatch.js.map +1 -1
- package/cjs/transport/startRumEventBridge.js.map +1 -1
- package/cjs/types/index.js.map +1 -1
- package/cjs/types/sessionReplayConstants.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/buildEnv.js.map +1 -1
- package/esm/boot/perStartRum.js +42 -6
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +192 -197
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/recorderApiStub.js +3 -29
- package/esm/boot/recorderApiStub.js.map +1 -1
- package/esm/boot/rum.entry.js.map +1 -1
- package/esm/boot/rum.js +8 -0
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rum.slim.entry.js.map +1 -1
- package/esm/boot/rumEntryFactory.js.map +1 -1
- package/esm/boot/rumPublicApi.js +36 -3
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/boot/rumRecorderApiStub.js.map +1 -1
- package/esm/boot/rumSlimConfiguration.js.map +1 -1
- package/esm/boot/sessionReplayPublicApi.js +14 -27
- package/esm/boot/sessionReplayPublicApi.js.map +1 -1
- package/esm/boot/startRecording.js +334 -109
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/constants.js.map +1 -1
- package/esm/domain/assembly.js +1 -7
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +39 -44
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/contexts/commonContext.js.map +1 -1
- package/esm/domain/contexts/displayContext.js.map +1 -1
- package/esm/domain/contexts/foregroundContexts.js.map +1 -1
- package/esm/domain/contexts/internalContext.js.map +1 -1
- package/esm/domain/contexts/pageStateHistory.js.map +1 -1
- package/esm/domain/contexts/urlContexts.js +21 -3
- package/esm/domain/contexts/urlContexts.js.map +1 -1
- package/esm/domain/contexts/viewContexts.js +2 -2
- package/esm/domain/contexts/viewContexts.js.map +1 -1
- package/esm/domain/deflate/deflateEncoder.js +517 -39
- package/esm/domain/deflate/deflateEncoder.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +193 -116
- package/esm/domain/deflate/deflateWorker.js.map +1 -1
- package/esm/domain/deflate/index.js.map +1 -1
- package/esm/domain/domMutationObservable.js.map +1 -1
- package/esm/domain/encoderStreamId.js.map +1 -1
- package/esm/domain/firstInputPolyfill.js.map +1 -1
- package/esm/domain/initViewportObservable.js.map +1 -1
- package/esm/domain/locationChangeObservable.js.map +1 -1
- package/esm/domain/performanceObservable.js.map +1 -1
- package/esm/domain/performanceUtils.js.map +1 -1
- package/esm/domain/plugins.js +59 -0
- package/esm/domain/plugins.js.map +1 -0
- package/esm/domain/replay/record/canvasAutoSnapshot.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandCapture.js +968 -168
- package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandObserver.js +1058 -119
- package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js +60 -37
- package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasContext.js +50 -0
- package/esm/domain/replay/record/canvasContext.js.map +1 -0
- package/esm/domain/replay/record/canvasContinuousScheduler.js +246 -118
- package/esm/domain/replay/record/canvasContinuousScheduler.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeBridge.js +539 -87
- package/esm/domain/replay/record/canvasEncodeBridge.js.map +1 -1
- package/esm/domain/replay/record/canvasEncodeWorker.js +51 -33
- package/esm/domain/replay/record/canvasEncodeWorker.js.map +1 -1
- package/esm/domain/replay/record/canvasFrameSignature.js +50 -17
- package/esm/domain/replay/record/canvasFrameSignature.js.map +1 -1
- package/esm/domain/replay/record/canvasMutationRecord.js.map +1 -1
- package/esm/domain/replay/record/canvasObserver.js +295 -59
- package/esm/domain/replay/record/canvasObserver.js.map +1 -1
- package/esm/domain/replay/record/canvasSerializeArgs.js.map +1 -1
- package/esm/domain/replay/record/canvasWebGLPluginHost.js +26 -0
- package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -0
- package/esm/domain/replay/record/elementsScrollPositions.js +3 -0
- package/esm/domain/replay/record/elementsScrollPositions.js.map +1 -1
- package/esm/domain/replay/record/index.js.map +1 -1
- package/esm/domain/replay/record/mutationBatch.js +541 -25
- package/esm/domain/replay/record/mutationBatch.js.map +1 -1
- package/esm/domain/replay/record/mutationObserver.js +1892 -195
- package/esm/domain/replay/record/mutationObserver.js.map +1 -1
- package/esm/domain/replay/record/mutationResourceBudget.js +137 -0
- package/esm/domain/replay/record/mutationResourceBudget.js.map +1 -0
- package/esm/domain/replay/record/observers.js +224 -55
- package/esm/domain/replay/record/observers.js.map +1 -1
- package/esm/domain/replay/record/privacy.js +30 -7
- package/esm/domain/replay/record/privacy.js.map +1 -1
- package/esm/domain/replay/record/record.js +3086 -325
- package/esm/domain/replay/record/record.js.map +1 -1
- package/esm/domain/replay/record/serializationUtils.js +422 -25
- package/esm/domain/replay/record/serializationUtils.js.map +1 -1
- package/esm/domain/replay/record/serialize.js +258 -50
- package/esm/domain/replay/record/serialize.js.map +1 -1
- package/esm/domain/replay/record/shadowRootsController.js +875 -21
- package/esm/domain/replay/record/shadowRootsController.js.map +1 -1
- package/esm/domain/replay/record/utils.js.map +1 -1
- package/esm/domain/replay/record/viewports.js.map +1 -1
- package/esm/domain/replay/replayStats.js.map +1 -1
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
- package/esm/domain/replay/segmentCollection/index.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segment.js +315 -10
- package/esm/domain/replay/segmentCollection/segment.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segmentCollection.js +957 -72
- package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/esm/domain/replay/startRecordBridge.js.map +1 -1
- package/esm/domain/requestCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/actionCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/clickChain.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/interactionSelectorCache.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js.map +1 -1
- package/esm/domain/rumEventsCollection/error/trackReportError.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longAnimationFrameCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +55 -0
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js +189 -0
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- package/esm/domain/rumEventsCollection/view/interactionCountPolyfill.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCommonViewMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackFirstInput.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +8 -3
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackNavigationTimings.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackScrollMetrics.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +32 -13
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/esm/domain/rumSessionManager.js +24 -4
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/esm/domain/tracing/ddtraceTracer.js.map +1 -1
- package/esm/domain/tracing/getDocumentTraceId.js.map +1 -1
- package/esm/domain/tracing/jaegerTracer.js.map +1 -1
- package/esm/domain/tracing/sampler.js.map +1 -1
- package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
- package/esm/domain/tracing/traceIdentifier.js.map +1 -1
- package/esm/domain/tracing/tracer.js +2 -2
- package/esm/domain/tracing/tracer.js.map +1 -1
- package/esm/domain/tracing/w3cTraceParentTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinMultiTracer.js.map +1 -1
- package/esm/domain/tracing/zipkinSingleTracer.js.map +1 -1
- package/esm/domain/trackEventCounts.js.map +1 -1
- package/esm/domain/usr/index.js.map +1 -1
- package/esm/domain/waitPageActivityEnd.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/transport/startRumBatch.js +4 -2
- package/esm/transport/startRumBatch.js.map +1 -1
- package/esm/transport/startRumEventBridge.js.map +1 -1
- package/esm/types/index.js.map +1 -1
- package/esm/types/sessionReplayConstants.js.map +1 -1
- package/package.json +12 -7
- package/src/boot/perStartRum.js +47 -7
- package/src/boot/recorderApi.js +271 -220
- package/src/boot/recorderApiStub.js +3 -29
- package/src/boot/rum.js +11 -0
- package/src/boot/rumPublicApi.js +38 -3
- package/src/boot/sessionReplayPublicApi.js +15 -28
- package/src/boot/startRecording.js +429 -146
- package/src/domain/assembly.js +5 -4
- package/src/domain/configuration.js +76 -101
- package/src/domain/contexts/urlContexts.js +29 -3
- package/src/domain/contexts/viewContexts.js +2 -2
- package/src/domain/deflate/deflateEncoder.js +699 -43
- package/src/domain/deflate/deflateWorker.js +237 -136
- package/src/domain/plugins.js +94 -0
- package/src/domain/replay/record/canvasCommandCapture.js +1374 -180
- package/src/domain/replay/record/canvasCommandObserver.js +1585 -150
- package/src/domain/replay/record/canvasCommandSerializeArgs.js +79 -42
- package/src/domain/replay/record/canvasContext.js +67 -0
- package/src/domain/replay/record/canvasContinuousScheduler.js +379 -143
- package/src/domain/replay/record/canvasEncodeBridge.js +691 -106
- package/src/domain/replay/record/canvasEncodeWorker.js +67 -43
- package/src/domain/replay/record/canvasFrameSignature.js +58 -24
- package/src/domain/replay/record/canvasObserver.js +461 -89
- package/src/domain/replay/record/canvasWebGLPluginHost.js +43 -0
- package/src/domain/replay/record/elementsScrollPositions.js +3 -0
- package/src/domain/replay/record/mutationBatch.js +761 -27
- package/src/domain/replay/record/mutationObserver.js +2992 -261
- package/src/domain/replay/record/mutationResourceBudget.js +191 -0
- package/src/domain/replay/record/observers.js +367 -97
- package/src/domain/replay/record/privacy.js +34 -12
- package/src/domain/replay/record/record.js +4284 -413
- package/src/domain/replay/record/serializationUtils.js +587 -28
- package/src/domain/replay/record/serialize.js +432 -66
- package/src/domain/replay/record/shadowRootsController.js +1108 -30
- package/src/domain/replay/segmentCollection/segment.js +441 -11
- package/src/domain/replay/segmentCollection/segmentCollection.js +1300 -77
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +70 -0
- package/src/domain/rumEventsCollection/resource/webSocketCollection.js +271 -0
- package/src/domain/rumEventsCollection/view/trackLoadingTime.js +12 -3
- package/src/domain/rumEventsCollection/view/trackViews.js +38 -13
- package/src/domain/rumSessionManager.js +33 -2
- package/src/domain/tracing/tracer.js +4 -5
- package/src/transport/startRumBatch.js +6 -1
- package/types/index.d.ts +100 -8
- package/cjs/domain/replay/record/canvasReplayFixtures.js +0 -105
- package/cjs/domain/replay/record/canvasReplayFixtures.js.map +0 -1
- package/esm/domain/replay/record/canvasReplayFixtures.js +0 -96
- package/esm/domain/replay/record/canvasReplayFixtures.js.map +0 -1
- package/src/domain/replay/record/canvasReplayFixtures.js +0 -113
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.MUTATION_NORMALIZATION_MAX_DURATION_MS = exports.MAX_REMOVED_SUBTREE_TRAVERSAL_NODES = exports.MAX_PENDING_MUTATION_ROOT_TASKS = exports.MAX_PENDING_MUTATION_ROOT_APPROX_BYTES = exports.MAX_PENDING_MUTATION_GROUPS = exports.MAX_MUTATION_SERIALIZED_VALUE_CHARACTERS = exports.MAX_MUTATION_ROOT_TASK_REFRESH_COUNT = exports.MAX_MUTATION_CURRENT_SOURCE_CHARACTERS = exports.MAX_DEFERRED_MUTATION_ROOT_TASKS = void 0;
|
|
7
|
+
exports.cancelMutationAddPublicationToken = cancelMutationAddPublicationToken;
|
|
8
|
+
exports.consumeMutationAddPublicationToken = consumeMutationAddPublicationToken;
|
|
9
|
+
exports.consumeMutationRemoveSourceNode = consumeMutationRemoveSourceNode;
|
|
10
|
+
exports.createMutationAddPublicationToken = createMutationAddPublicationToken;
|
|
11
|
+
exports.createMutationTasksController = createMutationTasksController;
|
|
12
|
+
exports.getMutationAddPublicationToken = getMutationAddPublicationToken;
|
|
13
|
+
exports.getMutationPayloadApproxBytes = getMutationPayloadApproxBytes;
|
|
14
|
+
exports.getMutationRemoveSourceNode = getMutationRemoveSourceNode;
|
|
15
|
+
exports.processMutations = processMutations;
|
|
16
|
+
exports.publishMutationAddPublicationToken = publishMutationAddPublicationToken;
|
|
17
|
+
exports.registerMutationAddPublicationToken = registerMutationAddPublicationToken;
|
|
6
18
|
exports.sortAddedAndMovedNodes = sortAddedAndMovedNodes;
|
|
7
19
|
exports.startMutationObserver = startMutationObserver;
|
|
8
20
|
var _browserCore = require("@cloudcare/browser-core");
|
|
@@ -12,33 +24,192 @@ var _privacy = require("./privacy");
|
|
|
12
24
|
var _serializationUtils = require("./serializationUtils");
|
|
13
25
|
var _serialize = require("./serialize");
|
|
14
26
|
var _mutationBatch = require("./mutationBatch");
|
|
27
|
+
var _mutationResourceBudget = require("./mutationResourceBudget");
|
|
15
28
|
var MUTATION_SERIALIZATION_SLICE_MS = 4;
|
|
16
|
-
var
|
|
29
|
+
var MUTATION_SERIALIZATION_FLUSH_BUDGET_MS = 4;
|
|
30
|
+
var MUTATION_NORMALIZATION_MAX_DURATION_MS = exports.MUTATION_NORMALIZATION_MAX_DURATION_MS = 4;
|
|
31
|
+
var MUTATION_NORMALIZATION_TIME_CHECK_INTERVAL = 32;
|
|
32
|
+
// performance.now() can jump across a short GC pause or an interrupted
|
|
33
|
+
// observer callback. Let a small, raw-batch-bounded amount of normalization
|
|
34
|
+
// finish before treating the wall-clock deadline as structural loss.
|
|
35
|
+
var MUTATION_NORMALIZATION_SMALL_BATCH_MAX_RECORDS = 32;
|
|
36
|
+
var MUTATION_NORMALIZATION_MIN_OPERATIONS_BEFORE_TIMEOUT = 256;
|
|
37
|
+
var MUTATION_NORMALIZATION_ABORT = {};
|
|
38
|
+
// A serialized add cannot be split below its root. Stop before building one
|
|
39
|
+
// that would exceed record.js' single mutation emit watermark.
|
|
40
|
+
var MUTATION_SERIALIZATION_MAX_NODE_COUNT = 5000;
|
|
41
|
+
var MUTATION_SERIALIZATION_MAX_APPROX_BYTES = 200000;
|
|
42
|
+
var MAX_PENDING_MUTATION_ROOT_TASKS = exports.MAX_PENDING_MUTATION_ROOT_TASKS = 256;
|
|
43
|
+
// Keep the expensive serializer state bounded while allowing a large burst of
|
|
44
|
+
// unpublished, add-only roots to wait as lightweight DOM references. The
|
|
45
|
+
// deferred queue is intentionally finite and matches the raw node watermark:
|
|
46
|
+
// one accepted native callback can therefore be drained without dropping a
|
|
47
|
+
// root, while a sustained producer still cannot grow the queue without bound.
|
|
48
|
+
var MAX_DEFERRED_MUTATION_ROOT_TASKS = exports.MAX_DEFERRED_MUTATION_ROOT_TASKS = _mutationBatch.MAX_QUEUED_MUTATION_NODES;
|
|
49
|
+
var DEFERRED_MUTATION_ROOT_TASK_APPROX_BYTES = 128;
|
|
50
|
+
var MAX_PENDING_MUTATION_GROUPS = exports.MAX_PENDING_MUTATION_GROUPS = 256;
|
|
51
|
+
var MAX_PENDING_MUTATION_ROOT_APPROX_BYTES = exports.MAX_PENDING_MUTATION_ROOT_APPROX_BYTES = 4 * 1024 * 1024;
|
|
52
|
+
var MAX_MUTATION_ROOT_TASK_REFRESH_COUNT = exports.MAX_MUTATION_ROOT_TASK_REFRESH_COUNT = 16;
|
|
53
|
+
var MAX_REMOVED_SUBTREE_TRAVERSAL_NODES = exports.MAX_REMOVED_SUBTREE_TRAVERSAL_NODES = 5000;
|
|
54
|
+
// MutationBatch can only account for MutationRecord.oldValue. Bound the
|
|
55
|
+
// current text/attribute values separately before privacy transforms and
|
|
56
|
+
// record-size estimation scan them synchronously.
|
|
57
|
+
var MAX_MUTATION_CURRENT_SOURCE_CHARACTERS = exports.MAX_MUTATION_CURRENT_SOURCE_CHARACTERS = 512 * 1024;
|
|
58
|
+
var MAX_MUTATION_SERIALIZED_VALUE_CHARACTERS = exports.MAX_MUTATION_SERIALIZED_VALUE_CHARACTERS = _serialize.SERIALIZATION_MAX_MUTATION_SOURCE_LENGTH;
|
|
59
|
+
var AGGREGATE_RETAINED_MUTATION_WATERMARK = 'aggregate_retained_mutation_watermark';
|
|
60
|
+
var MUTATION_ROOT_ADMISSION_WATERMARK = 'mutation_root_admission_watermark';
|
|
61
|
+
var MUTATION_ROOT_RETAINED_BYTES_WATERMARK = 'mutation_root_retained_bytes_watermark';
|
|
62
|
+
var MAX_REMOVED_SUBTREE_TRAVERSAL_DURATION_MS = 4;
|
|
63
|
+
var REMOVED_SUBTREE_TIME_CHECK_INTERVAL = 32;
|
|
64
|
+
var publicationTokenByMutationAdd = new WeakMap();
|
|
65
|
+
var sourceNodeByMutationRemove = new WeakMap();
|
|
66
|
+
var approxBytesByMutationPayload = new WeakMap();
|
|
67
|
+
function getMutationPayloadApproxBytes(payload) {
|
|
68
|
+
var trackedApproxBytes = approxBytesByMutationPayload.get(payload);
|
|
69
|
+
if (trackedApproxBytes) {
|
|
70
|
+
return trackedApproxBytes;
|
|
71
|
+
}
|
|
72
|
+
return estimateFallbackMutationPayloadApproxBytes(payload);
|
|
73
|
+
}
|
|
74
|
+
function estimateFallbackMutationPayloadApproxBytes(payload) {
|
|
75
|
+
if (!payload) {
|
|
76
|
+
return 64;
|
|
77
|
+
}
|
|
78
|
+
return 64 + (payload.adds || []).length * 64 + estimateMutationPayloadEntriesApproxBytes(payload);
|
|
79
|
+
}
|
|
80
|
+
function estimateMutationPayloadEntriesApproxBytes(payload) {
|
|
81
|
+
var approxBytes = (payload.removes || []).length * 24;
|
|
82
|
+
(payload.texts || []).forEach(function (text) {
|
|
83
|
+
approxBytes += 24 + getMutationPayloadStringApproxBytes(text.value);
|
|
84
|
+
});
|
|
85
|
+
(payload.attributes || []).forEach(function (attribute) {
|
|
86
|
+
approxBytes += 24;
|
|
87
|
+
Object.keys(attribute.attributes || {}).forEach(function (name) {
|
|
88
|
+
approxBytes += getMutationPayloadStringApproxBytes(name) + getMutationPayloadStringApproxBytes(attribute.attributes[name]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return approxBytes;
|
|
92
|
+
}
|
|
93
|
+
function getMutationPayloadStringApproxBytes(value) {
|
|
94
|
+
return typeof value === 'string' ? value.length * 2 : 0;
|
|
95
|
+
}
|
|
96
|
+
function getMutationDependencyState(shadowRootsController) {
|
|
97
|
+
if (!shadowRootsController) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!shadowRootsController.$rMutationDependencyState) {
|
|
101
|
+
shadowRootsController.$rMutationDependencyState = {
|
|
102
|
+
$rPublishedRoots: new WeakSet(),
|
|
103
|
+
$rLocallyDroppedRoots: new WeakSet()
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return shadowRootsController.$rMutationDependencyState;
|
|
107
|
+
}
|
|
108
|
+
function consumeMutationAddPublicationToken(add) {
|
|
109
|
+
var publicationToken = publicationTokenByMutationAdd.get(add);
|
|
110
|
+
publicationTokenByMutationAdd["delete"](add);
|
|
111
|
+
return publicationToken;
|
|
112
|
+
}
|
|
113
|
+
function getMutationAddPublicationToken(add) {
|
|
114
|
+
return publicationTokenByMutationAdd.get(add);
|
|
115
|
+
}
|
|
116
|
+
function registerMutationAddPublicationToken(add, publicationToken) {
|
|
117
|
+
publicationTokenByMutationAdd.set(add, publicationToken);
|
|
118
|
+
}
|
|
119
|
+
function createMutationAddPublicationToken(shadowRootsController, requiresBaselineOnDrop) {
|
|
120
|
+
return {
|
|
121
|
+
$rPublished: false,
|
|
122
|
+
$rQueued: false,
|
|
123
|
+
$rCanceled: false,
|
|
124
|
+
$rRequiresBaselineOnDrop: Boolean(requiresBaselineOnDrop),
|
|
125
|
+
$rShadowRootsController: shadowRootsController
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function publishMutationAddPublicationToken(publicationToken) {
|
|
129
|
+
if (!publicationToken || publicationToken.$rCanceled) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
publicationToken.$rQueued = false;
|
|
133
|
+
publicationToken.$rPublished = true;
|
|
134
|
+
var shadowRootsController = publicationToken.$rShadowRootsController;
|
|
135
|
+
if (shadowRootsController && shadowRootsController.commitProvisionalShadowRoots) {
|
|
136
|
+
shadowRootsController.commitProvisionalShadowRoots(publicationToken);
|
|
137
|
+
}
|
|
138
|
+
publicationToken.$rShadowRootsController = undefined;
|
|
139
|
+
}
|
|
140
|
+
function cancelMutationAddPublicationToken(publicationToken) {
|
|
141
|
+
if (!publicationToken || publicationToken.$rPublished || publicationToken.$rCanceled) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
publicationToken.$rQueued = false;
|
|
145
|
+
publicationToken.$rCanceled = true;
|
|
146
|
+
var shadowRootsController = publicationToken.$rShadowRootsController;
|
|
147
|
+
if (shadowRootsController && shadowRootsController.rollbackProvisionalShadowRoots) {
|
|
148
|
+
shadowRootsController.rollbackProvisionalShadowRoots(publicationToken);
|
|
149
|
+
}
|
|
150
|
+
publicationToken.$rShadowRootsController = undefined;
|
|
151
|
+
}
|
|
152
|
+
function consumeMutationRemoveSourceNode(remove) {
|
|
153
|
+
var sourceNode = sourceNodeByMutationRemove.get(remove);
|
|
154
|
+
sourceNodeByMutationRemove["delete"](remove);
|
|
155
|
+
return sourceNode;
|
|
156
|
+
}
|
|
157
|
+
function getMutationRemoveSourceNode(remove) {
|
|
158
|
+
return sourceNodeByMutationRemove.get(remove);
|
|
159
|
+
}
|
|
17
160
|
|
|
18
161
|
/**
|
|
19
162
|
* Buffers and aggregate mutations generated by a MutationObserver into MutationPayload
|
|
20
163
|
*/
|
|
21
|
-
function startMutationObserver(mutationCallback, configuration, shadowRootsController, target, mutationPerfCb) {
|
|
164
|
+
function startMutationObserver(mutationCallback, configuration, shadowRootsController, target, mutationPerfCb, mutationOverflowCb, mutationActivityCb, mutationNodeSerializationCb, isNodeIgnored, isNodePublished, isSourceActive, mutationResourceBudget) {
|
|
22
165
|
var MutationObserver = (0, _domMutationObservable.getMutationObserverConstructor)();
|
|
23
166
|
if (!MutationObserver) {
|
|
24
167
|
return {
|
|
25
168
|
stop: _browserCore.noop,
|
|
26
169
|
flush: _browserCore.noop,
|
|
27
|
-
reset: _browserCore.noop
|
|
170
|
+
reset: _browserCore.noop,
|
|
171
|
+
deactivate: _browserCore.noop
|
|
28
172
|
};
|
|
29
173
|
}
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
174
|
+
var active = true;
|
|
175
|
+
var isObserverActive = function isObserverActive() {
|
|
176
|
+
return active && (!isSourceActive || isSourceActive());
|
|
177
|
+
};
|
|
178
|
+
var mutationTasksController = createMutationTasksController(mutationCallback, configuration, shadowRootsController, mutationPerfCb, mutationOverflowCb, mutationNodeSerializationCb, isNodeIgnored, mutationResourceBudget);
|
|
179
|
+
var mutationBatch = (0, _mutationBatch.createMutationBatch)(function (mutations, mutationBatchContext) {
|
|
180
|
+
if (!isObserverActive()) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
var processStart = false ? getCurrentTime() : 0;
|
|
184
|
+
var overflowCountBeforeProcess = mutationTasksController.getOverflowCount();
|
|
185
|
+
var processed = processMutations(mutations, mutationCallback, configuration, shadowRootsController, mutationTasksController, isNodeIgnored, isNodePublished, mutationBatchContext);
|
|
186
|
+
if (false && mutationPerfCb) {
|
|
35
187
|
mutationPerfCb({
|
|
36
188
|
processMutationsCount: 1,
|
|
37
189
|
processMutationsDuration: getCurrentTime() - processStart
|
|
38
190
|
});
|
|
39
191
|
}
|
|
40
|
-
|
|
41
|
-
|
|
192
|
+
return mutationTasksController.getOverflowCount() === overflowCountBeforeProcess ? processed : false;
|
|
193
|
+
}, function (overflow) {
|
|
194
|
+
if (!active) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
observer.takeRecords();
|
|
198
|
+
mutationTasksController.reset();
|
|
199
|
+
reportMutationOverflow({
|
|
200
|
+
reason: overflow.reason || 'raw_mutation_watermark',
|
|
201
|
+
mutationRecordCount: overflow.mutationRecordCount,
|
|
202
|
+
mutationNodeCount: overflow.mutationNodeCount,
|
|
203
|
+
mutationApproxBytes: overflow.mutationApproxBytes
|
|
204
|
+
});
|
|
205
|
+
}, mutationResourceBudget);
|
|
206
|
+
var observer = new MutationObserver((0, _browserCore.monitor)(function (mutations) {
|
|
207
|
+
if (!isObserverActive()) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
notifyMutationActivity(mutations);
|
|
211
|
+
mutationBatch.addMutations(mutations);
|
|
212
|
+
}));
|
|
42
213
|
try {
|
|
43
214
|
observer.observe(target, {
|
|
44
215
|
attributeOldValue: true,
|
|
@@ -51,38 +222,193 @@ function startMutationObserver(mutationCallback, configuration, shadowRootsContr
|
|
|
51
222
|
} catch (err) {}
|
|
52
223
|
return {
|
|
53
224
|
stop: function stop() {
|
|
225
|
+
active = false;
|
|
54
226
|
observer.disconnect();
|
|
55
227
|
mutationBatch.stop();
|
|
56
228
|
mutationTasksController.stop();
|
|
57
229
|
},
|
|
230
|
+
deactivate: function deactivate() {
|
|
231
|
+
// Shadow-root generation cleanup is deliberately sliced. Stop native
|
|
232
|
+
// callbacks and release queued records/serializer tasks immediately,
|
|
233
|
+
// while leaving the physical disconnect and listener cleanup to stop().
|
|
234
|
+
//
|
|
235
|
+
// Do not mark the task controller as stopped here. A removed-subtree
|
|
236
|
+
// overflow can retire its shadow generation from inside processMutations
|
|
237
|
+
// and must still deliver the paired overflow callback after reset().
|
|
238
|
+
active = false;
|
|
239
|
+
mutationBatch.reset();
|
|
240
|
+
mutationTasksController.reset();
|
|
241
|
+
},
|
|
242
|
+
refreshAndFlushPendingRootForNode: function refreshAndFlushPendingRootForNode(node) {
|
|
243
|
+
if (!isObserverActive()) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
// A common attachShadow() pattern appends the host and attaches the root
|
|
247
|
+
// in the same JavaScript turn, before the native MutationObserver
|
|
248
|
+
// callback runs. Materialize those queued host records first so the
|
|
249
|
+
// targeted pending-root lookup also covers that synchronous window.
|
|
250
|
+
var pendingRecords = observer.takeRecords();
|
|
251
|
+
notifyMutationActivity(pendingRecords);
|
|
252
|
+
if (!mutationBatch.addMutations(pendingRecords)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
var batchFlushResult = mutationBatch.flush();
|
|
256
|
+
if (batchFlushResult === false) {
|
|
257
|
+
// A normalization overflow is reported from inside the batch
|
|
258
|
+
// processor. The batch drops its queued generation, but the task
|
|
259
|
+
// controller must also leave its overflowed state so a later DOM
|
|
260
|
+
// change can be recorded after recovery, matching the pre-slicing
|
|
261
|
+
// observer lifecycle.
|
|
262
|
+
mutationTasksController.reset();
|
|
263
|
+
}
|
|
264
|
+
if (batchFlushResult !== true) {
|
|
265
|
+
return batchFlushResult;
|
|
266
|
+
}
|
|
267
|
+
return mutationTasksController.refreshAndFlushPendingRootForNode(node);
|
|
268
|
+
},
|
|
58
269
|
flush: function flush() {
|
|
59
|
-
|
|
60
|
-
|
|
270
|
+
if (!isObserverActive()) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
var pendingRecords = observer.takeRecords();
|
|
274
|
+
notifyMutationActivity(pendingRecords);
|
|
275
|
+
if (!mutationBatch.addMutations(pendingRecords)) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
var overflowCountBeforeFlush = mutationTasksController.getOverflowCount();
|
|
279
|
+
var batchFlushResult = mutationBatch.flush();
|
|
280
|
+
if (batchFlushResult === false) {
|
|
281
|
+
// processMutations may fail the task controller while mutationBatch
|
|
282
|
+
// is draining a transaction. Reset both halves of the pipeline; an
|
|
283
|
+
// otherwise sticky overflow would silently drop every later change.
|
|
284
|
+
mutationTasksController.reset();
|
|
285
|
+
}
|
|
286
|
+
if (batchFlushResult !== true) {
|
|
287
|
+
return batchFlushResult;
|
|
288
|
+
}
|
|
289
|
+
var taskFlushResult = mutationTasksController.flush();
|
|
290
|
+
if (taskFlushResult === 'pending') {
|
|
291
|
+
return 'pending';
|
|
292
|
+
}
|
|
293
|
+
if (taskFlushResult === false) {
|
|
294
|
+
var overflowAlreadyReported = mutationTasksController.getOverflowCount() > overflowCountBeforeFlush;
|
|
295
|
+
mutationTasksController.reset();
|
|
296
|
+
if (!overflowAlreadyReported) {
|
|
297
|
+
reportMutationOverflow({
|
|
298
|
+
reason: 'serialization_budget'
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
61
304
|
},
|
|
62
305
|
reset: function reset() {
|
|
306
|
+
if (!isObserverActive()) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
// Drop records queued by the native observer before resetting the
|
|
310
|
+
// time-sliced serializer. Otherwise they may be delivered after a full
|
|
311
|
+
// snapshot and replay stale mutations on top of the new DOM baseline.
|
|
312
|
+
notifyMutationActivity(observer.takeRecords());
|
|
63
313
|
if (mutationBatch.reset) {
|
|
64
314
|
mutationBatch.reset();
|
|
65
315
|
}
|
|
66
316
|
mutationTasksController.reset();
|
|
67
317
|
}
|
|
68
318
|
};
|
|
319
|
+
function notifyMutationActivity(mutations) {
|
|
320
|
+
if (mutations.length && mutationActivityCb) {
|
|
321
|
+
mutationActivityCb(target);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function reportMutationOverflow(overflow) {
|
|
325
|
+
if (mutationResourceBudget && !mutationResourceBudget.failOnce()) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (mutationOverflowCb) {
|
|
329
|
+
mutationOverflowCb(overflow);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
69
332
|
}
|
|
70
|
-
function processMutations(mutations, mutationCallback, configuration, shadowRootsController, mutationTasksController) {
|
|
333
|
+
function processMutations(mutations, mutationCallback, configuration, shadowRootsController, mutationTasksController, isNodeIgnored, isNodePublished, mutationBatchContext) {
|
|
334
|
+
isNodeIgnored = isNodeIgnored || function () {
|
|
335
|
+
return false;
|
|
336
|
+
};
|
|
337
|
+
isNodePublished = isNodePublished || _serializationUtils.hasSerializedNode;
|
|
338
|
+
if (mutationTasksController.isOverflowed()) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
var transactionState = mutationBatchContext && mutationBatchContext.transaction;
|
|
71
342
|
var nodePrivacyLevelCache = new Map();
|
|
72
343
|
var pendingRootTasksToRefresh = new Set();
|
|
73
344
|
var childListMutations = [];
|
|
74
345
|
var characterDataMutations = [];
|
|
75
346
|
var attributeMutations = [];
|
|
347
|
+
var disconnectedShadowRootsCleaned = false;
|
|
348
|
+
var removedSubtreeTraversalState = {
|
|
349
|
+
deadline: undefined,
|
|
350
|
+
nodeCount: 0
|
|
351
|
+
};
|
|
352
|
+
var normalizationState = {
|
|
353
|
+
deadline: getCurrentTime() + MUTATION_NORMALIZATION_MAX_DURATION_MS,
|
|
354
|
+
exhausted: false,
|
|
355
|
+
mutationTasksController: mutationTasksController,
|
|
356
|
+
mutationRecordCount: mutations.length,
|
|
357
|
+
timeCheckCount: 0
|
|
358
|
+
};
|
|
359
|
+
var currentSourceState;
|
|
360
|
+
if (transactionState) {
|
|
361
|
+
currentSourceState = transactionState.$rCurrentSourceState;
|
|
362
|
+
if (!currentSourceState) {
|
|
363
|
+
currentSourceState = {
|
|
364
|
+
characters: 0
|
|
365
|
+
};
|
|
366
|
+
transactionState.$rCurrentSourceState = currentSourceState;
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
currentSourceState = {
|
|
370
|
+
characters: 0
|
|
371
|
+
};
|
|
372
|
+
}
|
|
76
373
|
for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
|
|
374
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
375
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
77
378
|
var mutation = mutations_1[_i];
|
|
78
|
-
if (mutation.type === 'childList') {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
379
|
+
if (mutation.type === 'childList' && mutation.removedNodes.length) {
|
|
380
|
+
if (!disconnectedShadowRootsCleaned && shadowRootsController.cleanupDisconnectedShadowRoots) {
|
|
381
|
+
// The controller owns a sliced registry cleanup. It is both safer and
|
|
382
|
+
// cheaper than walking every node in a potentially huge removed
|
|
383
|
+
// subtree merely to discover its shadow hosts. The root removal itself
|
|
384
|
+
// remains a complete replay mutation.
|
|
385
|
+
shadowRootsController.cleanupDisconnectedShadowRoots();
|
|
386
|
+
disconnectedShadowRootsCleaned = true;
|
|
387
|
+
} else if (!shadowRootsController.cleanupDisconnectedShadowRoots) {
|
|
388
|
+
// Preserve compatibility with lightweight/custom controllers that do
|
|
389
|
+
// not own a registry by falling back to the bounded subtree walk.
|
|
390
|
+
mutation.removedNodes.forEach(function (removedNode) {
|
|
391
|
+
if (!removedSubtreeTraversalState.overflowed && !traverseRemovedShadowDom(removedNode, shadowRootsController.removeShadowRoot, removedSubtreeTraversalState)) {
|
|
392
|
+
removedSubtreeTraversalState.overflowed = true;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
if (removedSubtreeTraversalState.overflowed) {
|
|
396
|
+
if (shadowRootsController.reset) {
|
|
397
|
+
try {
|
|
398
|
+
shadowRootsController.reset();
|
|
399
|
+
} catch (_) {}
|
|
400
|
+
}
|
|
401
|
+
mutationTasksController.handleOverflow({
|
|
402
|
+
reason: 'removed_subtree_watermark',
|
|
403
|
+
mutationNodeCount: removedSubtreeTraversalState.nodeCount
|
|
404
|
+
});
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
82
408
|
}
|
|
83
409
|
var target = mutation.target;
|
|
84
410
|
var pendingRootTask = mutationTasksController.findPendingRootTask(target);
|
|
85
|
-
if (!target.isConnected || !(0, _serializationUtils.nodeAndAncestorsHaveSerializedNode)(target) && !pendingRootTask || (0, _privacy.getNodePrivacyLevel)(target, configuration.defaultPrivacyLevel, nodePrivacyLevelCache) === _constants.NodePrivacyLevel.HIDDEN) {
|
|
411
|
+
if (!target.isConnected || !(0, _serializationUtils.nodeAndAncestorsHaveSerializedNode)(target) && !pendingRootTask || isNodeIgnored(target) && !pendingRootTask || (0, _privacy.getNodePrivacyLevel)(target, configuration.defaultPrivacyLevel, nodePrivacyLevelCache) === _constants.NodePrivacyLevel.HIDDEN) {
|
|
86
412
|
continue;
|
|
87
413
|
}
|
|
88
414
|
switch (mutation.type) {
|
|
@@ -97,14 +423,57 @@ function processMutations(mutations, mutationCallback, configuration, shadowRoot
|
|
|
97
423
|
break;
|
|
98
424
|
}
|
|
99
425
|
}
|
|
100
|
-
|
|
426
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController, true)) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
var supportsMutationGroups = Boolean(mutationTasksController.createMutationGroup);
|
|
430
|
+
var isPureAddTransaction = Boolean(transactionState && transactionState.$rPureAdd);
|
|
431
|
+
if (transactionState && transactionState.$rFailed) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
var shouldCreateMutationGroup = supportsMutationGroups && (!isPureAddTransaction && Boolean(transactionState) || shouldUseAtomicMutationGroup(childListMutations, characterDataMutations, attributeMutations));
|
|
435
|
+
var mutationGroup;
|
|
436
|
+
if (transactionState && !isPureAddTransaction) {
|
|
437
|
+
if (!transactionState.$rMutationGroup) {
|
|
438
|
+
transactionState.$rMutationGroup = mutationTasksController.createMutationGroup(mutationCallback);
|
|
439
|
+
if (transactionState.$rMutationGroup) {
|
|
440
|
+
transactionState.$rMutationGroup.$rTransactionState = transactionState;
|
|
441
|
+
}
|
|
442
|
+
transactionState.$rPayload = {
|
|
443
|
+
removes: [],
|
|
444
|
+
texts: [],
|
|
445
|
+
attributes: []
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
mutationGroup = transactionState.$rMutationGroup;
|
|
449
|
+
} else if (shouldCreateMutationGroup) {
|
|
450
|
+
mutationGroup = mutationTasksController.createMutationGroup(mutationCallback);
|
|
451
|
+
}
|
|
452
|
+
// Overflow recovery can synchronously reset the controller from inside the
|
|
453
|
+
// callback. An empty result is therefore the durable failure signal; the
|
|
454
|
+
// transient overflow flag is not safe to re-read here.
|
|
455
|
+
if (shouldCreateMutationGroup && !mutationGroup) {
|
|
456
|
+
if (transactionState) {
|
|
457
|
+
transactionState.$rFailed = true;
|
|
458
|
+
}
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
var _processChildListMutations = processChildListMutations(childListMutations, configuration, shadowRootsController, nodePrivacyLevelCache, mutationTasksController, pendingRootTasksToRefresh, normalizationState, isNodePublished, mutationGroup, mutationBatchContext && mutationBatchContext.$rTextReplacementByRemovedNode);
|
|
101
462
|
var removes = _processChildListMutations.removes;
|
|
102
463
|
var serializedNodeIds = _processChildListMutations.serializedNodeIds;
|
|
464
|
+
if (_processChildListMutations.overflowed) {
|
|
465
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
103
468
|
function hasBeenSerialized(node) {
|
|
104
469
|
return (0, _serializationUtils.hasSerializedNode)(node) && serializedNodeIds.has((0, _serializationUtils.getSerializedNodeId)(node));
|
|
105
470
|
}
|
|
106
471
|
var pendingCharacterDataMutations = [];
|
|
107
472
|
for (var _a = 0, characterDataMutations_1 = characterDataMutations; _a < characterDataMutations_1.length; _a++) {
|
|
473
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
474
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
108
477
|
var characterDataMutation = characterDataMutations_1[_a];
|
|
109
478
|
var pendingCharacterDataRootTask = mutationTasksController.findPendingRootTask(characterDataMutation.target);
|
|
110
479
|
if (pendingCharacterDataRootTask) {
|
|
@@ -115,9 +484,22 @@ function processMutations(mutations, mutationCallback, configuration, shadowRoot
|
|
|
115
484
|
pendingCharacterDataMutations.push(characterDataMutation);
|
|
116
485
|
}
|
|
117
486
|
}
|
|
118
|
-
var texts = processCharacterDataMutations(pendingCharacterDataMutations, configuration, nodePrivacyLevelCache);
|
|
487
|
+
var texts = processCharacterDataMutations(pendingCharacterDataMutations, configuration, nodePrivacyLevelCache, mutationTasksController, normalizationState, currentSourceState, transactionState && (transactionState.$rHandledCharacterDataNodes || (transactionState.$rHandledCharacterDataNodes = new Set())));
|
|
488
|
+
consumeMutationNormalizationBudget(normalizationState, mutationTasksController, true);
|
|
489
|
+
if (normalizationState.exhausted) {
|
|
490
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (mutationTasksController.isOverflowed()) {
|
|
494
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
119
497
|
var pendingAttributeMutations = [];
|
|
120
498
|
for (var _b = 0, attributeMutations_1 = attributeMutations; _b < attributeMutations_1.length; _b++) {
|
|
499
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
500
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
121
503
|
var attributeMutation = attributeMutations_1[_b];
|
|
122
504
|
var pendingAttributeRootTask = mutationTasksController.findPendingRootTask(attributeMutation.target);
|
|
123
505
|
if (pendingAttributeRootTask) {
|
|
@@ -128,10 +510,74 @@ function processMutations(mutations, mutationCallback, configuration, shadowRoot
|
|
|
128
510
|
pendingAttributeMutations.push(attributeMutation);
|
|
129
511
|
}
|
|
130
512
|
}
|
|
131
|
-
var attributes = processAttributesMutations(pendingAttributeMutations, configuration, nodePrivacyLevelCache);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
513
|
+
var attributes = processAttributesMutations(pendingAttributeMutations, configuration, nodePrivacyLevelCache, mutationTasksController, normalizationState, currentSourceState, transactionState && (transactionState.$rHandledAttributeMutations || (transactionState.$rHandledAttributeMutations = new Map())));
|
|
514
|
+
consumeMutationNormalizationBudget(normalizationState, mutationTasksController, true);
|
|
515
|
+
if (normalizationState.exhausted) {
|
|
516
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (mutationTasksController.isOverflowed()) {
|
|
520
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
var rootTasksToRefresh = Array.from(pendingRootTasksToRefresh);
|
|
524
|
+
var refreshedRootTasks = transactionState && rootTasksToRefresh.length ? transactionState.$rRefreshedRootTasks || (transactionState.$rRefreshedRootTasks = new Set()) : undefined;
|
|
525
|
+
for (var refreshIndex = 0; refreshIndex < rootTasksToRefresh.length; refreshIndex += 1) {
|
|
526
|
+
var rootTaskToRefresh = rootTasksToRefresh[refreshIndex];
|
|
527
|
+
if (refreshedRootTasks && refreshedRootTasks.has(rootTaskToRefresh)) {
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
531
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (!mutationTasksController.refreshPendingRootTask(rootTaskToRefresh)) {
|
|
535
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (refreshedRootTasks) {
|
|
539
|
+
refreshedRootTasks.add(rootTaskToRefresh);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController, true)) {
|
|
543
|
+
cancelNormalizedMutationGroup(mutationTasksController, mutationGroup);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (transactionState && !isPureAddTransaction) {
|
|
547
|
+
Array.prototype.push.apply(transactionState.$rPayload.removes, removes);
|
|
548
|
+
Array.prototype.push.apply(transactionState.$rPayload.texts, texts);
|
|
549
|
+
Array.prototype.push.apply(transactionState.$rPayload.attributes, attributes);
|
|
550
|
+
if (mutationBatchContext.isLast) {
|
|
551
|
+
completeNormalizedMutation(mutationCallback, mutationTasksController, mutationGroup, transactionState.$rPayload.removes, transactionState.$rPayload.texts, transactionState.$rPayload.attributes);
|
|
552
|
+
transactionState.$rCompleted = true;
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
completeNormalizedMutation(mutationCallback, mutationTasksController, mutationGroup, removes, texts, attributes);
|
|
556
|
+
}
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
function shouldUseAtomicMutationGroup(childListMutations, characterDataMutations, attributeMutations) {
|
|
560
|
+
if (characterDataMutations.length || attributeMutations.length) {
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
for (var mutationIndex = 0; mutationIndex < childListMutations.length; mutationIndex += 1) {
|
|
564
|
+
var mutation = childListMutations[mutationIndex];
|
|
565
|
+
if (mutation.removedNodes.length) {
|
|
566
|
+
return true;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
function completeNormalizedMutation(mutationCallback, mutationTasksController, mutationGroup, removes, texts, attributes) {
|
|
572
|
+
if (mutationGroup && mutationTasksController.completeMutationGroup) {
|
|
573
|
+
mutationTasksController.completeMutationGroup(mutationGroup, {
|
|
574
|
+
adds: [],
|
|
575
|
+
removes: removes,
|
|
576
|
+
texts: texts,
|
|
577
|
+
attributes: attributes
|
|
578
|
+
});
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
135
581
|
if (!texts.length && !attributes.length && !removes.length) {
|
|
136
582
|
return;
|
|
137
583
|
}
|
|
@@ -142,7 +588,15 @@ function processMutations(mutations, mutationCallback, configuration, shadowRoot
|
|
|
142
588
|
attributes: attributes
|
|
143
589
|
});
|
|
144
590
|
}
|
|
145
|
-
function
|
|
591
|
+
function cancelNormalizedMutationGroup(mutationTasksController, mutationGroup) {
|
|
592
|
+
if (mutationGroup && mutationTasksController.cancelMutationGroup) {
|
|
593
|
+
if (mutationGroup.$rTransactionState) {
|
|
594
|
+
mutationGroup.$rTransactionState.$rFailed = true;
|
|
595
|
+
}
|
|
596
|
+
mutationTasksController.cancelMutationGroup(mutationGroup);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
function processChildListMutations(mutations, configuration, shadowRootsController, nodePrivacyLevelCache, mutationTasksController, pendingRootTasksToRefresh, normalizationState, isNodePublished, mutationGroup, coalescedTextReplacementByRemovedNode) {
|
|
146
600
|
// First, we iterate over mutations to collect:
|
|
147
601
|
//
|
|
148
602
|
// * nodes that have been added in the document and not removed by a subsequent mutation
|
|
@@ -156,17 +610,181 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
156
610
|
// the node will be in both sets.
|
|
157
611
|
var addedAndMovedNodes = new Set();
|
|
158
612
|
var removedNodes = new Map();
|
|
613
|
+
var replacementNodes = new Set();
|
|
614
|
+
var singleReplacementNodes = new Map();
|
|
159
615
|
for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
|
|
160
616
|
var mutation = mutations_1[_i];
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
617
|
+
var coalescedTextReplacementMarker = undefined;
|
|
618
|
+
var expectedTextReplacementSource;
|
|
619
|
+
if (coalescedTextReplacementByRemovedNode) {
|
|
620
|
+
for (var markerIndex = 0; markerIndex < mutation.removedNodes.length; markerIndex += 1) {
|
|
621
|
+
var markerSource = mutation.removedNodes[markerIndex];
|
|
622
|
+
var currentMarker = coalescedTextReplacementByRemovedNode.get(markerSource);
|
|
623
|
+
if (currentMarker) {
|
|
624
|
+
if (coalescedTextReplacementMarker) {
|
|
625
|
+
mutationTasksController.handleOverflow({
|
|
626
|
+
reason: 'published_move_cancelled'
|
|
627
|
+
});
|
|
628
|
+
return createChildListNormalizationOverflowResult();
|
|
629
|
+
}
|
|
630
|
+
coalescedTextReplacementMarker = currentMarker;
|
|
631
|
+
expectedTextReplacementSource = markerSource;
|
|
632
|
+
}
|
|
167
633
|
}
|
|
168
|
-
|
|
169
|
-
|
|
634
|
+
}
|
|
635
|
+
if (coalescedTextReplacementMarker) {
|
|
636
|
+
var markerAddedNode = mutation.addedNodes[0];
|
|
637
|
+
var markerReachedFinal = markerAddedNode === coalescedTextReplacementMarker[1];
|
|
638
|
+
if (mutation.removedNodes.length !== 1 || mutation.addedNodes.length !== 1 || expectedTextReplacementSource.nodeType !== 3 || !markerAddedNode || markerAddedNode.nodeType !== 3 || mutation.target !== coalescedTextReplacementMarker[0] || expectedTextReplacementSource.isConnected || isNodePublished(expectedTextReplacementSource) || mutationTasksController.findPendingRootTask(expectedTextReplacementSource) || !markerReachedFinal && (markerAddedNode.isConnected || isNodePublished(markerAddedNode) || mutationTasksController.findPendingRootTask(markerAddedNode))) {
|
|
639
|
+
mutationTasksController.handleOverflow({
|
|
640
|
+
reason: 'published_move_cancelled'
|
|
641
|
+
});
|
|
642
|
+
return createChildListNormalizationOverflowResult();
|
|
643
|
+
}
|
|
644
|
+
coalescedTextReplacementByRemovedNode["delete"](expectedTextReplacementSource);
|
|
645
|
+
if (!markerReachedFinal) {
|
|
646
|
+
coalescedTextReplacementByRemovedNode.set(markerAddedNode, coalescedTextReplacementMarker);
|
|
647
|
+
}
|
|
648
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
649
|
+
return createChildListNormalizationOverflowResult();
|
|
650
|
+
}
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
if (mutation.removedNodes.length === 1 && mutation.addedNodes.length === 1 && mutation.removedNodes[0] !== mutation.addedNodes[0]) {
|
|
654
|
+
singleReplacementNodes.set(mutation.removedNodes[0], [mutation.addedNodes[0], mutation.target, mutation.previousSibling, mutation.nextSibling]);
|
|
655
|
+
}
|
|
656
|
+
var hasPublishedRemoval = false;
|
|
657
|
+
for (var publishedRemovalIndex = 0; publishedRemovalIndex < mutation.removedNodes.length; publishedRemovalIndex += 1) {
|
|
658
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
659
|
+
return createChildListNormalizationOverflowResult();
|
|
660
|
+
}
|
|
661
|
+
if (isNodePublished(mutation.removedNodes[publishedRemovalIndex]) || replacementNodes.has(mutation.removedNodes[publishedRemovalIndex])) {
|
|
662
|
+
hasPublishedRemoval = true;
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
var structuralState = mutation.$rStructuralState;
|
|
667
|
+
if (structuralState && hasPublishedRemoval) {
|
|
668
|
+
structuralState.$rHasPublishedRemoval = true;
|
|
669
|
+
}
|
|
670
|
+
for (var addedIndex = 0; addedIndex < mutation.addedNodes.length; addedIndex += 1) {
|
|
671
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
672
|
+
return createChildListNormalizationOverflowResult();
|
|
673
|
+
}
|
|
674
|
+
var addedNode = mutation.addedNodes[addedIndex];
|
|
675
|
+
addedAndMovedNodes.add(addedNode);
|
|
676
|
+
if (hasPublishedRemoval || structuralState && structuralState.$rHasPublishedRemoval) {
|
|
677
|
+
replacementNodes.add(addedNode);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
for (var removedIndex = 0; removedIndex < mutation.removedNodes.length; removedIndex += 1) {
|
|
681
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
682
|
+
return createChildListNormalizationOverflowResult();
|
|
683
|
+
}
|
|
684
|
+
var removedNode = mutation.removedNodes[removedIndex];
|
|
685
|
+
if (!addedAndMovedNodes.has(removedNode)) {
|
|
686
|
+
removedNodes.set(removedNode, mutation.target);
|
|
687
|
+
}
|
|
688
|
+
addedAndMovedNodes["delete"](removedNode);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// A renderer can replace the same text/element again before the previous
|
|
693
|
+
// asynchronous add is emitted. Keep the original published removal and
|
|
694
|
+
// retarget its atomic add to the latest node. Treating the unpublished
|
|
695
|
+
// intermediate node as a cancelled published move would unnecessarily
|
|
696
|
+
// invalidate the whole replay while counters or framework text churn.
|
|
697
|
+
var singleReplacementEntries = Array.from(singleReplacementNodes);
|
|
698
|
+
for (var replacementIndex = 0; replacementIndex < singleReplacementEntries.length; replacementIndex += 1) {
|
|
699
|
+
var replacementEntry = singleReplacementEntries[replacementIndex];
|
|
700
|
+
var replacedNode = replacementEntry[0];
|
|
701
|
+
var replacementNode = replacementEntry[1][0];
|
|
702
|
+
var replacementParent = replacementEntry[1][1];
|
|
703
|
+
var replacementDepth = 0;
|
|
704
|
+
while (!replacementNode.isConnected && replacementDepth < singleReplacementNodes.size) {
|
|
705
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
706
|
+
return createChildListNormalizationOverflowResult();
|
|
707
|
+
}
|
|
708
|
+
var intermediateReplacementOwner = mutationTasksController.findPendingRootTask(replacementNode);
|
|
709
|
+
if (isNodePublished(replacementNode) || intermediateReplacementOwner && intermediateReplacementOwner.rootNode === replacementNode) {
|
|
710
|
+
mutationTasksController.handleOverflow({
|
|
711
|
+
reason: 'published_move_cancelled'
|
|
712
|
+
});
|
|
713
|
+
return createChildListNormalizationOverflowResult();
|
|
714
|
+
}
|
|
715
|
+
var nextReplacement = singleReplacementNodes.get(replacementNode);
|
|
716
|
+
if (!nextReplacement || nextReplacement[1] !== replacementParent) {
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
replacementNode = nextReplacement[0];
|
|
720
|
+
replacementDepth += 1;
|
|
721
|
+
}
|
|
722
|
+
var queuedReplacementSourceNode = replacementNode;
|
|
723
|
+
var replacementTask = mutationTasksController.findPendingRootTask(replacedNode, replacementParent);
|
|
724
|
+
var replacementOwner = mutationTasksController.findPendingRootTask(replacementNode);
|
|
725
|
+
var coalescedDetachedTextReplacement = false;
|
|
726
|
+
// A hot textContent loop can detach the text node stored by an older
|
|
727
|
+
// normalization chunk before that chunk runs. Resolve only the exact live
|
|
728
|
+
// node occupying the MutationRecord's sibling slot. This is O(1), and all
|
|
729
|
+
// element moves, cross-parent moves, published intermediates, ambiguous
|
|
730
|
+
// slots and task-owner conflicts keep the existing fail-closed path.
|
|
731
|
+
if (!replacementNode.isConnected && replacedNode.nodeType === 3 && replacementNode.nodeType === 3 && !isNodePublished(replacementNode) && !replacementOwner && isNodePublished(replacementParent) && (isNodePublished(replacedNode) || replacementTask && replacementTask.rootNode === replacedNode && replacementTask.requiresBaselineOnDrop)) {
|
|
732
|
+
var currentSlotNode = findCurrentTextNodeAtReplacementSlot(replacementParent, replacementEntry[1][2], replacementEntry[1][3]);
|
|
733
|
+
var currentSlotOwner = currentSlotNode ? mutationTasksController.findPendingRootTask(currentSlotNode) : undefined;
|
|
734
|
+
if (currentSlotNode && !isNodePublished(currentSlotNode) && !currentSlotOwner) {
|
|
735
|
+
replacementNode = currentSlotNode;
|
|
736
|
+
coalescedDetachedTextReplacement = true;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (coalescedDetachedTextReplacement) {
|
|
740
|
+
if (addedAndMovedNodes["delete"](queuedReplacementSourceNode)) {
|
|
741
|
+
addedAndMovedNodes.add(replacementNode);
|
|
742
|
+
}
|
|
743
|
+
if (replacementNodes["delete"](queuedReplacementSourceNode)) {
|
|
744
|
+
replacementNodes.add(replacementNode);
|
|
745
|
+
}
|
|
746
|
+
if (coalescedTextReplacementByRemovedNode) {
|
|
747
|
+
coalescedTextReplacementByRemovedNode.set(queuedReplacementSourceNode, [replacementParent, replacementNode]);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (replacementTask && replacementTask.rootNode === replacedNode && !replacementOwner && !isNodePublished(replacementNode) && !replacedNode.isConnected && replacementNode.isConnected && (0, _browserCore.getParentNode)(replacementNode) === replacementParent) {
|
|
751
|
+
if (!mutationTasksController.$rRetargetPendingRootTask(replacementTask, replacementNode)) {
|
|
752
|
+
return createChildListNormalizationOverflowResult();
|
|
753
|
+
}
|
|
754
|
+
removedNodes["delete"](replacedNode);
|
|
755
|
+
addedAndMovedNodes["delete"](replacementNode);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
var publishedMoveDependencyRoots = new Set();
|
|
759
|
+
var sharedDependencyState = getMutationDependencyState(shadowRootsController);
|
|
760
|
+
var removedNodesForDependency = Array.from(removedNodes.keys());
|
|
761
|
+
for (var dependencyIndex = 0; dependencyIndex < removedNodesForDependency.length; dependencyIndex += 1) {
|
|
762
|
+
var publishedRemovedNode = removedNodesForDependency[dependencyIndex];
|
|
763
|
+
if (!isNodePublished(publishedRemovedNode)) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
var currentDependencyNode = publishedRemovedNode;
|
|
767
|
+
var dependencyDepth = 0;
|
|
768
|
+
while (currentDependencyNode && dependencyDepth < _serializationUtils.MAX_SERIALIZED_NODE_ANCESTOR_DEPTH) {
|
|
769
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
770
|
+
return createChildListNormalizationOverflowResult();
|
|
771
|
+
}
|
|
772
|
+
if (sharedDependencyState) {
|
|
773
|
+
sharedDependencyState.$rPublishedRoots.add(currentDependencyNode);
|
|
774
|
+
if (sharedDependencyState.$rLocallyDroppedRoots.has(currentDependencyNode)) {
|
|
775
|
+
mutationTasksController.handleOverflow({
|
|
776
|
+
reason: 'published_move_serialization_watermark'
|
|
777
|
+
});
|
|
778
|
+
return createChildListNormalizationOverflowResult();
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
if (addedAndMovedNodes.has(currentDependencyNode)) {
|
|
782
|
+
publishedMoveDependencyRoots.add(currentDependencyNode);
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
currentDependencyNode = (0, _browserCore.getParentNode)(currentDependencyNode);
|
|
786
|
+
dependencyDepth += 1;
|
|
787
|
+
}
|
|
170
788
|
}
|
|
171
789
|
|
|
172
790
|
// Then, we sort nodes that are still in the document by topological order, for two reasons:
|
|
@@ -180,15 +798,28 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
180
798
|
// siblings, we want to iterate from last to first. This will ensure that any "next" node is
|
|
181
799
|
// already serialized and have an id.
|
|
182
800
|
var sortedAddedAndMovedNodes = Array.from(addedAndMovedNodes);
|
|
183
|
-
sortAddedAndMovedNodes(sortedAddedAndMovedNodes)
|
|
801
|
+
if (!sortAddedAndMovedNodes(sortedAddedAndMovedNodes, normalizationState)) {
|
|
802
|
+
// Sorting can dominate the observer callback for a wide mutation batch.
|
|
803
|
+
// The batch is still unpublished here. Retire its complete serializer
|
|
804
|
+
// generation and require a replacement baseline rather than publishing a
|
|
805
|
+
// partially ordered prefix.
|
|
806
|
+
abortMutationNormalization(normalizationState, mutationTasksController);
|
|
807
|
+
return createChildListNormalizationOverflowResult();
|
|
808
|
+
}
|
|
184
809
|
|
|
185
810
|
// Then, we iterate over our sorted node sets to emit mutations. We collect the newly serialized
|
|
186
811
|
// node ids in a set to be able to skip subsequent related mutations.
|
|
187
812
|
var serializedNodeIds = new Set();
|
|
188
813
|
for (var _a = 0, sortedAddedAndMovedNodes_1 = sortedAddedAndMovedNodes; _a < sortedAddedAndMovedNodes_1.length; _a++) {
|
|
814
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
815
|
+
return createChildListNormalizationOverflowResult();
|
|
816
|
+
}
|
|
189
817
|
var node = sortedAddedAndMovedNodes_1[_a];
|
|
190
818
|
var pendingRootTask = mutationTasksController.findPendingRootTask(node);
|
|
191
819
|
if (pendingRootTask) {
|
|
820
|
+
if (isNodePublished(node)) {
|
|
821
|
+
mutationTasksController.markPendingRootTaskPublishedDependency(pendingRootTask);
|
|
822
|
+
}
|
|
192
823
|
pendingRootTasksToRefresh.add(pendingRootTask);
|
|
193
824
|
continue;
|
|
194
825
|
}
|
|
@@ -199,32 +830,80 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
199
830
|
if (parentNodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === _constants.NodePrivacyLevel.IGNORE) {
|
|
200
831
|
continue;
|
|
201
832
|
}
|
|
202
|
-
mutationTasksController.addPendingRootTask(node, {
|
|
833
|
+
if (!mutationTasksController.addPendingRootTask(node, {
|
|
203
834
|
serializedNodeIds: serializedNodeIds,
|
|
204
835
|
parentNodePrivacyLevel: parentNodePrivacyLevel,
|
|
205
836
|
serializationContext: {
|
|
206
837
|
status: _serialize.SerializationContextStatus.MUTATION,
|
|
207
838
|
shadowRootsController: shadowRootsController
|
|
208
839
|
},
|
|
209
|
-
configuration: configuration
|
|
210
|
-
|
|
840
|
+
configuration: configuration,
|
|
841
|
+
normalizationState: normalizationState,
|
|
842
|
+
// A task paired with a published removal is part of one atomic
|
|
843
|
+
// replacement. If its add cannot be serialized, emitting only the
|
|
844
|
+
// removal would leave a permanent hole in the replay tree.
|
|
845
|
+
requiresBaselineOnDrop: isNodePublished(node) || replacementNodes.has(node) || publishedMoveDependencyRoots.has(node) || sharedDependencyState && sharedDependencyState.$rPublishedRoots.has(node),
|
|
846
|
+
mutationGroup: mutationGroup
|
|
847
|
+
})) {
|
|
848
|
+
return {
|
|
849
|
+
removes: [],
|
|
850
|
+
serializedNodeIds: serializedNodeIds,
|
|
851
|
+
overflowed: true
|
|
852
|
+
};
|
|
853
|
+
}
|
|
211
854
|
}
|
|
212
855
|
// Finally, we emit remove mutations.
|
|
213
856
|
var removedNodeMutations = [];
|
|
214
|
-
|
|
215
|
-
|
|
857
|
+
var pendingRootRemovalOverflowed = false;
|
|
858
|
+
var removedNodeEntries = Array.from(removedNodes);
|
|
859
|
+
for (var removedEntryIndex = 0; removedEntryIndex < removedNodeEntries.length; removedEntryIndex += 1) {
|
|
860
|
+
if (pendingRootRemovalOverflowed) {
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
864
|
+
return createChildListNormalizationOverflowResult();
|
|
865
|
+
}
|
|
866
|
+
var removedNodeEntry = removedNodeEntries[removedEntryIndex];
|
|
867
|
+
var node = removedNodeEntry[0];
|
|
868
|
+
var parent = removedNodeEntry[1];
|
|
869
|
+
// A removed descendant is already detached when the MutationRecord is
|
|
870
|
+
// processed, so walking from it can no longer reach an unpublished
|
|
871
|
+
// pending root. The mutation target is its former parent and still gives
|
|
872
|
+
// us the path needed to refresh that root instead of publishing a stale
|
|
873
|
+
// subtree followed by an ineffective remove.
|
|
874
|
+
var pendingRootTask = mutationTasksController.findPendingRootTask(node, parent);
|
|
216
875
|
if (pendingRootTask) {
|
|
876
|
+
if (isNodePublished(node)) {
|
|
877
|
+
mutationTasksController.markPendingRootTaskPublishedDependency(pendingRootTask);
|
|
878
|
+
}
|
|
879
|
+
if (node !== pendingRootTask.rootNode && pendingRootTask.rootNode.isConnected) {
|
|
880
|
+
// Several descendants can be removed in one batch. Rebuild the
|
|
881
|
+
// unpublished root once after normalization instead of once per node.
|
|
882
|
+
pendingRootTasksToRefresh.add(pendingRootTask);
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
217
885
|
pendingRootTasksToRefresh["delete"](pendingRootTask);
|
|
218
|
-
mutationTasksController.handlePendingRootRemoval(pendingRootTask, node)
|
|
219
|
-
|
|
886
|
+
if (!mutationTasksController.handlePendingRootRemoval(pendingRootTask, node)) {
|
|
887
|
+
pendingRootRemovalOverflowed = true;
|
|
888
|
+
}
|
|
889
|
+
continue;
|
|
220
890
|
}
|
|
221
|
-
if ((0, _serializationUtils.hasSerializedNode)(node)) {
|
|
222
|
-
|
|
891
|
+
if ((0, _serializationUtils.hasSerializedNode)(node) && isNodePublished(node)) {
|
|
892
|
+
var removeMutation = {
|
|
223
893
|
parentId: (0, _serializationUtils.getSerializedNodeId)(parent),
|
|
224
894
|
id: (0, _serializationUtils.getSerializedNodeId)(node)
|
|
225
|
-
}
|
|
895
|
+
};
|
|
896
|
+
sourceNodeByMutationRemove.set(removeMutation, node);
|
|
897
|
+
removedNodeMutations.push(removeMutation);
|
|
226
898
|
}
|
|
227
|
-
}
|
|
899
|
+
}
|
|
900
|
+
if (pendingRootRemovalOverflowed) {
|
|
901
|
+
return {
|
|
902
|
+
removes: [],
|
|
903
|
+
serializedNodeIds: serializedNodeIds,
|
|
904
|
+
overflowed: true
|
|
905
|
+
};
|
|
906
|
+
}
|
|
228
907
|
return {
|
|
229
908
|
removes: removedNodeMutations,
|
|
230
909
|
serializedNodeIds: serializedNodeIds,
|
|
@@ -234,12 +913,37 @@ function processChildListMutations(mutations, configuration, shadowRootsControll
|
|
|
234
913
|
return (0, _serializationUtils.hasSerializedNode)(node) && serializedNodeIds.has((0, _serializationUtils.getSerializedNodeId)(node));
|
|
235
914
|
}
|
|
236
915
|
}
|
|
237
|
-
function
|
|
916
|
+
function findCurrentTextNodeAtReplacementSlot(parent, previousSibling, nextSibling) {
|
|
917
|
+
// `undefined` means the synthetic record did not preserve native slot
|
|
918
|
+
// evidence. Never infer a replacement from the current DOM in that case.
|
|
919
|
+
if (previousSibling === undefined || nextSibling === undefined) {
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (previousSibling && (0, _browserCore.getParentNode)(previousSibling) !== parent || nextSibling && (0, _browserCore.getParentNode)(nextSibling) !== parent) {
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
var candidate = previousSibling ? previousSibling.nextSibling : parent.firstChild;
|
|
926
|
+
if (!candidate || candidate === nextSibling || candidate.nextSibling !== nextSibling || !candidate.isConnected || candidate.nodeType !== 3) {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
return candidate;
|
|
930
|
+
}
|
|
931
|
+
function createChildListNormalizationOverflowResult() {
|
|
932
|
+
return {
|
|
933
|
+
removes: [],
|
|
934
|
+
serializedNodeIds: new Set(),
|
|
935
|
+
overflowed: true
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function processCharacterDataMutations(mutations, configuration, nodePrivacyLevelCache, mutationTasksController, normalizationState, currentSourceState, handledNodes) {
|
|
238
939
|
var textMutations = [];
|
|
239
940
|
|
|
240
941
|
// Deduplicate mutations based on their target node
|
|
241
|
-
|
|
942
|
+
handledNodes = handledNodes || new Set();
|
|
242
943
|
var filteredMutations = mutations.filter(function (mutation) {
|
|
944
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
243
947
|
if (handledNodes.has(mutation.target)) {
|
|
244
948
|
return false;
|
|
245
949
|
}
|
|
@@ -249,6 +953,9 @@ function processCharacterDataMutations(mutations, configuration, nodePrivacyLeve
|
|
|
249
953
|
|
|
250
954
|
// Emit mutations
|
|
251
955
|
for (var _i = 0, filteredMutations_1 = filteredMutations; _i < filteredMutations_1.length; _i++) {
|
|
956
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
957
|
+
return textMutations;
|
|
958
|
+
}
|
|
252
959
|
var mutation = filteredMutations_1[_i];
|
|
253
960
|
var value = mutation.target.textContent;
|
|
254
961
|
if (value === mutation.oldValue) {
|
|
@@ -258,19 +965,30 @@ function processCharacterDataMutations(mutations, configuration, nodePrivacyLeve
|
|
|
258
965
|
if (parentNodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === _constants.NodePrivacyLevel.IGNORE) {
|
|
259
966
|
continue;
|
|
260
967
|
}
|
|
968
|
+
var serializedTextValue = (0, _serialize.truncateSerializedValue)((0, _browserCore.isNullUndefinedDefaultValue)((0, _privacy.getTextContent)(configuration, mutation.target, false, parentNodePrivacyLevel, null)), MAX_MUTATION_SERIALIZED_VALUE_CHARACTERS);
|
|
969
|
+
if (!reserveCurrentMutationSource(serializedTextValue, currentSourceState)) {
|
|
970
|
+
mutationTasksController.handleOverflow({
|
|
971
|
+
reason: 'mutation_current_source_watermark',
|
|
972
|
+
mutationApproxBytes: currentSourceState.characters * 2
|
|
973
|
+
});
|
|
974
|
+
return [];
|
|
975
|
+
}
|
|
261
976
|
textMutations.push({
|
|
262
977
|
id: (0, _serializationUtils.getSerializedNodeId)(mutation.target),
|
|
263
|
-
value:
|
|
978
|
+
value: serializedTextValue
|
|
264
979
|
});
|
|
265
980
|
}
|
|
266
981
|
return textMutations;
|
|
267
982
|
}
|
|
268
|
-
function processAttributesMutations(mutations, configuration, nodePrivacyLevelCache) {
|
|
983
|
+
function processAttributesMutations(mutations, configuration, nodePrivacyLevelCache, mutationTasksController, normalizationState, currentSourceState, handledElements) {
|
|
269
984
|
var attributeMutations = [];
|
|
270
985
|
|
|
271
986
|
// Deduplicate mutations based on their target node and changed attribute
|
|
272
|
-
|
|
987
|
+
handledElements = handledElements || new Map();
|
|
273
988
|
var filteredMutations = mutations.filter(function (mutation) {
|
|
989
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
274
992
|
var handledAttributes = handledElements.get(mutation.target);
|
|
275
993
|
if (handledAttributes && handledAttributes.has(mutation.attributeName)) {
|
|
276
994
|
return false;
|
|
@@ -286,6 +1004,9 @@ function processAttributesMutations(mutations, configuration, nodePrivacyLevelCa
|
|
|
286
1004
|
// Emit mutations
|
|
287
1005
|
var emittedMutations = new Map();
|
|
288
1006
|
for (var _i = 0, filteredMutations_2 = filteredMutations; _i < filteredMutations_2.length; _i++) {
|
|
1007
|
+
if (consumeMutationNormalizationBudget(normalizationState, mutationTasksController)) {
|
|
1008
|
+
return attributeMutations;
|
|
1009
|
+
}
|
|
289
1010
|
var mutation = filteredMutations_2[_i];
|
|
290
1011
|
var uncensoredValue = mutation.target.getAttribute(mutation.attributeName);
|
|
291
1012
|
if (uncensoredValue === mutation.oldValue) {
|
|
@@ -305,6 +1026,14 @@ function processAttributesMutations(mutations, configuration, nodePrivacyLevelCa
|
|
|
305
1026
|
} else {
|
|
306
1027
|
transformedValue = null;
|
|
307
1028
|
}
|
|
1029
|
+
transformedValue = (0, _serialize.truncateSerializedValue)(transformedValue, MAX_MUTATION_SERIALIZED_VALUE_CHARACTERS);
|
|
1030
|
+
if (!reserveCurrentMutationSource(transformedValue, currentSourceState)) {
|
|
1031
|
+
mutationTasksController.handleOverflow({
|
|
1032
|
+
reason: 'mutation_current_source_watermark',
|
|
1033
|
+
mutationApproxBytes: currentSourceState.characters * 2
|
|
1034
|
+
});
|
|
1035
|
+
return [];
|
|
1036
|
+
}
|
|
308
1037
|
var emittedMutation = emittedMutations.get(mutation.target);
|
|
309
1038
|
if (!emittedMutation) {
|
|
310
1039
|
emittedMutation = {
|
|
@@ -318,209 +1047,919 @@ function processAttributesMutations(mutations, configuration, nodePrivacyLevelCa
|
|
|
318
1047
|
}
|
|
319
1048
|
return attributeMutations;
|
|
320
1049
|
}
|
|
321
|
-
function
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
1050
|
+
function reserveCurrentMutationSource(value, currentSourceState) {
|
|
1051
|
+
if (typeof value !== 'string') {
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|
|
1054
|
+
currentSourceState.characters += value.length;
|
|
1055
|
+
return currentSourceState.characters <= MAX_MUTATION_CURRENT_SOURCE_CHARACTERS;
|
|
1056
|
+
}
|
|
1057
|
+
function sortAddedAndMovedNodes(nodes, normalizationState) {
|
|
1058
|
+
try {
|
|
1059
|
+
nodes.sort(function (a, b) {
|
|
1060
|
+
if (normalizationState && consumeMutationNormalizationBudget(normalizationState, normalizationState.mutationTasksController)) {
|
|
1061
|
+
throw MUTATION_NORMALIZATION_ABORT;
|
|
1062
|
+
}
|
|
1063
|
+
var position = a.compareDocumentPosition(b);
|
|
1064
|
+
/* eslint-disable no-bitwise */
|
|
1065
|
+
if (position & Node.DOCUMENT_POSITION_CONTAINED_BY) {
|
|
1066
|
+
return -1;
|
|
1067
|
+
} else if (position & Node.DOCUMENT_POSITION_CONTAINS) {
|
|
1068
|
+
return 1;
|
|
1069
|
+
} else if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
1070
|
+
return 1;
|
|
1071
|
+
} else if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
1072
|
+
return -1;
|
|
1073
|
+
}
|
|
1074
|
+
/* eslint-enable no-bitwise */
|
|
1075
|
+
return 0;
|
|
1076
|
+
});
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
if (error === MUTATION_NORMALIZATION_ABORT) {
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
throw error;
|
|
1082
|
+
}
|
|
1083
|
+
return !(normalizationState && consumeMutationNormalizationBudget(normalizationState, normalizationState.mutationTasksController, true));
|
|
1084
|
+
}
|
|
1085
|
+
function consumeMutationNormalizationBudget(normalizationState, mutationTasksController, forceTimeCheck) {
|
|
1086
|
+
if (normalizationState.exhausted) {
|
|
1087
|
+
return true;
|
|
1088
|
+
}
|
|
1089
|
+
normalizationState.timeCheckCount += 1;
|
|
1090
|
+
if (!forceTimeCheck && normalizationState.timeCheckCount % MUTATION_NORMALIZATION_TIME_CHECK_INTERVAL !== 0) {
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
if (normalizationState.mutationRecordCount <= MUTATION_NORMALIZATION_SMALL_BATCH_MAX_RECORDS && normalizationState.timeCheckCount < MUTATION_NORMALIZATION_MIN_OPERATIONS_BEFORE_TIMEOUT) {
|
|
1094
|
+
return false;
|
|
1095
|
+
}
|
|
1096
|
+
if (getCurrentTime() < normalizationState.deadline) {
|
|
1097
|
+
return false;
|
|
1098
|
+
}
|
|
1099
|
+
abortMutationNormalization(normalizationState, mutationTasksController);
|
|
1100
|
+
return true;
|
|
1101
|
+
}
|
|
1102
|
+
function abortMutationNormalization(normalizationState, mutationTasksController) {
|
|
1103
|
+
if (normalizationState.exhausted) {
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
normalizationState.exhausted = true;
|
|
1107
|
+
mutationTasksController.handleOverflow({
|
|
1108
|
+
reason: 'mutation_normalization_budget',
|
|
1109
|
+
mutationRecordCount: normalizationState.mutationRecordCount
|
|
336
1110
|
});
|
|
337
1111
|
}
|
|
338
|
-
function createMutationTasksController(mutationCallback, configuration, shadowRootsController) {
|
|
1112
|
+
function createMutationTasksController(mutationCallback, configuration, shadowRootsController, mutationPerfCb, mutationOverflowCb, mutationNodeSerializationCb, isNodeIgnored, mutationResourceBudget) {
|
|
1113
|
+
isNodeIgnored = isNodeIgnored || function () {
|
|
1114
|
+
return false;
|
|
1115
|
+
};
|
|
339
1116
|
var generation = 0;
|
|
340
1117
|
var nextTaskSequence = 0;
|
|
341
1118
|
var nextEmitSequence = 0;
|
|
1119
|
+
var pendingMutationGroups = [];
|
|
1120
|
+
var pendingMutationGroupHead = 0;
|
|
342
1121
|
var pendingRootTasks = [];
|
|
1122
|
+
var pendingRootTaskHead = 0;
|
|
1123
|
+
var pendingRootTaskContinuation;
|
|
1124
|
+
var pendingRootTaskCount = 0;
|
|
1125
|
+
var activeRootTaskCount = 0;
|
|
1126
|
+
var deferredRootTaskCount = 0;
|
|
1127
|
+
var deferredRootTaskOutstandingCount = 0;
|
|
343
1128
|
var pendingRootTaskByRootNode = new WeakMap();
|
|
344
1129
|
var pendingRootTaskBySequence = new Map();
|
|
345
1130
|
var scheduledFlush = undefined;
|
|
346
|
-
var scheduledEmit = undefined;
|
|
347
1131
|
var stopped = false;
|
|
348
|
-
var
|
|
1132
|
+
var overflowed = false;
|
|
1133
|
+
var overflowCount = 0;
|
|
1134
|
+
var retainedRootTaskApproxBytes = 0;
|
|
1135
|
+
var retainedMutationGroupApproxBytes = 0;
|
|
1136
|
+
var retainedMutationBudgetReservation;
|
|
1137
|
+
var completedRootTasksBySequence = new Map();
|
|
1138
|
+
var locallyDroppedRootNodes = new WeakSet();
|
|
349
1139
|
return {
|
|
1140
|
+
createMutationGroup: createMutationGroup,
|
|
1141
|
+
completeMutationGroup: completeMutationGroup,
|
|
1142
|
+
cancelMutationGroup: cancelMutationGroup,
|
|
350
1143
|
addPendingRootTask: addPendingRootTask,
|
|
351
1144
|
findPendingRootTask: findPendingRootTask,
|
|
1145
|
+
markPendingRootTaskPublishedDependency: markPendingRootTaskPublishedDependency,
|
|
1146
|
+
refreshAndFlushPendingRootForNode: refreshAndFlushPendingRootForNode,
|
|
352
1147
|
refreshPendingRootTask: refreshPendingRootTask,
|
|
1148
|
+
$rRetargetPendingRootTask: retargetPendingRootTask,
|
|
353
1149
|
handlePendingRootRemoval: handlePendingRootRemoval,
|
|
354
|
-
|
|
355
|
-
|
|
1150
|
+
dropMutationGroupTasks: dropMutationGroupTasks,
|
|
1151
|
+
handleOverflow: handleOverflow,
|
|
1152
|
+
getOverflowCount: function getOverflowCount() {
|
|
1153
|
+
return overflowCount;
|
|
356
1154
|
},
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
1155
|
+
isOverflowed: function isOverflowed() {
|
|
1156
|
+
return overflowed;
|
|
1157
|
+
},
|
|
1158
|
+
flush: function flush() {
|
|
1159
|
+
if (overflowed) {
|
|
1160
|
+
return false;
|
|
1161
|
+
}
|
|
1162
|
+
var flushResult = processPendingRootTasks(getCurrentTime() + MUTATION_SERIALIZATION_FLUSH_BUDGET_MS, true);
|
|
1163
|
+
if (flushResult === false && deferredRootTaskOutstandingCount) {
|
|
1164
|
+
return 'pending';
|
|
1165
|
+
}
|
|
1166
|
+
return flushResult;
|
|
367
1167
|
},
|
|
1168
|
+
reset: reset,
|
|
368
1169
|
stop: function stop() {
|
|
369
1170
|
stopped = true;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
pendingRootTasks = [];
|
|
373
|
-
completedRootTasks = [];
|
|
374
|
-
pendingRootTaskByRootNode = new WeakMap();
|
|
375
|
-
pendingRootTaskBySequence = new Map();
|
|
1171
|
+
overflowed = false;
|
|
1172
|
+
clearMutationTaskState();
|
|
376
1173
|
}
|
|
377
1174
|
};
|
|
378
|
-
function
|
|
379
|
-
|
|
1175
|
+
function clearMutationTaskState() {
|
|
1176
|
+
pendingRootTaskBySequence.forEach(function (task) {
|
|
1177
|
+
cancelPublicationToken(task.publicationToken);
|
|
1178
|
+
});
|
|
1179
|
+
for (var groupIndex = pendingMutationGroupHead; groupIndex < pendingMutationGroups.length; groupIndex += 1) {
|
|
1180
|
+
cancelMutationGroupPublicationTokens(pendingMutationGroups[groupIndex]);
|
|
1181
|
+
}
|
|
1182
|
+
generation += 1;
|
|
1183
|
+
nextTaskSequence = 0;
|
|
1184
|
+
nextEmitSequence = 0;
|
|
1185
|
+
pendingMutationGroups = [];
|
|
1186
|
+
pendingMutationGroupHead = 0;
|
|
1187
|
+
clearScheduledFlush();
|
|
1188
|
+
pendingRootTasks = [];
|
|
1189
|
+
pendingRootTaskHead = 0;
|
|
1190
|
+
pendingRootTaskContinuation = undefined;
|
|
1191
|
+
pendingRootTaskCount = 0;
|
|
1192
|
+
activeRootTaskCount = 0;
|
|
1193
|
+
deferredRootTaskCount = 0;
|
|
1194
|
+
deferredRootTaskOutstandingCount = 0;
|
|
1195
|
+
retainedRootTaskApproxBytes = 0;
|
|
1196
|
+
retainedMutationGroupApproxBytes = 0;
|
|
1197
|
+
updateRetainedMutationResourceBudget();
|
|
1198
|
+
completedRootTasksBySequence = new Map();
|
|
1199
|
+
locallyDroppedRootNodes = new WeakSet();
|
|
1200
|
+
pendingRootTaskByRootNode = new WeakMap();
|
|
1201
|
+
pendingRootTaskBySequence = new Map();
|
|
1202
|
+
}
|
|
1203
|
+
function reset() {
|
|
1204
|
+
overflowed = false;
|
|
1205
|
+
clearMutationTaskState();
|
|
1206
|
+
}
|
|
1207
|
+
function createMutationGroup(callback) {
|
|
1208
|
+
if (stopped || overflowed) {
|
|
380
1209
|
return;
|
|
381
1210
|
}
|
|
382
|
-
|
|
383
|
-
|
|
1211
|
+
if (pendingMutationGroups.length - pendingMutationGroupHead >= MAX_PENDING_MUTATION_GROUPS || getRetainedMutationApproxBytes() + 64 > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1212
|
+
handleOverflow({
|
|
1213
|
+
reason: 'mutation_group_watermark',
|
|
1214
|
+
mutationRecordCount: pendingMutationGroups.length - pendingMutationGroupHead + 1,
|
|
1215
|
+
mutationApproxBytes: getRetainedMutationApproxBytes() + 64
|
|
1216
|
+
});
|
|
384
1217
|
return;
|
|
385
1218
|
}
|
|
386
|
-
var
|
|
1219
|
+
var mutationGroup = {
|
|
1220
|
+
active: true,
|
|
387
1221
|
generation: generation,
|
|
388
|
-
sequence: nextTaskSequence
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
1222
|
+
sequence: nextTaskSequence,
|
|
1223
|
+
callback: callback || mutationCallback,
|
|
1224
|
+
payload: {
|
|
1225
|
+
adds: [],
|
|
1226
|
+
removes: [],
|
|
1227
|
+
texts: [],
|
|
1228
|
+
attributes: []
|
|
1229
|
+
},
|
|
1230
|
+
approxBytes: 64,
|
|
1231
|
+
approxBytesReleased: false,
|
|
1232
|
+
pendingTaskCount: 0,
|
|
1233
|
+
closed: false,
|
|
1234
|
+
canceled: false
|
|
393
1235
|
};
|
|
394
|
-
|
|
1236
|
+
pendingMutationGroups.push(mutationGroup);
|
|
1237
|
+
retainedMutationGroupApproxBytes += mutationGroup.approxBytes;
|
|
1238
|
+
if (!updateRetainedMutationResourceBudget()) {
|
|
1239
|
+
handleOverflow({
|
|
1240
|
+
reason: AGGREGATE_RETAINED_MUTATION_WATERMARK,
|
|
1241
|
+
mutationApproxBytes: getRetainedMutationApproxBytes()
|
|
1242
|
+
});
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
return mutationGroup;
|
|
1246
|
+
}
|
|
1247
|
+
function completeMutationGroup(mutationGroup, payload) {
|
|
1248
|
+
if (!isActiveMutationGroup(mutationGroup) || mutationGroup.canceled || mutationGroup.closed) {
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
var payloadApproxBytes = estimateMutationGroupPayloadApproxBytes(payload);
|
|
1252
|
+
if (getRetainedMutationApproxBytes() + payloadApproxBytes > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1253
|
+
handleOverflow({
|
|
1254
|
+
reason: 'mutation_group_byte_watermark',
|
|
1255
|
+
mutationApproxBytes: getRetainedMutationApproxBytes() + payloadApproxBytes
|
|
1256
|
+
});
|
|
1257
|
+
return false;
|
|
1258
|
+
}
|
|
1259
|
+
mutationGroup.approxBytes += payloadApproxBytes;
|
|
1260
|
+
retainedMutationGroupApproxBytes += payloadApproxBytes;
|
|
1261
|
+
if (!updateRetainedMutationResourceBudget()) {
|
|
1262
|
+
return handleOverflow({
|
|
1263
|
+
reason: AGGREGATE_RETAINED_MUTATION_WATERMARK,
|
|
1264
|
+
mutationApproxBytes: getRetainedMutationApproxBytes()
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
Array.prototype.push.apply(mutationGroup.payload.removes, payload.removes);
|
|
1268
|
+
Array.prototype.push.apply(mutationGroup.payload.texts, payload.texts);
|
|
1269
|
+
Array.prototype.push.apply(mutationGroup.payload.attributes, payload.attributes);
|
|
1270
|
+
mutationGroup.closed = true;
|
|
1271
|
+
emitReadyMutationGroups();
|
|
1272
|
+
}
|
|
1273
|
+
function cancelMutationGroup(mutationGroup) {
|
|
1274
|
+
if (!isActiveMutationGroup(mutationGroup)) {
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
mutationGroup.canceled = true;
|
|
1278
|
+
mutationGroup.closed = true;
|
|
1279
|
+
cancelMutationGroupPublicationTokens(mutationGroup);
|
|
1280
|
+
releaseMutationGroupApproxBytes(mutationGroup);
|
|
1281
|
+
Array.from(pendingRootTaskBySequence.values()).forEach(function (task) {
|
|
1282
|
+
if (task.mutationGroup === mutationGroup) {
|
|
1283
|
+
cancelPendingRootTask(task);
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
emitReadyMutationGroups();
|
|
1287
|
+
}
|
|
1288
|
+
function cancelMutationGroupPublicationTokens(mutationGroup) {
|
|
1289
|
+
mutationGroup.payload.adds.forEach(function (add) {
|
|
1290
|
+
cancelPublicationToken(consumeMutationAddPublicationToken(add));
|
|
1291
|
+
});
|
|
1292
|
+
mutationGroup.payload.adds = [];
|
|
1293
|
+
}
|
|
1294
|
+
function isActiveMutationGroup(mutationGroup) {
|
|
1295
|
+
return Boolean(mutationGroup && mutationGroup.active && mutationGroup.generation === generation && !stopped);
|
|
1296
|
+
}
|
|
1297
|
+
function emitReadyMutationGroups() {
|
|
1298
|
+
while (pendingMutationGroupHead < pendingMutationGroups.length) {
|
|
1299
|
+
var mutationGroup = pendingMutationGroups[pendingMutationGroupHead];
|
|
1300
|
+
if (!mutationGroup || !mutationGroup.closed || mutationGroup.pendingTaskCount || nextEmitSequence < mutationGroup.sequence) {
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
mutationGroup.active = false;
|
|
1304
|
+
pendingMutationGroups[pendingMutationGroupHead] = undefined;
|
|
1305
|
+
pendingMutationGroupHead += 1;
|
|
1306
|
+
var mutationGroupApproxBytes = mutationGroup.approxBytes;
|
|
1307
|
+
releaseMutationGroupApproxBytes(mutationGroup);
|
|
1308
|
+
if (!mutationGroup.canceled && hasMutationGroupEntries(mutationGroup.payload)) {
|
|
1309
|
+
approxBytesByMutationPayload.set(mutationGroup.payload, mutationGroupApproxBytes);
|
|
1310
|
+
mutationGroup.callback(mutationGroup.payload);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
pendingMutationGroups = [];
|
|
1314
|
+
pendingMutationGroupHead = 0;
|
|
1315
|
+
}
|
|
1316
|
+
function hasMutationGroupEntries(payload) {
|
|
1317
|
+
return Boolean(payload.adds.length || payload.removes.length || payload.texts.length || payload.attributes.length);
|
|
1318
|
+
}
|
|
1319
|
+
function estimateMutationGroupPayloadApproxBytes(payload) {
|
|
1320
|
+
return estimateMutationPayloadEntriesApproxBytes(payload);
|
|
1321
|
+
}
|
|
1322
|
+
function getRetainedMutationApproxBytes() {
|
|
1323
|
+
return retainedRootTaskApproxBytes + retainedMutationGroupApproxBytes;
|
|
1324
|
+
}
|
|
1325
|
+
function releaseMutationGroupApproxBytes(mutationGroup) {
|
|
1326
|
+
if (mutationGroup.approxBytesReleased) {
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
mutationGroup.approxBytesReleased = true;
|
|
1330
|
+
retainedMutationGroupApproxBytes = Math.max(retainedMutationGroupApproxBytes - mutationGroup.approxBytes, 0);
|
|
1331
|
+
updateRetainedMutationResourceBudget();
|
|
1332
|
+
}
|
|
1333
|
+
function transferRetainedRootTaskToMutationGroup(task, mutationGroup) {
|
|
1334
|
+
var taskApproxBytes = task.accountedApproxBytes;
|
|
1335
|
+
task.isRetained = false;
|
|
1336
|
+
retainedRootTaskApproxBytes = Math.max(retainedRootTaskApproxBytes - taskApproxBytes, 0);
|
|
1337
|
+
task.accountedApproxBytes = 0;
|
|
1338
|
+
mutationGroup.approxBytes += taskApproxBytes;
|
|
1339
|
+
retainedMutationGroupApproxBytes += taskApproxBytes;
|
|
1340
|
+
releaseActiveRootTask(task);
|
|
1341
|
+
releaseDeferredRootTaskOutstanding(task);
|
|
1342
|
+
}
|
|
1343
|
+
function releaseMutationGroupDependency(task) {
|
|
1344
|
+
if (task.mutationGroupDependencyReleased || !task.mutationGroup) {
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
task.mutationGroupDependencyReleased = true;
|
|
1348
|
+
if (isActiveMutationGroup(task.mutationGroup)) {
|
|
1349
|
+
task.mutationGroup.pendingTaskCount = Math.max(task.mutationGroup.pendingTaskCount - 1, 0);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
function handleOverflow(overflow) {
|
|
1353
|
+
if (stopped || overflowed) {
|
|
1354
|
+
return false;
|
|
1355
|
+
}
|
|
1356
|
+
overflowed = true;
|
|
1357
|
+
overflowCount += 1;
|
|
1358
|
+
var shouldReportOverflow = !mutationResourceBudget || mutationResourceBudget.failOnce();
|
|
1359
|
+
clearMutationTaskState();
|
|
1360
|
+
if (shouldReportOverflow && mutationOverflowCb) {
|
|
1361
|
+
mutationOverflowCb(overflow);
|
|
1362
|
+
}
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1365
|
+
function addPendingRootTask(node, serializationOptions) {
|
|
1366
|
+
if (stopped || overflowed) {
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
var isNormalizationTransaction = Boolean(serializationOptions.normalizationState && !serializationOptions.normalizationState.exhausted);
|
|
1370
|
+
var mustDeferNormalizationEmission = Boolean(isNormalizationTransaction && !serializationOptions.mutationGroup);
|
|
1371
|
+
var parentPendingRootTask = findPendingRootTask((0, _browserCore.getParentNode)(node));
|
|
1372
|
+
if (parentPendingRootTask) {
|
|
1373
|
+
if (serializationOptions.requiresBaselineOnDrop) {
|
|
1374
|
+
markPendingRootTaskPublishedDependency(parentPendingRootTask);
|
|
1375
|
+
}
|
|
1376
|
+
return true;
|
|
1377
|
+
}
|
|
1378
|
+
var canDefer = canDeferPendingRootTask(serializationOptions);
|
|
1379
|
+
if (deferredRootTaskCount && canDefer) {
|
|
1380
|
+
return deferPendingRootTask(node, serializationOptions);
|
|
1381
|
+
}
|
|
1382
|
+
if (deferredRootTaskCount) {
|
|
1383
|
+
// A non-deferred task cannot overtake an older deferred sequence: once
|
|
1384
|
+
// later active tasks fill the cap, neither side can publish. Drain the
|
|
1385
|
+
// older work within the normal slice before admitting the dependency.
|
|
1386
|
+
if (!drainPendingRootTasksForAdmission()) {
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1389
|
+
if (deferredRootTaskCount) {
|
|
1390
|
+
return handleOverflow({
|
|
1391
|
+
reason: MUTATION_ROOT_ADMISSION_WATERMARK
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
if (activeRootTaskCount >= MAX_PENDING_MUTATION_ROOT_TASKS) {
|
|
1396
|
+
if (!mustDeferNormalizationEmission && !drainPendingRootTasksForAdmission()) {
|
|
1397
|
+
return false;
|
|
1398
|
+
}
|
|
1399
|
+
if (activeRootTaskCount >= MAX_PENDING_MUTATION_ROOT_TASKS) {
|
|
1400
|
+
if (canDefer) {
|
|
1401
|
+
return deferPendingRootTask(node, serializationOptions);
|
|
1402
|
+
}
|
|
1403
|
+
return handleOverflow({
|
|
1404
|
+
reason: MUTATION_ROOT_ADMISSION_WATERMARK
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
var trackedSerializerTask = createTrackedMutationSerializerTask(node, serializationOptions);
|
|
1409
|
+
var serializerTask = trackedSerializerTask.serializerTask;
|
|
1410
|
+
if (!serializerTask) {
|
|
1411
|
+
return dropUnadmittedRootNode(node, trackedSerializerTask.publicationToken, serializationOptions.requiresBaselineOnDrop, 'published_move_serialization_failed');
|
|
1412
|
+
}
|
|
1413
|
+
if (serializerTask.isMaxNodeComplexityReached) {
|
|
1414
|
+
return dropUnadmittedRootNode(node, trackedSerializerTask.publicationToken, serializationOptions.requiresBaselineOnDrop, 'published_move_serialization_watermark');
|
|
1415
|
+
}
|
|
1416
|
+
if (serializerTask.approxBytes > MUTATION_SERIALIZATION_MAX_APPROX_BYTES) {
|
|
1417
|
+
return dropUnadmittedRootNode(node, trackedSerializerTask.publicationToken, serializationOptions.requiresBaselineOnDrop, serializationOptions.requiresBaselineOnDrop ? 'published_move_serialization_watermark' : 'unpublished_add_serialization_watermark', true);
|
|
1418
|
+
}
|
|
1419
|
+
if (getRetainedMutationApproxBytes() + serializerTask.approxBytes > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1420
|
+
if (mustDeferNormalizationEmission) {
|
|
1421
|
+
cancelPublicationToken(trackedSerializerTask.publicationToken);
|
|
1422
|
+
if (canDeferPendingRootTask(serializationOptions)) {
|
|
1423
|
+
return deferPendingRootTask(node, serializationOptions);
|
|
1424
|
+
}
|
|
1425
|
+
return handleOverflow({
|
|
1426
|
+
reason: MUTATION_ROOT_RETAINED_BYTES_WATERMARK
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
if (!drainPendingRootTasksForAdmission()) {
|
|
1430
|
+
cancelPublicationToken(trackedSerializerTask.publicationToken);
|
|
1431
|
+
return false;
|
|
1432
|
+
}
|
|
1433
|
+
if (getRetainedMutationApproxBytes() + serializerTask.approxBytes > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1434
|
+
cancelPublicationToken(trackedSerializerTask.publicationToken);
|
|
1435
|
+
if (canDeferPendingRootTask(serializationOptions)) {
|
|
1436
|
+
return deferPendingRootTask(node, serializationOptions);
|
|
1437
|
+
}
|
|
1438
|
+
return handleOverflow({
|
|
1439
|
+
reason: MUTATION_ROOT_RETAINED_BYTES_WATERMARK
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
var task = {
|
|
1444
|
+
generation: generation,
|
|
1445
|
+
sequence: nextTaskSequence++,
|
|
1446
|
+
rootNode: node,
|
|
1447
|
+
parentId: (0, _serializationUtils.getSerializedNodeId)((0, _browserCore.getParentNode)(node)),
|
|
1448
|
+
nextId: null,
|
|
1449
|
+
serializerTask: serializerTask,
|
|
1450
|
+
publicationToken: trackedSerializerTask.publicationToken,
|
|
1451
|
+
serializedNodeIds: serializationOptions.serializedNodeIds,
|
|
1452
|
+
refreshCount: 0,
|
|
1453
|
+
accountedApproxBytes: serializerTask.approxBytes,
|
|
1454
|
+
isRetained: true,
|
|
1455
|
+
mutationGroup: isActiveMutationGroup(serializationOptions.mutationGroup) ? serializationOptions.mutationGroup : undefined,
|
|
1456
|
+
requiresBaselineOnDrop: Boolean(serializationOptions.requiresBaselineOnDrop),
|
|
1457
|
+
isActiveSerializerTask: true
|
|
1458
|
+
};
|
|
1459
|
+
if (task.mutationGroup) {
|
|
1460
|
+
task.mutationGroup.pendingTaskCount += 1;
|
|
1461
|
+
}
|
|
1462
|
+
retainedRootTaskApproxBytes += task.accountedApproxBytes;
|
|
1463
|
+
activeRootTaskCount += 1;
|
|
1464
|
+
if (!updateRetainedMutationResourceBudget()) {
|
|
1465
|
+
cancelPublicationToken(task.publicationToken);
|
|
1466
|
+
return handleOverflow({
|
|
1467
|
+
reason: AGGREGATE_RETAINED_MUTATION_WATERMARK,
|
|
1468
|
+
mutationApproxBytes: getRetainedMutationApproxBytes()
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
clearLocallyDroppedRootNode(node);
|
|
1472
|
+
enqueuePendingRootTask(task);
|
|
1473
|
+
pendingRootTaskByRootNode.set(node, task);
|
|
1474
|
+
pendingRootTaskBySequence.set(task.sequence, task);
|
|
1475
|
+
schedulePendingRootTasks();
|
|
1476
|
+
return true;
|
|
1477
|
+
}
|
|
1478
|
+
function drainPendingRootTasksForAdmission() {
|
|
1479
|
+
var drainGeneration = generation;
|
|
1480
|
+
var overflowCountBeforeDrain = overflowCount;
|
|
1481
|
+
processPendingRootTasks(getCurrentTime() + MUTATION_SERIALIZATION_FLUSH_BUDGET_MS, true);
|
|
1482
|
+
return !stopped && generation === drainGeneration && overflowCount === overflowCountBeforeDrain;
|
|
1483
|
+
}
|
|
1484
|
+
function canDeferPendingRootTask(serializationOptions) {
|
|
1485
|
+
return Boolean(!serializationOptions.requiresBaselineOnDrop && !isActiveMutationGroup(serializationOptions.mutationGroup));
|
|
1486
|
+
}
|
|
1487
|
+
function deferPendingRootTask(node, serializationOptions) {
|
|
1488
|
+
// A dropped unpublished add has no replay-tree dependency yet. If the
|
|
1489
|
+
// lightweight queue itself reaches its hard bound, degrading only that
|
|
1490
|
+
// root is safer than replacing (and synchronously serializing) the whole
|
|
1491
|
+
// document under the same load spike.
|
|
1492
|
+
if (deferredRootTaskCount >= MAX_DEFERRED_MUTATION_ROOT_TASKS || getRetainedMutationApproxBytes() + DEFERRED_MUTATION_ROOT_TASK_APPROX_BYTES > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1493
|
+
reportLocalRootDrop(deferredRootTaskCount >= MAX_DEFERRED_MUTATION_ROOT_TASKS ? MUTATION_ROOT_ADMISSION_WATERMARK : MUTATION_ROOT_RETAINED_BYTES_WATERMARK);
|
|
1494
|
+
markLocallyDroppedRootNode(node);
|
|
1495
|
+
return true;
|
|
1496
|
+
}
|
|
1497
|
+
var task = {
|
|
1498
|
+
generation: generation,
|
|
1499
|
+
sequence: nextTaskSequence++,
|
|
1500
|
+
rootNode: node,
|
|
1501
|
+
serializedNodeIds: serializationOptions.serializedNodeIds,
|
|
1502
|
+
refreshCount: 0,
|
|
1503
|
+
accountedApproxBytes: DEFERRED_MUTATION_ROOT_TASK_APPROX_BYTES,
|
|
1504
|
+
isRetained: true,
|
|
1505
|
+
isDeferred: true,
|
|
1506
|
+
wasDeferred: true,
|
|
1507
|
+
requiresBaselineOnDrop: false
|
|
1508
|
+
};
|
|
1509
|
+
retainedRootTaskApproxBytes += task.accountedApproxBytes;
|
|
1510
|
+
if (!updateRetainedMutationResourceBudget()) {
|
|
1511
|
+
retainedRootTaskApproxBytes = Math.max(retainedRootTaskApproxBytes - task.accountedApproxBytes, 0);
|
|
1512
|
+
task.isRetained = false;
|
|
1513
|
+
task.accountedApproxBytes = 0;
|
|
1514
|
+
reportLocalRootDrop(AGGREGATE_RETAINED_MUTATION_WATERMARK);
|
|
1515
|
+
markLocallyDroppedRootNode(node);
|
|
1516
|
+
return true;
|
|
1517
|
+
}
|
|
1518
|
+
clearLocallyDroppedRootNode(node);
|
|
1519
|
+
deferredRootTaskCount += 1;
|
|
1520
|
+
deferredRootTaskOutstandingCount += 1;
|
|
395
1521
|
pendingRootTaskByRootNode.set(node, task);
|
|
396
1522
|
pendingRootTaskBySequence.set(task.sequence, task);
|
|
1523
|
+
enqueuePendingRootTask(task);
|
|
397
1524
|
schedulePendingRootTasks();
|
|
1525
|
+
return true;
|
|
398
1526
|
}
|
|
399
|
-
function
|
|
1527
|
+
function reportLocalRootDrop(reason) {
|
|
1528
|
+
if (mutationPerfCb) {
|
|
1529
|
+
mutationPerfCb(false ? {
|
|
1530
|
+
mutationLocalDropCount: 1,
|
|
1531
|
+
mutationLocalDropReason: reason
|
|
1532
|
+
} : reason);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function findPendingRootTask(node, fallbackAncestor) {
|
|
1536
|
+
if (overflowed) {
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
400
1539
|
var current = node;
|
|
1540
|
+
var depth = 0;
|
|
401
1541
|
while (current) {
|
|
1542
|
+
if (depth >= _serializationUtils.MAX_SERIALIZED_NODE_ANCESTOR_DEPTH) {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
402
1545
|
var task = pendingRootTaskByRootNode.get(current);
|
|
403
1546
|
if (task && task.generation === generation) {
|
|
404
1547
|
return task;
|
|
405
1548
|
}
|
|
1549
|
+
depth += 1;
|
|
406
1550
|
current = (0, _browserCore.getParentNode)(current);
|
|
407
1551
|
}
|
|
1552
|
+
if (fallbackAncestor && fallbackAncestor !== node) {
|
|
1553
|
+
return findPendingRootTask(fallbackAncestor);
|
|
1554
|
+
}
|
|
408
1555
|
}
|
|
409
|
-
function
|
|
410
|
-
if (
|
|
1556
|
+
function refreshAndFlushPendingRootForNode(node) {
|
|
1557
|
+
if (stopped || overflowed) {
|
|
1558
|
+
return false;
|
|
1559
|
+
}
|
|
1560
|
+
var task = findPendingRootTask(node);
|
|
1561
|
+
if (!task) {
|
|
411
1562
|
return;
|
|
412
1563
|
}
|
|
1564
|
+
if (!refreshPendingRootTask(task)) {
|
|
1565
|
+
return false;
|
|
1566
|
+
}
|
|
1567
|
+
var overflowCountBeforeFlush = overflowCount;
|
|
1568
|
+
if (processPendingRootTasks(getCurrentTime() + MUTATION_SERIALIZATION_FLUSH_BUDGET_MS, true)) {
|
|
1569
|
+
return true;
|
|
1570
|
+
}
|
|
1571
|
+
if (overflowed || overflowCount > overflowCountBeforeFlush) {
|
|
1572
|
+
return false;
|
|
1573
|
+
}
|
|
1574
|
+
// attachShadow() returns to application code synchronously. If the
|
|
1575
|
+
// rebuilt host cannot be published in this bounded drain, later shadow
|
|
1576
|
+
// mutations could overtake or be filtered behind the unpublished host.
|
|
1577
|
+
// Replace the baseline instead of leaving that dependency pending.
|
|
1578
|
+
return handleOverflow({
|
|
1579
|
+
reason: 'dynamic_shadow_pending_host_serialization_budget'
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
function refreshPendingRootTask(task, activateDeferredTask) {
|
|
1583
|
+
if (!task || task.generation !== generation || task.isCancelled) {
|
|
1584
|
+
return true;
|
|
1585
|
+
}
|
|
1586
|
+
if (overflowed) {
|
|
1587
|
+
return false;
|
|
1588
|
+
}
|
|
413
1589
|
if (!task.rootNode.isConnected) {
|
|
1590
|
+
if (taskRequiresBaselineOnDrop(task)) {
|
|
1591
|
+
return handleOverflow({
|
|
1592
|
+
reason: 'published_move_cancelled'
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
414
1595
|
cancelPendingRootTask(task);
|
|
415
|
-
return;
|
|
1596
|
+
return true;
|
|
416
1597
|
}
|
|
417
1598
|
var parentNode = (0, _browserCore.getParentNode)(task.rootNode);
|
|
418
1599
|
var parentPendingRootTask = findPendingRootTask(parentNode);
|
|
419
1600
|
if (parentPendingRootTask && parentPendingRootTask !== task) {
|
|
1601
|
+
if (taskRequiresBaselineOnDrop(task)) {
|
|
1602
|
+
markPendingRootTaskPublishedDependency(parentPendingRootTask);
|
|
1603
|
+
}
|
|
420
1604
|
cancelPendingRootTask(task);
|
|
421
|
-
|
|
1605
|
+
// The parent serializer may have already walked this branch before the
|
|
1606
|
+
// child moved under it. Rebuild the surviving task so it cannot publish
|
|
1607
|
+
// a stale subtree after absorbing the child's publication dependency.
|
|
1608
|
+
return refreshPendingRootTask(parentPendingRootTask);
|
|
422
1609
|
}
|
|
423
1610
|
var parentNodePrivacyLevel = (0, _privacy.getNodePrivacyLevel)(parentNode, configuration.defaultPrivacyLevel);
|
|
424
1611
|
if (parentNodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === _constants.NodePrivacyLevel.IGNORE) {
|
|
1612
|
+
if (taskRequiresBaselineOnDrop(task)) {
|
|
1613
|
+
return handleOverflow({
|
|
1614
|
+
reason: 'published_move_cancelled'
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
425
1617
|
cancelPendingRootTask(task);
|
|
426
|
-
return;
|
|
1618
|
+
return true;
|
|
427
1619
|
}
|
|
428
|
-
var
|
|
1620
|
+
var wasDeferred = task.isDeferred;
|
|
1621
|
+
if (wasDeferred && !activateDeferredTask) {
|
|
1622
|
+
schedulePendingRootTasks();
|
|
1623
|
+
return true;
|
|
1624
|
+
}
|
|
1625
|
+
if (!wasDeferred && task.refreshCount >= MAX_MUTATION_ROOT_TASK_REFRESH_COUNT) {
|
|
1626
|
+
return dropUnpublishedRootTask(task, taskRequiresBaselineOnDrop(task) ? 'published_move_refresh_watermark' : 'unpublished_add_serialization_watermark', true);
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
// A refresh supersedes the previous serialization generation. Nodes that
|
|
1630
|
+
// are not present in the rebuilt subtree must immediately fall back to
|
|
1631
|
+
// their last published parent instead of remaining blocked by a token that
|
|
1632
|
+
// can no longer be emitted.
|
|
1633
|
+
if (!wasDeferred) {
|
|
1634
|
+
task.requiresBaselineOnDrop = taskRequiresBaselineOnDrop(task);
|
|
1635
|
+
cancelPublicationToken(task.publicationToken);
|
|
1636
|
+
}
|
|
1637
|
+
var trackedSerializerTask = createTrackedMutationSerializerTask(task.rootNode, {
|
|
1638
|
+
serializedNodeIds: task.serializedNodeIds,
|
|
429
1639
|
parentNodePrivacyLevel: parentNodePrivacyLevel,
|
|
430
1640
|
serializationContext: {
|
|
431
1641
|
status: _serialize.SerializationContextStatus.MUTATION,
|
|
432
1642
|
shadowRootsController: shadowRootsController
|
|
433
1643
|
},
|
|
434
|
-
configuration: configuration
|
|
1644
|
+
configuration: configuration,
|
|
1645
|
+
requiresBaselineOnDrop: taskRequiresBaselineOnDrop(task)
|
|
435
1646
|
});
|
|
1647
|
+
task.publicationToken = trackedSerializerTask.publicationToken;
|
|
1648
|
+
var serializerTask = trackedSerializerTask.serializerTask;
|
|
436
1649
|
if (!serializerTask) {
|
|
1650
|
+
if (taskRequiresBaselineOnDrop(task)) {
|
|
1651
|
+
return handleOverflow({
|
|
1652
|
+
reason: 'published_move_serialization_failed'
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
437
1655
|
cancelPendingRootTask(task);
|
|
438
|
-
return;
|
|
1656
|
+
return true;
|
|
1657
|
+
}
|
|
1658
|
+
if (!wasDeferred) {
|
|
1659
|
+
task.refreshCount += 1;
|
|
1660
|
+
}
|
|
1661
|
+
if (serializerTask.isMaxNodeComplexityReached) {
|
|
1662
|
+
return dropUnpublishedRootTask(task, 'published_move_serialization_watermark');
|
|
1663
|
+
}
|
|
1664
|
+
if (serializerTask.approxBytes > MUTATION_SERIALIZATION_MAX_APPROX_BYTES) {
|
|
1665
|
+
return dropUnpublishedRootTask(task, taskRequiresBaselineOnDrop(task) ? 'published_move_serialization_watermark' : 'unpublished_add_serialization_watermark', true);
|
|
1666
|
+
}
|
|
1667
|
+
if (wasDeferred && getRetainedMutationApproxBytes() - task.accountedApproxBytes + serializerTask.approxBytes > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1668
|
+
cancelPublicationToken(task.publicationToken);
|
|
1669
|
+
task.publicationToken = undefined;
|
|
1670
|
+
return 'blocked';
|
|
1671
|
+
}
|
|
1672
|
+
if (!updateRetainedRootTaskApproxBytes(task, serializerTask.approxBytes)) {
|
|
1673
|
+
return handleOverflow({
|
|
1674
|
+
reason: AGGREGATE_RETAINED_MUTATION_WATERMARK,
|
|
1675
|
+
mutationApproxBytes: getRetainedMutationApproxBytes()
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
if (getRetainedMutationApproxBytes() > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1679
|
+
return handleOverflow({
|
|
1680
|
+
reason: MUTATION_ROOT_RETAINED_BYTES_WATERMARK
|
|
1681
|
+
});
|
|
439
1682
|
}
|
|
440
1683
|
removeCompletedRootTask(task);
|
|
441
1684
|
task.parentId = (0, _serializationUtils.getSerializedNodeId)(parentNode);
|
|
442
|
-
task.nextId =
|
|
1685
|
+
task.nextId = null;
|
|
443
1686
|
task.serializerTask = serializerTask;
|
|
444
1687
|
task.isCompleted = false;
|
|
445
|
-
|
|
1688
|
+
task.isCancelled = false;
|
|
1689
|
+
if (wasDeferred) {
|
|
1690
|
+
removeDeferredRootTaskQueueMembership(task);
|
|
1691
|
+
task.isActiveSerializerTask = true;
|
|
1692
|
+
activeRootTaskCount += 1;
|
|
1693
|
+
} else {
|
|
1694
|
+
enqueuePendingRootTask(task);
|
|
1695
|
+
schedulePendingRootTasks();
|
|
1696
|
+
}
|
|
1697
|
+
return true;
|
|
1698
|
+
}
|
|
1699
|
+
function retargetPendingRootTask(task, replacementNode) {
|
|
1700
|
+
if (!task || task.generation !== generation || task.isCancelled || !replacementNode) {
|
|
1701
|
+
return true;
|
|
1702
|
+
}
|
|
1703
|
+
if (pendingRootTaskByRootNode.get(task.rootNode) !== task || pendingRootTaskByRootNode.get(replacementNode)) {
|
|
1704
|
+
return handleOverflow({
|
|
1705
|
+
reason: 'published_move_cancelled'
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
pendingRootTaskByRootNode["delete"](task.rootNode);
|
|
1709
|
+
task.rootNode = replacementNode;
|
|
1710
|
+
clearLocallyDroppedRootNode(replacementNode);
|
|
1711
|
+
pendingRootTaskByRootNode.set(replacementNode, task);
|
|
1712
|
+
return refreshPendingRootTask(task);
|
|
446
1713
|
}
|
|
447
1714
|
function handlePendingRootRemoval(task, node) {
|
|
448
1715
|
if (!task || task.generation !== generation) {
|
|
449
|
-
return;
|
|
1716
|
+
return true;
|
|
450
1717
|
}
|
|
451
1718
|
if (node === task.rootNode) {
|
|
452
1719
|
if (task.rootNode.isConnected) {
|
|
453
|
-
refreshPendingRootTask(task);
|
|
454
|
-
|
|
1720
|
+
return refreshPendingRootTask(task);
|
|
1721
|
+
}
|
|
1722
|
+
if (taskRequiresBaselineOnDrop(task)) {
|
|
1723
|
+
return handleOverflow({
|
|
1724
|
+
reason: 'published_move_cancelled'
|
|
1725
|
+
});
|
|
455
1726
|
}
|
|
456
1727
|
cancelPendingRootTask(task);
|
|
457
|
-
return;
|
|
1728
|
+
return true;
|
|
458
1729
|
}
|
|
459
1730
|
if (!task.rootNode.isConnected) {
|
|
1731
|
+
if (taskRequiresBaselineOnDrop(task)) {
|
|
1732
|
+
return handleOverflow({
|
|
1733
|
+
reason: 'published_move_cancelled'
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
460
1736
|
cancelPendingRootTask(task);
|
|
461
|
-
return;
|
|
1737
|
+
return true;
|
|
462
1738
|
}
|
|
463
|
-
refreshPendingRootTask(task);
|
|
1739
|
+
return refreshPendingRootTask(task);
|
|
464
1740
|
}
|
|
465
1741
|
function cancelPendingRootTask(task) {
|
|
1742
|
+
cancelPublicationToken(task.publicationToken);
|
|
1743
|
+
releaseMutationGroupDependency(task);
|
|
1744
|
+
task.isCancelled = true;
|
|
1745
|
+
removeDeferredRootTaskQueueMembership(task);
|
|
1746
|
+
if (task.isQueued) {
|
|
1747
|
+
task.isQueued = false;
|
|
1748
|
+
pendingRootTaskCount -= 1;
|
|
1749
|
+
if (pendingRootTaskContinuation === task) {
|
|
1750
|
+
pendingRootTaskContinuation = undefined;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
466
1753
|
pendingRootTaskByRootNode["delete"](task.rootNode);
|
|
467
1754
|
pendingRootTaskBySequence["delete"](task.sequence);
|
|
468
1755
|
removeCompletedRootTask(task);
|
|
469
|
-
|
|
470
|
-
return pendingRootTask !== task;
|
|
471
|
-
});
|
|
1756
|
+
releaseRetainedRootTask(task);
|
|
472
1757
|
advanceEmitSequencePastGaps();
|
|
1758
|
+
emitReadyMutationGroups();
|
|
1759
|
+
}
|
|
1760
|
+
function dropUnpublishedRootTask(task, recoveryReason, shouldRecoverUnpublishedRoot) {
|
|
1761
|
+
if (taskRequiresBaselineOnDrop(task) || shouldRecoverUnpublishedRoot) {
|
|
1762
|
+
return handleOverflow({
|
|
1763
|
+
reason: recoveryReason || 'published_move_serialization_watermark'
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
markLocallyDroppedRootNode(task.rootNode);
|
|
1767
|
+
cancelPendingRootTask(task);
|
|
1768
|
+
return true;
|
|
1769
|
+
}
|
|
1770
|
+
function dropUnadmittedRootNode(node, publicationToken, requiresBaselineOnDrop, recoveryReason, shouldRecoverUnpublishedRoot) {
|
|
1771
|
+
if (requiresBaselineOnDrop || shouldRecoverUnpublishedRoot) {
|
|
1772
|
+
cancelPublicationToken(publicationToken);
|
|
1773
|
+
return handleOverflow({
|
|
1774
|
+
reason: recoveryReason || 'published_move_serialization_watermark'
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
markLocallyDroppedRootNode(node);
|
|
1778
|
+
cancelPublicationToken(publicationToken);
|
|
1779
|
+
return true;
|
|
1780
|
+
}
|
|
1781
|
+
function dropMutationGroupTasks(mutationGroup) {
|
|
1782
|
+
if (stopped || overflowed || !mutationGroup || !pendingRootTaskBySequence.size) {
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
var tasks = Array.from(pendingRootTaskBySequence.values()).filter(function (task) {
|
|
1786
|
+
return task.mutationGroup === mutationGroup;
|
|
1787
|
+
});
|
|
1788
|
+
if (!tasks.length) {
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
if (tasks.some(function (task) {
|
|
1792
|
+
return taskRequiresBaselineOnDrop(task);
|
|
1793
|
+
})) {
|
|
1794
|
+
return handleOverflow({
|
|
1795
|
+
reason: 'published_move_normalization_budget'
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
// Mark the whole group before cancellation. Sibling anchors are resolved
|
|
1799
|
+
// again immediately before emission, so no eager pending-task scan is
|
|
1800
|
+
// needed here.
|
|
1801
|
+
tasks.forEach(function (task) {
|
|
1802
|
+
markSharedLocallyDroppedRootNode(task.rootNode);
|
|
1803
|
+
locallyDroppedRootNodes.add(task.rootNode);
|
|
1804
|
+
});
|
|
1805
|
+
tasks.forEach(function (task) {
|
|
1806
|
+
cancelPendingRootTask(task);
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
function markPendingRootTaskPublishedDependency(task) {
|
|
1810
|
+
if (task && task.generation === generation && !task.isCancelled) {
|
|
1811
|
+
task.requiresBaselineOnDrop = true;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
function taskRequiresBaselineOnDrop(task) {
|
|
1815
|
+
return Boolean(task && task.requiresBaselineOnDrop);
|
|
1816
|
+
}
|
|
1817
|
+
function markLocallyDroppedRootNode(node) {
|
|
1818
|
+
markSharedLocallyDroppedRootNode(node);
|
|
1819
|
+
locallyDroppedRootNodes.add(node);
|
|
1820
|
+
}
|
|
1821
|
+
function markSharedLocallyDroppedRootNode(node) {
|
|
1822
|
+
var dependencyState = getMutationDependencyState(shadowRootsController);
|
|
1823
|
+
if (dependencyState) {
|
|
1824
|
+
dependencyState.$rLocallyDroppedRoots.add(node);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
function clearLocallyDroppedRootNode(node) {
|
|
1828
|
+
locallyDroppedRootNodes["delete"](node);
|
|
1829
|
+
var dependencyState = getMutationDependencyState(shadowRootsController);
|
|
1830
|
+
if (dependencyState) {
|
|
1831
|
+
dependencyState.$rLocallyDroppedRoots["delete"](node);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
function removeDeferredRootTaskQueueMembership(task) {
|
|
1835
|
+
if (!task || !task.isDeferred) {
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
task.isDeferred = false;
|
|
1839
|
+
deferredRootTaskCount = Math.max(deferredRootTaskCount - 1, 0);
|
|
473
1840
|
}
|
|
474
1841
|
function schedulePendingRootTasks() {
|
|
475
|
-
if (stopped || scheduledFlush || !
|
|
1842
|
+
if (stopped || overflowed || scheduledFlush || !pendingRootTaskCount) {
|
|
476
1843
|
return;
|
|
477
1844
|
}
|
|
478
1845
|
scheduledFlush = setTimeout(function () {
|
|
479
1846
|
scheduledFlush = undefined;
|
|
480
|
-
processPendingRootTasks(false);
|
|
1847
|
+
processPendingRootTasks(getCurrentTime() + MUTATION_SERIALIZATION_SLICE_MS, false);
|
|
481
1848
|
}, 0);
|
|
482
1849
|
}
|
|
483
|
-
function processPendingRootTasks(
|
|
1850
|
+
function processPendingRootTasks(deadline, flushCompletedTasks) {
|
|
484
1851
|
clearScheduledFlush();
|
|
485
|
-
if (stopped) {
|
|
486
|
-
return;
|
|
1852
|
+
if (stopped || overflowed) {
|
|
1853
|
+
return true;
|
|
487
1854
|
}
|
|
488
|
-
if (
|
|
489
|
-
|
|
490
|
-
emitCompletedRootTasks();
|
|
491
|
-
}
|
|
492
|
-
return;
|
|
1855
|
+
if (flushCompletedTasks && completedRootTasksBySequence.size) {
|
|
1856
|
+
emitCompletedRootTasks();
|
|
493
1857
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
1858
|
+
if (!pendingRootTaskCount) {
|
|
1859
|
+
return true;
|
|
1860
|
+
}
|
|
1861
|
+
var serializationStart = false ? getCurrentTime() : 0;
|
|
1862
|
+
while (pendingRootTaskCount) {
|
|
1863
|
+
var task = dequeuePendingRootTask();
|
|
1864
|
+
if (!task) {
|
|
1865
|
+
break;
|
|
1866
|
+
}
|
|
497
1867
|
if (task.generation !== generation) {
|
|
498
1868
|
continue;
|
|
499
1869
|
}
|
|
500
|
-
|
|
1870
|
+
if (task.isDeferred) {
|
|
1871
|
+
if (activeRootTaskCount >= MAX_PENDING_MUTATION_ROOT_TASKS) {
|
|
1872
|
+
emitCompletedRootTasks();
|
|
1873
|
+
if (stopped || overflowed) {
|
|
1874
|
+
return false;
|
|
1875
|
+
}
|
|
1876
|
+
if (activeRootTaskCount >= MAX_PENDING_MUTATION_ROOT_TASKS) {
|
|
1877
|
+
return handleOverflow({
|
|
1878
|
+
reason: MUTATION_ROOT_ADMISSION_WATERMARK
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
var activationResult = refreshPendingRootTask(task, true);
|
|
1883
|
+
if (activationResult === 'blocked') {
|
|
1884
|
+
emitCompletedRootTasks();
|
|
1885
|
+
if (stopped || overflowed) {
|
|
1886
|
+
return false;
|
|
1887
|
+
}
|
|
1888
|
+
activationResult = refreshPendingRootTask(task, true);
|
|
1889
|
+
if (activationResult === 'blocked') {
|
|
1890
|
+
return handleOverflow({
|
|
1891
|
+
reason: MUTATION_ROOT_RETAINED_BYTES_WATERMARK,
|
|
1892
|
+
mutationApproxBytes: getRetainedMutationApproxBytes()
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
if (activationResult === false) {
|
|
1897
|
+
return false;
|
|
1898
|
+
}
|
|
1899
|
+
if (task.isCancelled || !task.isActiveSerializerTask) {
|
|
1900
|
+
continue;
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
var completed = task.serializerTask.advance(deadline, MUTATION_SERIALIZATION_MAX_NODE_COUNT, MUTATION_SERIALIZATION_MAX_APPROX_BYTES);
|
|
501
1904
|
if (task.generation !== generation) {
|
|
502
1905
|
continue;
|
|
503
1906
|
}
|
|
1907
|
+
if (!updateRetainedRootTaskApproxBytes(task, task.serializerTask.approxBytes)) {
|
|
1908
|
+
handleOverflow({
|
|
1909
|
+
reason: AGGREGATE_RETAINED_MUTATION_WATERMARK,
|
|
1910
|
+
mutationApproxBytes: getRetainedMutationApproxBytes()
|
|
1911
|
+
});
|
|
1912
|
+
return false;
|
|
1913
|
+
}
|
|
1914
|
+
if (!completed && (task.serializerTask.isMaxNodeCountReached || task.serializerTask.isMaxApproxBytesReached || task.serializerTask.isMaxDepthReached || task.serializerTask.isMaxNodeComplexityReached)) {
|
|
1915
|
+
// A new subtree that only exceeds the mutation record's node/byte
|
|
1916
|
+
// watermarks may still fit in the larger full-snapshot budget. Replace
|
|
1917
|
+
// the baseline so a static oversized root is not lost forever. Depth
|
|
1918
|
+
// and per-node complexity use the same hard limits in a full snapshot,
|
|
1919
|
+
// so those remain a bounded local drop.
|
|
1920
|
+
var shouldRecoverUnpublishedRoot = !task.serializerTask.isMaxDepthReached && !task.serializerTask.isMaxNodeComplexityReached && (task.serializerTask.isMaxNodeCountReached || task.serializerTask.isMaxApproxBytesReached);
|
|
1921
|
+
if (!dropUnpublishedRootTask(task, taskRequiresBaselineOnDrop(task) ? 'published_move_serialization_watermark' : 'unpublished_add_serialization_watermark', shouldRecoverUnpublishedRoot)) {
|
|
1922
|
+
return false;
|
|
1923
|
+
}
|
|
1924
|
+
continue;
|
|
1925
|
+
}
|
|
504
1926
|
if (completed) {
|
|
505
1927
|
task.isCompleted = true;
|
|
506
|
-
|
|
1928
|
+
completedRootTasksBySequence.set(task.sequence, task);
|
|
1929
|
+
}
|
|
1930
|
+
if (getRetainedMutationApproxBytes() > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1931
|
+
emitCompletedRootTasks();
|
|
1932
|
+
if (getRetainedMutationApproxBytes() > MAX_PENDING_MUTATION_ROOT_APPROX_BYTES) {
|
|
1933
|
+
handleOverflow({
|
|
1934
|
+
reason: MUTATION_ROOT_RETAINED_BYTES_WATERMARK
|
|
1935
|
+
});
|
|
1936
|
+
return false;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
if (completed) {
|
|
1940
|
+
if (getCurrentTime() >= deadline) {
|
|
1941
|
+
break;
|
|
1942
|
+
}
|
|
507
1943
|
} else {
|
|
508
|
-
|
|
509
|
-
if (
|
|
1944
|
+
enqueuePendingRootTaskContinuation(task);
|
|
1945
|
+
if (getCurrentTime() >= deadline) {
|
|
510
1946
|
break;
|
|
511
1947
|
}
|
|
512
1948
|
}
|
|
513
1949
|
}
|
|
514
|
-
if (
|
|
515
|
-
|
|
516
|
-
emitCompletedRootTasks();
|
|
517
|
-
} else {
|
|
518
|
-
scheduleCompletedRootTasksEmit();
|
|
519
|
-
}
|
|
1950
|
+
if (completedRootTasksBySequence.size) {
|
|
1951
|
+
emitCompletedRootTasks();
|
|
520
1952
|
}
|
|
521
|
-
if (
|
|
1953
|
+
if (pendingRootTaskCount) {
|
|
522
1954
|
schedulePendingRootTasks();
|
|
523
1955
|
}
|
|
1956
|
+
if (false && mutationPerfCb) {
|
|
1957
|
+
mutationPerfCb({
|
|
1958
|
+
mutationSerializationCount: 1,
|
|
1959
|
+
mutationSerializationDuration: getCurrentTime() - serializationStart
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
return pendingRootTaskCount === 0;
|
|
524
1963
|
}
|
|
525
1964
|
function clearScheduledFlush() {
|
|
526
1965
|
if (scheduledFlush) {
|
|
@@ -528,90 +1967,319 @@ function createMutationTasksController(mutationCallback, configuration, shadowRo
|
|
|
528
1967
|
scheduledFlush = undefined;
|
|
529
1968
|
}
|
|
530
1969
|
}
|
|
531
|
-
function scheduleCompletedRootTasksEmit() {
|
|
532
|
-
if (stopped || scheduledEmit || !completedRootTasks.length) {
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
scheduledEmit = setTimeout(function () {
|
|
536
|
-
scheduledEmit = undefined;
|
|
537
|
-
emitCompletedRootTasks();
|
|
538
|
-
}, MUTATION_SERIALIZATION_EMIT_DELAY_MS);
|
|
539
|
-
}
|
|
540
1970
|
function emitCompletedRootTasks() {
|
|
541
|
-
|
|
542
|
-
if (!completedRootTasks.length) {
|
|
1971
|
+
if (overflowed || !completedRootTasksBySequence.size) {
|
|
543
1972
|
return;
|
|
544
1973
|
}
|
|
545
|
-
var completedTasksBySequence = new Map();
|
|
546
|
-
completedRootTasks.forEach(function (task) {
|
|
547
|
-
completedTasksBySequence.set(task.sequence, task);
|
|
548
|
-
});
|
|
549
1974
|
var readyTasks = [];
|
|
550
1975
|
advanceEmitSequencePastGaps();
|
|
551
1976
|
while (nextEmitSequence < nextTaskSequence) {
|
|
552
|
-
var nextTask =
|
|
1977
|
+
var nextTask = completedRootTasksBySequence.get(nextEmitSequence);
|
|
553
1978
|
if (!nextTask) {
|
|
554
1979
|
break;
|
|
555
1980
|
}
|
|
556
1981
|
readyTasks.push(nextTask);
|
|
557
|
-
|
|
1982
|
+
completedRootTasksBySequence["delete"](nextEmitSequence);
|
|
558
1983
|
nextEmitSequence += 1;
|
|
559
1984
|
}
|
|
560
1985
|
if (!readyTasks.length) {
|
|
561
|
-
if (
|
|
1986
|
+
if (pendingRootTaskCount || deferredRootTaskCount) {
|
|
562
1987
|
schedulePendingRootTasks();
|
|
563
|
-
} else if (completedRootTasks.length) {
|
|
564
|
-
scheduleCompletedRootTasksEmit();
|
|
565
1988
|
}
|
|
566
1989
|
return;
|
|
567
1990
|
}
|
|
568
|
-
var
|
|
1991
|
+
var emissionGeneration = generation;
|
|
1992
|
+
var ungroupedAdds = [];
|
|
1993
|
+
var ungroupedAddsApproxBytes = 64;
|
|
1994
|
+
var queuedRootParentIds = new Map();
|
|
1995
|
+
var siblingResolutionState = [getCurrentTime() + MUTATION_NORMALIZATION_MAX_DURATION_MS, 0, false, new Map(), new Map()];
|
|
1996
|
+
for (var resolutionIndex = 0; resolutionIndex < readyTasks.length; resolutionIndex += 1) {
|
|
1997
|
+
var resolutionTask = readyTasks[resolutionIndex];
|
|
1998
|
+
resolutionTask.nextId = getNextSibling(resolutionTask.rootNode, queuedRootParentIds, true, siblingResolutionState, resolutionTask.parentId, resolutionTask.sequence);
|
|
1999
|
+
if (siblingResolutionState[2]) {
|
|
2000
|
+
handleOverflow({
|
|
2001
|
+
reason: 'mutation_sibling_resolution_watermark',
|
|
2002
|
+
mutationNodeCount: siblingResolutionState[1]
|
|
2003
|
+
});
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
queuedRootParentIds.set(resolutionTask.serializerTask.serializedNode.id, resolutionTask.parentId);
|
|
2007
|
+
}
|
|
2008
|
+
function isEmissionGenerationActive() {
|
|
2009
|
+
return !stopped && !overflowed && generation === emissionGeneration;
|
|
2010
|
+
}
|
|
2011
|
+
function emitUngroupedAdds() {
|
|
2012
|
+
if (!ungroupedAdds.length) {
|
|
2013
|
+
return true;
|
|
2014
|
+
}
|
|
2015
|
+
var adds = ungroupedAdds;
|
|
2016
|
+
var approxBytes = ungroupedAddsApproxBytes;
|
|
2017
|
+
ungroupedAdds = [];
|
|
2018
|
+
ungroupedAddsApproxBytes = 64;
|
|
2019
|
+
var payload = {
|
|
2020
|
+
adds: adds,
|
|
2021
|
+
removes: [],
|
|
2022
|
+
texts: [],
|
|
2023
|
+
attributes: []
|
|
2024
|
+
};
|
|
2025
|
+
approxBytesByMutationPayload.set(payload, approxBytes);
|
|
2026
|
+
mutationCallback(payload);
|
|
2027
|
+
return isEmissionGenerationActive();
|
|
2028
|
+
}
|
|
2029
|
+
for (var readyTaskIndex = 0; readyTaskIndex < readyTasks.length; readyTaskIndex += 1) {
|
|
2030
|
+
if (!isEmissionGenerationActive()) {
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
var task = readyTasks[readyTaskIndex];
|
|
569
2034
|
pendingRootTaskByRootNode["delete"](task.rootNode);
|
|
570
2035
|
pendingRootTaskBySequence["delete"](task.sequence);
|
|
571
|
-
|
|
2036
|
+
var activeMutationGroup = task.mutationGroup && isActiveMutationGroup(task.mutationGroup) && !task.mutationGroup.canceled ? task.mutationGroup : undefined;
|
|
2037
|
+
if (activeMutationGroup) {
|
|
2038
|
+
// Preserve callback order across the async serializer. A later pure
|
|
2039
|
+
// add can reference a node published by this atomic group through its
|
|
2040
|
+
// nextId, so it must not overtake the group's remove + add payload.
|
|
2041
|
+
if (!emitUngroupedAdds()) {
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
2044
|
+
transferRetainedRootTaskToMutationGroup(task, activeMutationGroup);
|
|
2045
|
+
} else {
|
|
2046
|
+
ungroupedAddsApproxBytes += task.accountedApproxBytes;
|
|
2047
|
+
releaseRetainedRootTask(task);
|
|
2048
|
+
}
|
|
2049
|
+
var add = {
|
|
572
2050
|
nextId: task.nextId,
|
|
573
2051
|
parentId: task.parentId,
|
|
574
2052
|
node: task.serializerTask.serializedNode
|
|
575
2053
|
};
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
2054
|
+
task.publicationToken.$rQueued = true;
|
|
2055
|
+
publicationTokenByMutationAdd.set(add, task.publicationToken);
|
|
2056
|
+
task.publicationToken = undefined;
|
|
2057
|
+
if (activeMutationGroup) {
|
|
2058
|
+
activeMutationGroup.payload.adds.push(add);
|
|
2059
|
+
} else {
|
|
2060
|
+
ungroupedAdds.push(add);
|
|
2061
|
+
}
|
|
2062
|
+
releaseMutationGroupDependency(task);
|
|
2063
|
+
if (activeMutationGroup) {
|
|
2064
|
+
emitReadyMutationGroups();
|
|
2065
|
+
if (!isEmissionGenerationActive()) {
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
588
2069
|
}
|
|
2070
|
+
if (!emitUngroupedAdds()) {
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
2073
|
+
// An attribute/text-only group can be waiting behind an earlier
|
|
2074
|
+
// ungrouped serializer task even though it has no tasks of its own.
|
|
2075
|
+
emitReadyMutationGroups();
|
|
589
2076
|
}
|
|
590
2077
|
function removeCompletedRootTask(task) {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
2078
|
+
completedRootTasksBySequence["delete"](task.sequence);
|
|
2079
|
+
}
|
|
2080
|
+
function updateRetainedRootTaskApproxBytes(task, approxBytes) {
|
|
2081
|
+
if (!task.isRetained) {
|
|
2082
|
+
return true;
|
|
2083
|
+
}
|
|
2084
|
+
retainedRootTaskApproxBytes += approxBytes - task.accountedApproxBytes;
|
|
2085
|
+
task.accountedApproxBytes = approxBytes;
|
|
2086
|
+
return updateRetainedMutationResourceBudget();
|
|
2087
|
+
}
|
|
2088
|
+
function releaseRetainedRootTask(task) {
|
|
2089
|
+
if (!task.isRetained) {
|
|
2090
|
+
return;
|
|
2091
|
+
}
|
|
2092
|
+
task.isRetained = false;
|
|
2093
|
+
retainedRootTaskApproxBytes = Math.max(0, retainedRootTaskApproxBytes - task.accountedApproxBytes);
|
|
2094
|
+
task.accountedApproxBytes = 0;
|
|
2095
|
+
updateRetainedMutationResourceBudget();
|
|
2096
|
+
releaseActiveRootTask(task);
|
|
2097
|
+
releaseDeferredRootTaskOutstanding(task);
|
|
2098
|
+
}
|
|
2099
|
+
function releaseActiveRootTask(task) {
|
|
2100
|
+
if (!task || !task.isActiveSerializerTask) {
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
task.isActiveSerializerTask = false;
|
|
2104
|
+
activeRootTaskCount = Math.max(activeRootTaskCount - 1, 0);
|
|
2105
|
+
}
|
|
2106
|
+
function releaseDeferredRootTaskOutstanding(task) {
|
|
2107
|
+
if (!task || !task.wasDeferred) {
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
task.wasDeferred = false;
|
|
2111
|
+
deferredRootTaskOutstandingCount = Math.max(deferredRootTaskOutstandingCount - 1, 0);
|
|
594
2112
|
}
|
|
595
|
-
function
|
|
596
|
-
if (
|
|
597
|
-
|
|
598
|
-
scheduledEmit = undefined;
|
|
2113
|
+
function updateRetainedMutationResourceBudget() {
|
|
2114
|
+
if (!mutationResourceBudget) {
|
|
2115
|
+
return true;
|
|
599
2116
|
}
|
|
2117
|
+
var approxBytes = getRetainedMutationApproxBytes();
|
|
2118
|
+
if (!approxBytes) {
|
|
2119
|
+
if (retainedMutationBudgetReservation) {
|
|
2120
|
+
retainedMutationBudgetReservation();
|
|
2121
|
+
retainedMutationBudgetReservation = undefined;
|
|
2122
|
+
}
|
|
2123
|
+
return true;
|
|
2124
|
+
}
|
|
2125
|
+
if (!retainedMutationBudgetReservation) {
|
|
2126
|
+
retainedMutationBudgetReservation = mutationResourceBudget.reserve(_mutationResourceBudget.MUTATION_RESOURCE_RETAINED, {
|
|
2127
|
+
approxBytes: approxBytes
|
|
2128
|
+
});
|
|
2129
|
+
return Boolean(retainedMutationBudgetReservation);
|
|
2130
|
+
}
|
|
2131
|
+
return retainedMutationBudgetReservation.update({
|
|
2132
|
+
approxBytes: approxBytes
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
function createTrackedMutationSerializerTask(node, serializationOptions) {
|
|
2136
|
+
var publicationToken = createMutationAddPublicationToken(shadowRootsController, serializationOptions.requiresBaselineOnDrop);
|
|
2137
|
+
var serializationContext = (0, _browserCore.assign)({}, serializationOptions.serializationContext, {
|
|
2138
|
+
publicationToken: publicationToken
|
|
2139
|
+
});
|
|
2140
|
+
var serializerTask = (0, _serialize.createMutationSerializerTask)(node, (0, _browserCore.assign)({}, serializationOptions, {
|
|
2141
|
+
serializationContext: serializationContext,
|
|
2142
|
+
onSerializedNode: function onSerializedNode(node, parentNode) {
|
|
2143
|
+
// A previously degraded node can later be published as a descendant
|
|
2144
|
+
// of a wider root task. Clear both local markers for every staged
|
|
2145
|
+
// node, not only when that node becomes a root task itself.
|
|
2146
|
+
clearLocallyDroppedRootNode(node);
|
|
2147
|
+
if (mutationNodeSerializationCb) {
|
|
2148
|
+
mutationNodeSerializationCb(node, parentNode, publicationToken);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
}));
|
|
2152
|
+
return {
|
|
2153
|
+
serializerTask: serializerTask,
|
|
2154
|
+
publicationToken: publicationToken
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
function cancelPublicationToken(publicationToken) {
|
|
2158
|
+
cancelMutationAddPublicationToken(publicationToken);
|
|
600
2159
|
}
|
|
601
2160
|
function advanceEmitSequencePastGaps() {
|
|
602
2161
|
while (nextEmitSequence < nextTaskSequence && !pendingRootTaskBySequence.has(nextEmitSequence)) {
|
|
603
2162
|
nextEmitSequence += 1;
|
|
604
2163
|
}
|
|
605
2164
|
}
|
|
606
|
-
function
|
|
2165
|
+
function enqueuePendingRootTask(task) {
|
|
2166
|
+
if (task.isQueued) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
if (!pendingRootTaskCount) {
|
|
2170
|
+
pendingRootTasks = [];
|
|
2171
|
+
pendingRootTaskHead = 0;
|
|
2172
|
+
}
|
|
2173
|
+
task.isQueued = true;
|
|
2174
|
+
pendingRootTaskCount += 1;
|
|
2175
|
+
pendingRootTasks.push(task);
|
|
2176
|
+
}
|
|
2177
|
+
function enqueuePendingRootTaskContinuation(task) {
|
|
2178
|
+
if (task.isQueued) {
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
task.isQueued = true;
|
|
2182
|
+
pendingRootTaskCount += 1;
|
|
2183
|
+
pendingRootTaskContinuation = task;
|
|
2184
|
+
}
|
|
2185
|
+
function dequeuePendingRootTask() {
|
|
2186
|
+
if (pendingRootTaskContinuation) {
|
|
2187
|
+
var continuation = pendingRootTaskContinuation;
|
|
2188
|
+
pendingRootTaskContinuation = undefined;
|
|
2189
|
+
if (continuation.isQueued) {
|
|
2190
|
+
continuation.isQueued = false;
|
|
2191
|
+
pendingRootTaskCount -= 1;
|
|
2192
|
+
return continuation;
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
while (pendingRootTaskHead < pendingRootTasks.length) {
|
|
2196
|
+
var task = pendingRootTasks[pendingRootTaskHead++];
|
|
2197
|
+
if (!task.isQueued) {
|
|
2198
|
+
continue;
|
|
2199
|
+
}
|
|
2200
|
+
task.isQueued = false;
|
|
2201
|
+
pendingRootTaskCount -= 1;
|
|
2202
|
+
compactPendingRootTaskQueue();
|
|
2203
|
+
if (!task.isCancelled) {
|
|
2204
|
+
return task;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
function compactPendingRootTaskQueue() {
|
|
2209
|
+
if (pendingRootTaskHead >= 256 && pendingRootTaskHead * 2 >= pendingRootTasks.length) {
|
|
2210
|
+
pendingRootTasks = pendingRootTasks.slice(pendingRootTaskHead);
|
|
2211
|
+
pendingRootTaskHead = 0;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
function getNextSibling(node, serializedNodeIds, requireQueued, resolutionState, expectedParentId, taskSequence) {
|
|
2215
|
+
if (requireQueued && (0, _serializationUtils.getSerializedNodeId)((0, _browserCore.getParentNode)(node)) !== expectedParentId) {
|
|
2216
|
+
// The native move is still waiting in MutationBatch. Emit the old-parent
|
|
2217
|
+
// add without a cross-parent anchor; the later normalized move will place
|
|
2218
|
+
// it under the current parent.
|
|
2219
|
+
return null;
|
|
2220
|
+
}
|
|
607
2221
|
var nextSibling = node.nextSibling;
|
|
2222
|
+
var visitedNodes = resolutionState ? [] : undefined;
|
|
608
2223
|
while (nextSibling) {
|
|
2224
|
+
if (resolutionState && consumeSiblingResolutionBudget(resolutionState)) {
|
|
2225
|
+
return null;
|
|
2226
|
+
}
|
|
609
2227
|
if ((0, _serializationUtils.hasSerializedNode)(nextSibling)) {
|
|
610
|
-
|
|
2228
|
+
var nextSiblingId = (0, _serializationUtils.getSerializedNodeId)(nextSibling);
|
|
2229
|
+
var pendingNextSiblingTask = requireQueued ? findPendingRootTask(nextSibling) : undefined;
|
|
2230
|
+
var serializedSiblingIsQueuedInCurrentParent = Boolean(serializedNodeIds && serializedNodeIds.has(nextSiblingId));
|
|
2231
|
+
if (serializedSiblingIsQueuedInCurrentParent && requireQueued) {
|
|
2232
|
+
serializedSiblingIsQueuedInCurrentParent = serializedNodeIds.get(nextSiblingId) === (0, _serializationUtils.getSerializedNodeId)((0, _browserCore.getParentNode)(nextSibling));
|
|
2233
|
+
}
|
|
2234
|
+
if (!locallyDroppedRootNodes.has(nextSibling) && (!pendingNextSiblingTask || serializedSiblingIsQueuedInCurrentParent) && (serializedSiblingIsQueuedInCurrentParent || !isIgnoredNode(nextSibling, requireQueued))) {
|
|
2235
|
+
return finalizeSiblingResolution(resolutionState, visitedNodes, nextSiblingId, Infinity);
|
|
2236
|
+
}
|
|
2237
|
+
var cachedMinSequence = resolutionState && resolutionState[4].get(nextSibling);
|
|
2238
|
+
if (cachedMinSequence !== undefined && cachedMinSequence >= taskSequence) {
|
|
2239
|
+
return finalizeSiblingResolution(resolutionState, visitedNodes, resolutionState[3].get(nextSibling), cachedMinSequence);
|
|
2240
|
+
}
|
|
2241
|
+
if (visitedNodes) {
|
|
2242
|
+
visitedNodes.push(nextSibling, pendingNextSiblingTask ? pendingNextSiblingTask.sequence : Infinity);
|
|
2243
|
+
}
|
|
2244
|
+
} else if (visitedNodes) {
|
|
2245
|
+
var cachedIgnoredMinSequence = resolutionState[4].get(nextSibling);
|
|
2246
|
+
if (cachedIgnoredMinSequence !== undefined && cachedIgnoredMinSequence >= taskSequence) {
|
|
2247
|
+
return finalizeSiblingResolution(resolutionState, visitedNodes, resolutionState[3].get(nextSibling), cachedIgnoredMinSequence);
|
|
2248
|
+
}
|
|
2249
|
+
visitedNodes.push(nextSibling, Infinity);
|
|
611
2250
|
}
|
|
612
2251
|
nextSibling = nextSibling.nextSibling;
|
|
613
2252
|
}
|
|
614
|
-
return null;
|
|
2253
|
+
return finalizeSiblingResolution(resolutionState, visitedNodes, null, Infinity);
|
|
2254
|
+
}
|
|
2255
|
+
function finalizeSiblingResolution(resolutionState, visitedNodes, nextId, minPendingSequence) {
|
|
2256
|
+
if (!resolutionState) {
|
|
2257
|
+
return nextId;
|
|
2258
|
+
}
|
|
2259
|
+
for (var index = visitedNodes.length - 2; index >= 0; index -= 2) {
|
|
2260
|
+
if (consumeSiblingResolutionBudget(resolutionState)) {
|
|
2261
|
+
return null;
|
|
2262
|
+
}
|
|
2263
|
+
minPendingSequence = Math.min(minPendingSequence, visitedNodes[index + 1]);
|
|
2264
|
+
resolutionState[3].set(visitedNodes[index], nextId);
|
|
2265
|
+
resolutionState[4].set(visitedNodes[index], minPendingSequence);
|
|
2266
|
+
}
|
|
2267
|
+
return nextId;
|
|
2268
|
+
}
|
|
2269
|
+
function consumeSiblingResolutionBudget(resolutionState) {
|
|
2270
|
+
resolutionState[1] += 1;
|
|
2271
|
+
if (resolutionState[1] >= MAX_PENDING_MUTATION_ROOT_TASKS * 32 || resolutionState[1] % MUTATION_NORMALIZATION_TIME_CHECK_INTERVAL === 0 && getCurrentTime() >= resolutionState[0]) {
|
|
2272
|
+
resolutionState[2] = true;
|
|
2273
|
+
return true;
|
|
2274
|
+
}
|
|
2275
|
+
return false;
|
|
2276
|
+
}
|
|
2277
|
+
function isIgnoredNode(node, includeQueued) {
|
|
2278
|
+
try {
|
|
2279
|
+
return isNodeIgnored(node, includeQueued);
|
|
2280
|
+
} catch (_) {
|
|
2281
|
+
return true;
|
|
2282
|
+
}
|
|
615
2283
|
}
|
|
616
2284
|
}
|
|
617
2285
|
function getCurrentTime() {
|
|
@@ -620,12 +2288,53 @@ function getCurrentTime() {
|
|
|
620
2288
|
}
|
|
621
2289
|
return Date.now();
|
|
622
2290
|
}
|
|
623
|
-
function traverseRemovedShadowDom(removedNode, shadowDomRemovedCallback) {
|
|
624
|
-
if (
|
|
625
|
-
|
|
2291
|
+
function traverseRemovedShadowDom(removedNode, shadowDomRemovedCallback, traversalState) {
|
|
2292
|
+
if (traversalState.deadline === undefined) {
|
|
2293
|
+
traversalState.deadline = getCurrentTime() + MAX_REMOVED_SUBTREE_TRAVERSAL_DURATION_MS;
|
|
626
2294
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
2295
|
+
// Keep one cursor frame per depth level instead of pushing every child of a
|
|
2296
|
+
// wide subtree. The stack itself is therefore bounded by the same node
|
|
2297
|
+
// watermark as the traversal.
|
|
2298
|
+
var traversalStack = [{
|
|
2299
|
+
node: removedNode,
|
|
2300
|
+
entered: false
|
|
2301
|
+
}];
|
|
2302
|
+
while (traversalStack.length) {
|
|
2303
|
+
var frame = traversalStack[traversalStack.length - 1];
|
|
2304
|
+
if (frame.entered) {
|
|
2305
|
+
if (frame.nextChild) {
|
|
2306
|
+
var nextChild = frame.nextChild;
|
|
2307
|
+
frame.nextChild = nextChild.nextSibling;
|
|
2308
|
+
traversalStack.push({
|
|
2309
|
+
node: nextChild,
|
|
2310
|
+
entered: false
|
|
2311
|
+
});
|
|
2312
|
+
continue;
|
|
2313
|
+
}
|
|
2314
|
+
if (frame.shadowRoot) {
|
|
2315
|
+
var shadowRoot = frame.shadowRoot;
|
|
2316
|
+
frame.shadowRoot = undefined;
|
|
2317
|
+
traversalStack.push({
|
|
2318
|
+
node: shadowRoot,
|
|
2319
|
+
entered: false
|
|
2320
|
+
});
|
|
2321
|
+
continue;
|
|
2322
|
+
}
|
|
2323
|
+
traversalStack.pop();
|
|
2324
|
+
continue;
|
|
2325
|
+
}
|
|
2326
|
+
if (traversalState.nodeCount >= MAX_REMOVED_SUBTREE_TRAVERSAL_NODES || traversalState.nodeCount % REMOVED_SUBTREE_TIME_CHECK_INTERVAL === 0 && getCurrentTime() >= traversalState.deadline) {
|
|
2327
|
+
return false;
|
|
2328
|
+
}
|
|
2329
|
+
frame.entered = true;
|
|
2330
|
+
traversalState.nodeCount += 1;
|
|
2331
|
+
var node = frame.node;
|
|
2332
|
+
if ((0, _browserCore.isNodeShadowHost)(node)) {
|
|
2333
|
+
shadowDomRemovedCallback(node.shadowRoot);
|
|
2334
|
+
frame.shadowRoot = node.shadowRoot;
|
|
2335
|
+
}
|
|
2336
|
+
frame.nextChild = node.firstChild;
|
|
2337
|
+
}
|
|
2338
|
+
return true;
|
|
630
2339
|
}
|
|
631
2340
|
//# sourceMappingURL=mutationObserver.js.map
|