Title: [288452] trunk/Source/WebCore
Revision
288452
Author
[email protected]
Date
2022-01-24 10:41:11 -0800 (Mon, 24 Jan 2022)

Log Message

Pass the Document through bindings to KeyframeEffect::setKeyframes()
https://bugs.webkit.org/show_bug.cgi?id=235503

Reviewed by Sam Weinig.

We're making a similar change as part of bug 232086 for getKeyframes()
after a suggestion from Darin during review. Since the bindings code
can guarantee a Document for these bindings-exposed methods, we might
as well use it rather than obtain the Document through the global object.

* animation/KeyframeEffect.cpp:
(WebCore::processKeyframeLikeObject):
(WebCore::processIterableKeyframes):
(WebCore::processPropertyIndexedKeyframes):
(WebCore::KeyframeEffect::create):
(WebCore::KeyframeEffect::setBindingsKeyframes):
(WebCore::KeyframeEffect::setKeyframes):
(WebCore::KeyframeEffect::processKeyframes):
* animation/KeyframeEffect.h:
* animation/KeyframeEffect.idl:
* dom/Element.cpp:
(WebCore::Element::animate):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288451 => 288452)


--- trunk/Source/WebCore/ChangeLog	2022-01-24 17:44:12 UTC (rev 288451)
+++ trunk/Source/WebCore/ChangeLog	2022-01-24 18:41:11 UTC (rev 288452)
@@ -1,3 +1,28 @@
+2022-01-24  Antoine Quint  <[email protected]>
+
+        Pass the Document through bindings to KeyframeEffect::setKeyframes()
+        https://bugs.webkit.org/show_bug.cgi?id=235503
+
+        Reviewed by Sam Weinig.
+
+        We're making a similar change as part of bug 232086 for getKeyframes()
+        after a suggestion from Darin during review. Since the bindings code
+        can guarantee a Document for these bindings-exposed methods, we might
+        as well use it rather than obtain the Document through the global object.
+
+        * animation/KeyframeEffect.cpp:
+        (WebCore::processKeyframeLikeObject):
+        (WebCore::processIterableKeyframes):
+        (WebCore::processPropertyIndexedKeyframes):
+        (WebCore::KeyframeEffect::create):
+        (WebCore::KeyframeEffect::setBindingsKeyframes):
+        (WebCore::KeyframeEffect::setKeyframes):
+        (WebCore::KeyframeEffect::processKeyframes):
+        * animation/KeyframeEffect.h:
+        * animation/KeyframeEffect.idl:
+        * dom/Element.cpp:
+        (WebCore::Element::animate):
+
 2022-01-24  David Quesada  <[email protected]>
 
         Simplify accesses to SystemVersion.plist

Modified: trunk/Source/WebCore/animation/KeyframeEffect.cpp (288451 => 288452)


--- trunk/Source/WebCore/animation/KeyframeEffect.cpp	2022-01-24 17:44:12 UTC (rev 288451)
+++ trunk/Source/WebCore/animation/KeyframeEffect.cpp	2022-01-24 18:41:11 UTC (rev 288452)
@@ -169,7 +169,7 @@
     }
 }
 
-static inline ExceptionOr<KeyframeEffect::KeyframeLikeObject> processKeyframeLikeObject(JSGlobalObject& lexicalGlobalObject, Strong<JSObject>&& keyframesInput, bool allowLists)
+static inline ExceptionOr<KeyframeEffect::KeyframeLikeObject> processKeyframeLikeObject(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput, bool allowLists)
 {
     // https://drafts.csswg.org/web-animations-1/#process-a-keyframe-like-object
 
@@ -206,11 +206,8 @@
             baseProperties.offset = nullptr;
         baseProperties.easing = baseKeyframe.easing;
 
-        auto* scriptExecutionContext = jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject)->scriptExecutionContext();
-        if (is<Document>(scriptExecutionContext)) {
-            if (downcast<Document>(*scriptExecutionContext).settings().webAnimationsCompositeOperationsEnabled())
-                baseProperties.composite = baseKeyframe.composite;
-        }
+        if (document.settings().webAnimationsCompositeOperationsEnabled())
+            baseProperties.composite = baseKeyframe.composite;
     }
     RETURN_IF_EXCEPTION(scope, Exception { TypeError });
 
@@ -282,12 +279,8 @@
     return { WTFMove(keyframeOuput) };
 }
 
-static inline ExceptionOr<void> processIterableKeyframes(JSGlobalObject& lexicalGlobalObject, Strong<JSObject>&& keyframesInput, JSValue method, Vector<KeyframeEffect::ParsedKeyframe>& parsedKeyframes)
+static inline ExceptionOr<void> processIterableKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput, JSValue method, Vector<KeyframeEffect::ParsedKeyframe>& parsedKeyframes)
 {
-    auto* scriptExecutionContext = jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject)->scriptExecutionContext();
-    if (!is<Document>(scriptExecutionContext))
-        return { };
-    auto& document = downcast<Document>(*scriptExecutionContext);
     CSSParserContext parserContext(document);
 
     // 1. Let iter be GetIterator(object, method).
@@ -301,7 +294,7 @@
 
         // 7. Append to processed keyframes the result of running the procedure to process a keyframe-like object passing nextItem
         // as the keyframe input and with the allow lists flag set to false.
-        auto processKeyframeLikeObjectResult = processKeyframeLikeObject(lexicalGlobalObject, Strong<JSObject>(vm, nextValue.toObject(&lexicalGlobalObject)), false);
+        auto processKeyframeLikeObjectResult = processKeyframeLikeObject(lexicalGlobalObject, document, Strong<JSObject>(vm, nextValue.toObject(&lexicalGlobalObject)), false);
         if (processKeyframeLikeObjectResult.hasException())
             return processKeyframeLikeObjectResult.releaseException();
         auto keyframeLikeObject = processKeyframeLikeObjectResult.returnValue();
@@ -345,18 +338,14 @@
     return { };
 }
 
-static inline ExceptionOr<void> processPropertyIndexedKeyframes(JSGlobalObject& lexicalGlobalObject, Strong<JSObject>&& keyframesInput, Vector<KeyframeEffect::ParsedKeyframe>& parsedKeyframes, Vector<String>& unusedEasings)
+static inline ExceptionOr<void> processPropertyIndexedKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput, Vector<KeyframeEffect::ParsedKeyframe>& parsedKeyframes, Vector<String>& unusedEasings)
 {
     // 1. Let property-indexed keyframe be the result of running the procedure to process a keyframe-like object passing object as the keyframe input.
-    auto processKeyframeLikeObjectResult = processKeyframeLikeObject(lexicalGlobalObject, WTFMove(keyframesInput), true);
+    auto processKeyframeLikeObjectResult = processKeyframeLikeObject(lexicalGlobalObject, document, WTFMove(keyframesInput), true);
     if (processKeyframeLikeObjectResult.hasException())
         return processKeyframeLikeObjectResult.releaseException();
     auto propertyIndexedKeyframe = processKeyframeLikeObjectResult.returnValue();
 
-    auto* scriptExecutionContext = jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject)->scriptExecutionContext();
-    if (!is<Document>(scriptExecutionContext))
-        return { };
-    auto& document = downcast<Document>(*scriptExecutionContext);
     CSSParserContext parserContext(document);
 
     // 2. For each member, m, in property-indexed keyframe, perform the following steps:
@@ -494,7 +483,7 @@
     return { };
 }
 
-ExceptionOr<Ref<KeyframeEffect>> KeyframeEffect::create(JSGlobalObject& lexicalGlobalObject, Element* target, Strong<JSObject>&& keyframes, std::optional<std::variant<double, KeyframeEffectOptions>>&& options)
+ExceptionOr<Ref<KeyframeEffect>> KeyframeEffect::create(JSGlobalObject& lexicalGlobalObject, Document& document, Element* target, Strong<JSObject>&& keyframes, std::optional<std::variant<double, KeyframeEffectOptions>>&& options)
 {
     auto keyframeEffect = adoptRef(*new KeyframeEffect(target, PseudoId::None));
 
@@ -522,12 +511,9 @@
                 keyframeEffectOptions.direction
             };
 
-            auto* scriptExecutionContext = jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject)->scriptExecutionContext();
-            if (is<Document>(scriptExecutionContext)) {
-                if (downcast<Document>(*scriptExecutionContext).settings().webAnimationsCompositeOperationsEnabled()) {
-                    keyframeEffect->setComposite(keyframeEffectOptions.composite);
-                    keyframeEffect->setIterationComposite(keyframeEffectOptions.iterationComposite);
-                }
+            if (document.settings().webAnimationsCompositeOperationsEnabled()) {
+                keyframeEffect->setComposite(keyframeEffectOptions.composite);
+                keyframeEffect->setIterationComposite(keyframeEffectOptions.iterationComposite);
             }
         }
         auto updateTimingResult = keyframeEffect->updateTiming(timing);
