Skip to content

Commit

Permalink
Crash in ViewTransition::create
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265806
rdar://119142736

Reviewed by Tim Nguyen.

If there is no global object, return null.  This matches the behavior of Chromium.

* LayoutTests/fast/dom/view-transition-without-global-object-expected.txt: Added.
* LayoutTests/fast/dom/view-transition-without-global-object.html: Added.
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::startViewTransition):
* Source/WebCore/dom/Document.h:

Canonical link: https://commits.webkit.org/272959@main
  • Loading branch information
achristensen07 committed Jan 12, 2024
1 parent 0c33928 commit 256b846
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALERT: result should be null:null
This test passes if it does not crash.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
if (window.testRunner) { testRunner.dumpAsText() }
let d = document.implementation.createDocument("", null);
alert("result should be null:" + d.startViewTransition(()=>{alert('callback should not be called')}))
</script>
This test passes if it does not crash.
7 changes: 5 additions & 2 deletions Source/WebCore/dom/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9862,16 +9862,19 @@ void Document::setHasViewTransitionPseudoElementTree(bool value)
m_hasViewTransitionPseudoElementTree = value;
}

Ref<ViewTransition> Document::startViewTransition(RefPtr<ViewTransitionUpdateCallback>&& updateCallback)
RefPtr<ViewTransition> Document::startViewTransition(RefPtr<ViewTransitionUpdateCallback>&& updateCallback)
{
if (!globalObject())
return nullptr;

Ref viewTransition = ViewTransition::create(*this, WTFMove(updateCallback));

if (RefPtr activeViewTransition = m_activeViewTransition)
activeViewTransition->skipViewTransition(Exception { ExceptionCode::AbortError, "Old view transition aborted by new view transition."_s });

setActiveViewTransition(WTFMove(viewTransition));
scheduleRenderingUpdate(RenderingUpdateStep::PerformPendingViewTransitions);
return *m_activeViewTransition;
return m_activeViewTransition;
}

void Document::performPendingViewTransitions()
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ class Document
void unobserveForContainIntrinsicSize(Element&);
void resetObservationSizeForContainIntrinsicSize(Element&);

Ref<ViewTransition> startViewTransition(RefPtr<ViewTransitionUpdateCallback>&& = nullptr);
RefPtr<ViewTransition> startViewTransition(RefPtr<ViewTransitionUpdateCallback>&& = nullptr);
ViewTransition* activeViewTransition() const;
void setActiveViewTransition(RefPtr<ViewTransition>&&);

Expand Down

0 comments on commit 256b846

Please sign in to comment.