Changeset 237880 in webkit
- Timestamp:
- Nov 6, 2018 12:52:51 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r237879 r237880 1 2018-11-06 Ali Juma <ajuma@chromium.org> 2 3 IntersectionObserver doesn't keep target's JS wrapper alive 4 https://bugs.webkit.org/show_bug.cgi?id=190235 5 6 Reviewed by Ryosuke Niwa. 7 8 Add test coverage. 9 10 Update test that depends on a target getting GC'd to call takeRecords() since 11 targets with pending entries are no logner GC'd. 12 13 * intersection-observer/intersection-observer-entry-keeps-js-wrapper-of-target-alive-expected.txt: Added. 14 * intersection-observer/intersection-observer-entry-keeps-js-wrapper-of-target-alive.html: Added. 15 * intersection-observer/intersection-observer-keeps-js-wrapper-of-target-alive-expected.txt: Added. 16 * intersection-observer/intersection-observer-keeps-js-wrapper-of-target-alive.html: Added. 17 * intersection-observer/root-element-deleted.html: 18 * intersection-observer/target-deleted-expected.txt: Added. 19 * intersection-observer/target-deleted.html: Added. 20 1 21 2018-11-06 Eric Carlson <eric.carlson@apple.com> 2 22 -
trunk/LayoutTests/intersection-observer/root-element-deleted.html
r235014 r237880 21 21 target = null; 22 22 requestAnimationFrame(t.step_func_done(function() { 23 observer.takeRecords(); 23 24 GCController.collect(); 24 25 assert_equals(observer.root, null, 'Observer has null root after root element is destroyed'); -
trunk/Source/WebCore/ChangeLog
r237878 r237880 1 2018-11-06 Ali Juma <ajuma@chromium.org> 2 3 IntersectionObserver doesn't keep target's JS wrapper alive 4 https://bugs.webkit.org/show_bug.cgi?id=190235 5 6 Reviewed by Ryosuke Niwa. 7 8 Retain JS wrappers of targets in queued entries using a vector of GCReachableRef owned by 9 IntersectionObserver, which gets cleared after the entries have been delivered. 10 11 Make IntersectionObserver::takeRecords return a struct which has both the vector of GCReachableRefs 12 for targets and the vector of intersection observer entries, so that the GCReachableRefs survive 13 until the creation of JS wrappers for the entries. 14 15 Modify IntersectionObserver::hasPendingActivity to keep the observer alive while it has 16 entries to deliver. 17 18 Tests: intersection-observer/intersection-observer-entry-keeps-js-wrapper-of-target-alive.html 19 intersection-observer/intersection-observer-keeps-js-wrapper-of-target-alive.html 20 intersection-observer/target-deleted.html 21 22 * Sources.txt: 23 * WebCore.xcodeproj/project.pbxproj: 24 * bindings/js/JSIntersectionObserverEntryCustom.cpp: 25 (WebCore::JSIntersectionObserverEntry::visitAdditionalChildren): Keep the target element's wrapper alive while the 26 IntersectionObserverEntry's wrapper is alive. 27 * page/IntersectionObserver.cpp: 28 (WebCore::IntersectionObserver::takeRecords): Change return type to include GCReachableRefs for each record's target, so that 29 each target can be kept until a JS wrapper is constructed for its IntersectionObserverEntry. 30 (WebCore::IntersectionObserver::appendQueuedEntry): 31 (WebCore::IntersectionObserver::notify): Erase GCReachableRefs for targets after delivering the corresponding records. 32 (WebCore::IntersectionObserver::hasPendingActivity const): Keep the IntersectionObserver alive until queued entries are delivered. 33 (WebCore::IntersectionObserver::stop): 34 * page/IntersectionObserver.h: 35 * page/IntersectionObserver.idl: 36 * page/IntersectionObserverEntry.h: 37 (WebCore::IntersectionObserverEntry::target const): Make this return a raw pointer instead of a RefPtr so that it 38 can be called in JSIntersectionObserverEntry::visitAdditionalChildren, which runs on the GC thread (it's illegal to ref a Node 39 on a non-main thread). 40 * page/IntersectionObserverEntry.idl: 41 1 42 2018-11-06 Timothy Hatcher <timothy@apple.com> 2 43 -
trunk/Source/WebCore/Sources.txt
r237855 r237880 431 431 bindings/js/JSIDBTransactionCustom.cpp 432 432 bindings/js/JSImageDataCustom.cpp 433 bindings/js/JSIntersectionObserverEntryCustom.cpp 433 434 bindings/js/JSLazyEventListener.cpp 434 435 bindings/js/JSLocationCustom.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r237855 r237880 9403 9403 77AAD6831ECFB66200BFA2D1 /* CredentialCreationOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CredentialCreationOptions.idl; sourceTree = "<group>"; }; 9404 9404 77AAD6851ECFBD3900BFA2D1 /* CredentialCreationOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CredentialCreationOptions.h; sourceTree = "<group>"; }; 9405 77C13F042165658A002D9C5F /* JSIntersectionObserverEntryCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSIntersectionObserverEntryCustom.cpp; sourceTree = "<group>"; }; 9405 9406 77CAAAEF1F2FC35000CB5C8D /* VisualViewport.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = VisualViewport.idl; sourceTree = "<group>"; }; 9406 9407 77D50FFA1ED4EC7800DA4C87 /* CredentialRequestOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CredentialRequestOptions.idl; sourceTree = "<group>"; }; … … 16130 16131 isa = PBXGroup; 16131 16132 children = ( 16132 71495DD8202B06DC00ADFD34 /* JSEffectTiming.cpp */,16133 71495DDA202B06DE00ADFD34 /* JSEffectTiming.h */,16134 16133 714C7C691FDADAD500F2BEE1 /* JSAnimationPlaybackEvent.cpp */, 16135 16134 714C7C6A1FDADAD500F2BEE1 /* JSAnimationPlaybackEvent.h */, … … 16152 16151 71729F7D20F3BABA00801CE6 /* JSDocumentTimelineOptions.cpp */, 16153 16152 71729F7C20F3BAB900801CE6 /* JSDocumentTimelineOptions.h */, 16153 71495DD8202B06DC00ADFD34 /* JSEffectTiming.cpp */, 16154 71495DDA202B06DE00ADFD34 /* JSEffectTiming.h */, 16154 16155 712BE4841FE867C2002031CC /* JSFillMode.cpp */, 16155 16156 712BE4851FE86818002031CC /* JSFillMode.h */, … … 20014 20015 71EFCED7202B388D00D7C411 /* AnimationEffect.h */, 20015 20016 71EFCED6202B388C00D7C411 /* AnimationEffect.idl */, 20016 712BE47C1FE86448002031CC /* EffectTiming.h */,20017 712BE47A1FE86447002031CC /* EffectTiming.idl */,20018 20017 714C7C601FDAD27900F2BEE1 /* AnimationPlaybackEvent.cpp */, 20019 20018 714C7C651FDAD27B00F2BEE1 /* AnimationPlaybackEvent.h */, … … 20046 20045 71729F7A20F3BA3A00801CE6 /* DocumentTimelineOptions.h */, 20047 20046 71729F7920F3BA3900801CE6 /* DocumentTimelineOptions.idl */, 20047 712BE47C1FE86448002031CC /* EffectTiming.h */, 20048 712BE47A1FE86447002031CC /* EffectTiming.idl */, 20048 20049 712BE4811FE865D4002031CC /* FillMode.h */, 20049 20050 712BE4821FE865D5002031CC /* FillMode.idl */, … … 20260 20261 51E269321DD3BC43006B6A58 /* JSIDBTransactionCustom.cpp */, 20261 20262 A7D0318D0E93540300E24ACD /* JSImageDataCustom.cpp */, 20263 77C13F042165658A002D9C5F /* JSIntersectionObserverEntryCustom.cpp */, 20262 20264 AD726FE716D9F204003A4E6D /* JSMediaListCustom.h */, 20263 20265 415CDAF61E6CE0D3004F11EE /* JSMediaStreamTrackCustom.cpp */, … … 27630 27632 316FE1120E6E1DA700BF6088 /* AnimationBase.h in Headers */, 27631 27633 71EFCEDC202B38A900D7C411 /* AnimationEffect.h in Headers */, 27632 712BE47D1FE86458002031CC /* EffectTiming.h in Headers */,27633 27634 319848011A1D817B00A13318 /* AnimationEvent.h in Headers */, 27634 27635 49E912AD0EFAC906009D0CAF /* AnimationList.h in Headers */, … … 27946 27947 93309DDD099E64920056E581 /* CompositeEditCommand.h in Headers */, 27947 27948 71247E371FEA5F86008C08CE /* CompositeOperation.h in Headers */, 27949 7111243E216FA71100EB7B67 /* CompositeOperationOrAuto.h in Headers */, 27948 27950 79F2F5A21091939A000D87CB /* CompositionEvent.h in Headers */, 27949 27951 2DD5A7271EBEE47D009BA597 /* CompositionUnderline.h in Headers */, … … 27954 27956 A818721C0977D3C0005826D9 /* ContainerNode.h in Headers */, 27955 27957 E1A1470811102B1500EEC0F3 /* ContainerNodeAlgorithms.h in Headers */, 27956 71112441216FA7CD00EB7B67 /* JSCompositeOperationOrAuto.h in Headers */,27957 27958 BC5EB9810E82072500B25965 /* ContentData.h in Headers */, 27958 27959 51B45D211AB8D1E200117CD2 /* ContentExtension.h in Headers */, … … 28392 28393 4BAE95B10B2FA9CE00AED8A0 /* EditorDeleteAction.h in Headers */, 28393 28394 93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */, 28395 712BE47D1FE86458002031CC /* EffectTiming.h in Headers */, 28394 28396 A8C4A80709D563270003AC8D /* Element.h in Headers */, 28395 28397 E4AE7C1A17D232350009FB31 /* ElementAncestorIterator.h in Headers */, … … 29003 29005 576814451E70CB1F00E77754 /* JSAesKeyParams.h in Headers */, 29004 29006 FDA15ECA12B03F50003A583A /* JSAnalyserNode.h in Headers */, 29005 71495DDB202B06F100ADFD34 /* JSEffectTiming.h in Headers */,29006 29007 3198480C1A1E6CE800A13318 /* JSAnimationEvent.h in Headers */, 29007 29008 714C7C6C1FDADAF300F2BEE1 /* JSAnimationPlaybackEvent.h in Headers */, … … 29079 29080 93F9B6E10BA0FB7200854064 /* JSComment.h in Headers */, 29080 29081 71247E3B1FEA5F90008C08CE /* JSCompositeOperation.h in Headers */, 29082 71112441216FA7CD00EB7B67 /* JSCompositeOperationOrAuto.h in Headers */, 29081 29083 79AC9219109945C80021266E /* JSCompositionEvent.h in Headers */, 29082 29084 7116E2CF1FED765B00C06FDE /* JSComputedEffectTiming.h in Headers */, … … 29167 29169 E323CFFA1E5AF6AF00F0B4A0 /* JSDOMConvertPromise.h in Headers */, 29168 29170 7C8E34BF1E4A33B00054CE23 /* JSDOMConvertRecord.h in Headers */, 29169 7111243E216FA71100EB7B67 /* CompositeOperationOrAuto.h in Headers */,29170 29171 7C1F5D591F22FF7300A8874F /* JSDOMConvertScheduledAction.h in Headers */, 29171 29172 7C8E34C01E4A33B00054CE23 /* JSDOMConvertSequences.h in Headers */, … … 29224 29225 57EEAA551EA001B100701124 /* JSEcdsaParams.h in Headers */, 29225 29226 5750A9821E6A150800705C4A /* JSEcKeyParams.h in Headers */, 29227 71495DDB202B06F100ADFD34 /* JSEffectTiming.h in Headers */, 29226 29228 65DF31FA09D1CC60000BE325 /* JSElement.h in Headers */, 29227 29229 ADEC78F818EE5308001315C2 /* JSElementCustom.h in Headers */, … … 29450 29452 3140C5271FDF558200D2A873 /* JSOffscreenCanvasRenderingContext2D.h in Headers */, 29451 29453 57E233651DC7DB1F00F28D01 /* JsonWebKey.h in Headers */, 29454 71207343216DFB4100C78329 /* JSOptionalEffectTiming.h in Headers */, 29452 29455 FDEA6243152102E200479DF0 /* JSOscillatorNode.h in Headers */, 29453 29456 0704A40C1D6DFC690086DCDB /* JSOverconstrainedError.h in Headers */, … … 29588 29591 24D9129613CA956100D21915 /* JSSVGAltGlyphItemElement.h in Headers */, 29589 29592 B222F6990AB771950022EFAD /* JSSVGAngle.h in Headers */, 29590 71207340216DFB0000C78329 /* OptionalEffectTiming.h in Headers */,29591 29593 B2FA3D370AB75A6F000E5AC4 /* JSSVGAnimateColorElement.h in Headers */, 29592 29594 B2FA3D390AB75A6F000E5AC4 /* JSSVGAnimatedAngle.h in Headers */, … … 30181 30183 B2D3DA650D006CD600EF6F27 /* OpenTypeMathData.h in Headers */, 30182 30184 B2D3EA650D006CD600EF6F28 /* OpenTypeTypes.h in Headers */, 30185 71207340216DFB0000C78329 /* OptionalEffectTiming.h in Headers */, 30183 30186 CDE7FC45181904B1002BBB77 /* OrderIterator.h in Headers */, 30184 30187 4184F5161EAF05A800F18BF0 /* OrientationNotifier.h in Headers */, … … 30600 30603 514C767A0CE923A1007EF3CD /* ResourceHandleClient.h in Headers */, 30601 30604 514C767B0CE923A1007EF3CD /* ResourceHandleInternal.h in Headers */, 30602 71207343216DFB4100C78329 /* JSOptionalEffectTiming.h in Headers */,30603 30605 656D373F0ADBA5DE00A4554D /* ResourceLoader.h in Headers */, 30604 30606 D0A3A7311405A39800FB8ED3 /* ResourceLoaderOptions.h in Headers */, -
trunk/Source/WebCore/bindings/js/JSIntersectionObserverEntryCustom.cpp
r237879 r237880 1 1 /* 2 * Copyright (C) 201 6 Apple Inc. All rights reserved.2 * Copyright (C) 2018 Google LLC. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 // https://wicg.github.io/IntersectionObserver/ 26 #include "config.h" 27 #include "JSIntersectionObserverEntry.h" 27 28 28 [ 29 ActiveDOMObject, 30 Conditional=INTERSECTION_OBSERVER, 31 ConstructorCallWith=Document, 32 ConstructorMayThrowException, 33 Constructor(IntersectionObserverCallback callback, optional IntersectionObserverInit options), 34 EnabledAtRuntime=IntersectionObserver 35 ] interface IntersectionObserver { 36 readonly attribute Element? root; 37 readonly attribute DOMString rootMargin; 38 readonly attribute sequence<double> thresholds; 29 #include "JSNodeCustom.h" 39 30 40 void observe(Element target); 41 void unobserve(Element target); 42 void disconnect(); 43 sequence<IntersectionObserverEntry> takeRecords(); 44 }; 31 namespace WebCore { 45 32 46 [ 47 Conditional=INTERSECTION_OBSERVER, 48 EnabledBySetting=IntersectionObserver 49 ] 50 dictionary IntersectionObserverInit { 51 Element? root = null; 52 DOMString rootMargin = "0px"; 53 (double or sequence<double>) threshold = 0.0; 54 }; 33 void JSIntersectionObserverEntry::visitAdditionalChildren(JSC::SlotVisitor& visitor) 34 { 35 visitor.addOpaqueRoot(root(wrapped().target())); 36 } 37 38 } -
trunk/Source/WebCore/page/IntersectionObserver.cpp
r237228 r237880 184 184 } 185 185 186 Vector<Ref<IntersectionObserverEntry>> IntersectionObserver::takeRecords() 187 { 188 return WTFMove(m_queuedEntries);186 auto IntersectionObserver::takeRecords() -> TakenRecords 187 { 188 return { WTFMove(m_queuedEntries), WTFMove(m_pendingTargets) }; 189 189 } 190 190 … … 245 245 void IntersectionObserver::appendQueuedEntry(Ref<IntersectionObserverEntry>&& entry) 246 246 { 247 ASSERT(entry->target()); 248 m_pendingTargets.append(*entry->target()); 247 249 m_queuedEntries.append(WTFMove(entry)); 248 250 } … … 250 252 void IntersectionObserver::notify() 251 253 { 252 if (m_queuedEntries.isEmpty() || !m_callback || !m_callback->canInvokeCallback()) 253 return; 254 255 m_callback->handleEvent(takeRecords(), *this); 254 if (m_queuedEntries.isEmpty()) { 255 ASSERT(m_pendingTargets.isEmpty()); 256 return; 257 } 258 259 auto takenRecords = takeRecords(); 260 m_callback->handleEvent(WTFMove(takenRecords.records), *this); 256 261 } 257 262 258 263 bool IntersectionObserver::hasPendingActivity() const 259 264 { 260 return hasObservationTargets() && trackingDocument();265 return (hasObservationTargets() && trackingDocument()) || !m_queuedEntries.isEmpty(); 261 266 } 262 267 … … 275 280 disconnect(); 276 281 m_callback = nullptr; 282 m_queuedEntries.clear(); 283 m_pendingTargets.clear(); 277 284 } 278 285 -
trunk/Source/WebCore/page/IntersectionObserver.h
r235943 r237880 29 29 30 30 #include "ActiveDOMObject.h" 31 #include "GCReachableRef.h" 31 32 #include "IntersectionObserverCallback.h" 32 33 #include "IntersectionObserverEntry.h" … … 81 82 void disconnect(); 82 83 83 Vector<Ref<IntersectionObserverEntry>> takeRecords(); 84 struct TakenRecords { 85 Vector<Ref<IntersectionObserverEntry>> records; 86 Vector<GCReachableRef<Element>> pendingTargets; 87 }; 88 TakenRecords takeRecords(); 84 89 85 90 void targetDestroyed(Element&); … … 110 115 RefPtr<IntersectionObserverCallback> m_callback; 111 116 Vector<Element*> m_observationTargets; 117 Vector<GCReachableRef<Element>> m_pendingTargets; 112 118 Vector<Ref<IntersectionObserverEntry>> m_queuedEntries; 113 119 }; -
trunk/Source/WebCore/page/IntersectionObserver.idl
r235736 r237880 41 41 void unobserve(Element target); 42 42 void disconnect(); 43 sequence<IntersectionObserverEntry> takeRecords();43 [ResultField=records] sequence<IntersectionObserverEntry> takeRecords(); 44 44 }; 45 45 -
trunk/Source/WebCore/page/IntersectionObserverEntry.h
r234732 r237880 61 61 RefPtr<DOMRectReadOnly> boundingClientRect() const { return m_boundingClientRect; } 62 62 RefPtr<DOMRectReadOnly> intersectionRect() const { return m_intersectionRect; } 63 RefPtr<Element> target() const { return m_target; }63 Element* target() const { return m_target.get(); } 64 64 65 65 bool isIntersecting() const { return m_isIntersecting; } -
trunk/Source/WebCore/page/IntersectionObserverEntry.idl
r234732 r237880 32 32 Constructor(IntersectionObserverEntryInit intersectionObserverEntryInit), 33 33 ImplementationLacksVTable, 34 EnabledAtRuntime=IntersectionObserver 34 EnabledAtRuntime=IntersectionObserver, 35 JSCustomMarkFunction, 35 36 ] interface IntersectionObserverEntry { 36 37 readonly attribute DOMHighResTimeStamp time;
Note: See TracChangeset
for help on using the changeset viewer.