@@ -535,7 +521,7 @@
             return updateTimingResult.releaseException();
     }
 
-    auto processKeyframesResult = keyframeEffect->processKeyframes(lexicalGlobalObject, WTFMove(keyframes));
+    auto processKeyframesResult = keyframeEffect->processKeyframes(lexicalGlobalObject, document, WTFMove(keyframes));
     if (processKeyframesResult.hasException())
         return processKeyframesResult.releaseException();
 
@@ -542,7 +528,7 @@
     return keyframeEffect;
 }
 
-ExceptionOr<Ref<KeyframeEffect>> KeyframeEffect::create(JSC::JSGlobalObject&, Ref<KeyframeEffect>&& source)
+ExceptionOr<Ref<KeyframeEffect>> KeyframeEffect::create(Ref<KeyframeEffect>&& source)
 {
     auto keyframeEffect = adoptRef(*new KeyframeEffect(nullptr, PseudoId::None));
     keyframeEffect->copyPropertiesFromSource(WTFMove(source));
@@ -806,17 +792,17 @@
     return result;
 }
 
-ExceptionOr<void> KeyframeEffect::setBindingsKeyframes(JSGlobalObject& lexicalGlobalObject, Strong<JSObject>&& keyframesInput)
+ExceptionOr<void> KeyframeEffect::setBindingsKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput)
 {
-    auto retVal = setKeyframes(lexicalGlobalObject, WTFMove(keyframesInput));
+    auto retVal = setKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput));
     if (!retVal.hasException() && is<CSSAnimation>(animation()))
         downcast<CSSAnimation>(*animation()).effectKeyframesWereSetUsingBindings();
     return retVal;
 }
 
-ExceptionOr<void> KeyframeEffect::setKeyframes(JSGlobalObject& lexicalGlobalObject, Strong<JSObject>&& keyframesInput)
+ExceptionOr<void> KeyframeEffect::setKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput)
 {
-    auto processKeyframesResult = processKeyframes(lexicalGlobalObject, WTFMove(keyframesInput));
+    auto processKeyframesResult = processKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput));
     if (!processKeyframesResult.hasException() && animation())
         animation()->effectTimingDidChange();
     return processKeyframesResult;
@@ -829,7 +815,7 @@
     invalidate();
 }
 
-ExceptionOr<void> KeyframeEffect::processKeyframes(JSGlobalObject& lexicalGlobalObject, Strong<JSObject>&& keyframesInput)
+ExceptionOr<void> KeyframeEffect::processKeyframes(JSGlobalObject& lexicalGlobalObject, Document& document, Strong<JSObject>&& keyframesInput)
 {
     // 1. If object is null, return an empty sequence of keyframes.
     if (!keyframesInput.get())
@@ -850,11 +836,11 @@
     // 5. Perform the steps corresponding to the first matching condition from below,
     Vector<String> unusedEasings;
     if (!method.isUndefined()) {
-        auto retVal = processIterableKeyframes(lexicalGlobalObject, WTFMove(keyframesInput), WTFMove(method), parsedKeyframes);
+        auto retVal = processIterableKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput), WTFMove(method), parsedKeyframes);
         if (retVal.hasException())
             return retVal.releaseException();
     } else {
-        auto retVal = processPropertyIndexedKeyframes(lexicalGlobalObject, WTFMove(keyframesInput), parsedKeyframes, unusedEasings);
+        auto retVal = processPropertyIndexedKeyframes(lexicalGlobalObject, document, WTFMove(keyframesInput), parsedKeyframes, unusedEasings);
         if (retVal.hasException())
             return retVal.releaseException();
     }

Modified: trunk/Source/WebCore/animation/KeyframeEffect.h (288451 => 288452)


