Commit cc4fa433 authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

Web Animations: Make AnimationPlaybackEvent's members null by default

Whilst the code did correctly check whether the members of
AnimationPlaybackEventInit were null, the AnimationPlaybackEvent
constructor was setting them to 0.0 as a default value, which is
incorrect via the spec:

https://drafts.csswg.org/web-animations-1/#the-animationplaybackevent-interface

This CL also converts the class members to use WTF::Optional to
clearly distinguish between them being set and not set.

Bug: 827572
Change-Id: I471666a022963dd19f8a74eaebafeeebf4e96c66
Reviewed-on: https://chromium-review.googlesource.com/988339Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Reviewed-by: default avatardsinclair <dsinclair@chromium.org>
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547715}
parent f5725087
This is a testharness.js-based test.
FAIL Event created without an event parameter has null time values assert_equals: expected (object) null but got (number) 0
PASS Created event reflects times specified in constructor
Harness: the test ran to completion.
......@@ -16,7 +16,7 @@ AnimationPlaybackEvent::AnimationPlaybackEvent(const AtomicString& type,
AnimationPlaybackEvent::AnimationPlaybackEvent(
const AtomicString& type,
const AnimationPlaybackEventInit& initializer)
: Event(type, initializer), current_time_(0.0), timeline_time_(0.0) {
: Event(type, initializer) {
if (initializer.hasCurrentTime())
current_time_ = initializer.currentTime();
if (initializer.hasTimelineTime())
......@@ -26,23 +26,13 @@ AnimationPlaybackEvent::AnimationPlaybackEvent(
AnimationPlaybackEvent::~AnimationPlaybackEvent() = default;
double AnimationPlaybackEvent::currentTime(bool& is_null) const {
double result = currentTime();
is_null = std::isnan(result);
return result;
}
double AnimationPlaybackEvent::currentTime() const {
return current_time_;
is_null = !current_time_.has_value();
return current_time_.value_or(0);
}
double AnimationPlaybackEvent::timelineTime(bool& is_null) const {
double result = timelineTime();
is_null = std::isnan(result);
return result;
}
double AnimationPlaybackEvent::timelineTime() const {
return timeline_time_;
is_null = !timeline_time_.has_value();
return timeline_time_.value_or(0);
}
const AtomicString& AnimationPlaybackEvent::InterfaceName() const {
......
......@@ -7,6 +7,7 @@
#include "core/dom/events/Event.h"
#include "core/events/AnimationPlaybackEventInit.h"
#include "platform/wtf/Optional.h"
namespace blink {
......@@ -28,9 +29,7 @@ class AnimationPlaybackEvent final : public Event {
~AnimationPlaybackEvent() override;
double currentTime(bool& is_null) const;
double currentTime() const;
double timelineTime(bool& is_null) const;
double timelineTime() const;
const AtomicString& InterfaceName() const override;
......@@ -43,8 +42,8 @@ class AnimationPlaybackEvent final : public Event {
AnimationPlaybackEvent(const AtomicString&,
const AnimationPlaybackEventInit&);
double current_time_;
double timeline_time_;
WTF::Optional<double> current_time_;
WTF::Optional<double> timeline_time_;
};
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment