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