--- trunk/Source/WebCore/animation/KeyframeEffect.h	2022-01-24 17:44:12 UTC (rev 288451)
+++ trunk/Source/WebCore/animation/KeyframeEffect.h	2022-01-24 18:41:11 UTC (rev 288452)
@@ -53,8 +53,8 @@
 class KeyframeEffect : public AnimationEffect
     , public CSSPropertyBlendingClient {
 public:
-    static ExceptionOr<Ref<KeyframeEffect>> create(JSC::JSGlobalObject&, Element*, JSC::Strong<JSC::JSObject>&&, std::optional<std::variant<double, KeyframeEffectOptions>>&&);
-    static ExceptionOr<Ref<KeyframeEffect>> create(JSC::JSGlobalObject&, Ref<KeyframeEffect>&&);
+    static ExceptionOr<Ref<KeyframeEffect>> create(JSC::JSGlobalObject&, Document&, Element*, JSC::Strong<JSC::JSObject>&&, std::optional<std::variant<double, KeyframeEffectOptions>>&&);
+    static ExceptionOr<Ref<KeyframeEffect>> create(Ref<KeyframeEffect>&&);
     static Ref<KeyframeEffect> create(const Element&, PseudoId);
     ~KeyframeEffect() { }
 
@@ -116,8 +116,8 @@
 
     Vector<JSC::Strong<JSC::JSObject>> getBindingsKeyframes(JSC::JSGlobalObject&, Document&);
     Vector<JSC::Strong<JSC::JSObject>> getKeyframes(JSC::JSGlobalObject&, Document&);
-    ExceptionOr<void> setBindingsKeyframes(JSC::JSGlobalObject&, JSC::Strong<JSC::JSObject>&&);
-    ExceptionOr<void> setKeyframes(JSC::JSGlobalObject&, JSC::Strong<JSC::JSObject>&&);
+    ExceptionOr<void> setBindingsKeyframes(JSC::JSGlobalObject&, Document&, JSC::Strong<JSC::JSObject>&&);
+    ExceptionOr<void> setKeyframes(JSC::JSGlobalObject&, Document&, JSC::Strong<JSC::JSObject>&&);
 
     IterationCompositeOperation iterationComposite() const { return m_iterationCompositeOperation; }
     void setIterationComposite(IterationCompositeOperation iterationCompositeOperation) { m_iterationCompositeOperation = iterationCompositeOperation; }
@@ -185,7 +185,7 @@
     void updateEffectStackMembership();
     void copyPropertiesFromSource(Ref<KeyframeEffect>&&);
     void didChangeTargetStyleable(const std::optional<const Styleable>&);
-    ExceptionOr<void> processKeyframes(JSC::JSGlobalObject&, JSC::Strong<JSC::JSObject>&&);
+    ExceptionOr<void> processKeyframes(JSC::JSGlobalObject&, Document&, JSC::Strong<JSC::JSObject>&&);
     void addPendingAcceleratedAction(AcceleratedAction);
     bool canBeAccelerated() const;
     bool isCompletelyAccelerated() const { return m_acceleratedPropertiesState == AcceleratedProperties::All; }

Modified: trunk/Source/WebCore/animation/KeyframeEffect.idl (288451 => 288452)


--- trunk/Source/WebCore/animation/KeyframeEffect.idl	2022-01-24 17:44:12 UTC (rev 288451)
+++ trunk/Source/WebCore/animation/KeyframeEffect.idl	2022-01-24 18:41:11 UTC (rev 288452)
@@ -29,8 +29,8 @@
     Exposed=Window,
     JSGenerateToNativeObject,
 ] interface KeyframeEffect : AnimationEffect {
-    [CallWith=GlobalObject] constructor(Element? target, object? keyframes, optional (unrestricted double or KeyframeEffectOptions) options);
-    [CallWith=GlobalObject] constructor(KeyframeEffect source);
+    [CallWith=GlobalObject&Document] constructor(Element? target, object? keyframes, optional (unrestricted double or KeyframeEffectOptions) options);
+    constructor(KeyframeEffect source);
 
     attribute Element? target;
     attribute CSSOMString? pseudoElement;

Modified: trunk/Source/WebCore/dom/Element.cpp (288451 => 288452)


--- trunk/Source/WebCore/dom/Element.cpp	2022-01-24 17:44:12 UTC (rev 288451)
+++ trunk/Source/WebCore/dom/Element.cpp	2022-01-24 18:41:11 UTC (rev 288452)
@@ -4695,7 +4695,7 @@
         keyframeEffectOptions = keyframeEffectOptionsVariant;
     }
 
-    auto keyframeEffectResult = KeyframeEffect::create(lexicalGlobalObject, this, WTFMove(keyframes), WTFMove(keyframeEffectOptions));
+    auto keyframeEffectResult = KeyframeEffect::create(lexicalGlobalObject, document(), this, WTFMove(keyframes), WTFMove(keyframeEffectOptions));
     if (keyframeEffectResult.hasException())
         return keyframeEffectResult.releaseException();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to