-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement input validation for CSSRGB constructor and setters
https://bugs.webkit.org/show_bug.cgi?id=246972 Reviewed by Antti Koivisto. Implement input validation for CSSRGB constructor and setters: - https://drafts.css-houdini.org/css-typed-om-1/#dom-cssrgb-cssrgb-r-g-b-optional-alpha - https://drafts.css-houdini.org/css-typed-om-1/#rectify-a-csscolorrgbcomp - https://drafts.css-houdini.org/css-typed-om-1/#rectify-a-csscolorpercent * LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/cssRGB-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/cssRGB.html: Made some fixes to the test, which I will export to WPT: - Expect a Syntax error instead of a TypeError, as per the specification. - The loop for iterating over invalid test cases for the setters was wrong. As a result, the setters kept getting called with the string "undefined" instead of the actual test value. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/css/typedom/color/CSSColorValue.cpp: Added. (WebCore::CSSColorValue::colorSpace): (WebCore::CSSColorValue::to): (WebCore::CSSColorValue::parse): (WebCore::CSSColorValue::rectifyCSSColorPercent): (WebCore::CSSColorValue::toCSSColorPercent): * Source/WebCore/css/typedom/color/CSSColorValue.h: (WebCore::CSSColorValue::colorSpace): Deleted. (WebCore::CSSColorValue::to): Deleted. (WebCore::CSSColorValue::parse): Deleted. * Source/WebCore/css/typedom/color/CSSRGB.cpp: (WebCore::toCSSColorRGBComp): (WebCore::CSSRGB::create): (WebCore::CSSRGB::CSSRGB): (WebCore::CSSRGB::r const): (WebCore::CSSRGB::setR): (WebCore::CSSRGB::g const): (WebCore::CSSRGB::setG): (WebCore::CSSRGB::b const): (WebCore::CSSRGB::setB): (WebCore::CSSRGB::alpha const): (WebCore::CSSRGB::setAlpha): (WebCore::CSSRGB::rectifyCSSColorRGBComp): * Source/WebCore/css/typedom/color/CSSRGB.h: (WebCore::CSSRGB::create): Deleted. (WebCore::CSSRGB::r const): Deleted. (WebCore::CSSRGB::setR): Deleted. (WebCore::CSSRGB::g const): Deleted. (WebCore::CSSRGB::setG): Deleted. (WebCore::CSSRGB::b const): Deleted. (WebCore::CSSRGB::setB): Deleted. (WebCore::CSSRGB::alpha const): Deleted. (WebCore::CSSRGB::setAlpha): Deleted. Canonical link: https://commits.webkit.org/256024@main
- Loading branch information
Showing
8 changed files
with
258 additions
and
63 deletions.
There are no files selected for viewing
56 changes: 28 additions & 28 deletions
56
...mported/w3c/web-platform-tests/css/css-typed-om/stylevalue-subclasses/cssRGB-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "CSSColorValue.h" | ||
|
||
#include "CSSKeywordValue.h" | ||
#include "CSSUnitValue.h" | ||
#include "CSSUnits.h" | ||
#include "ExceptionOr.h" | ||
|
||
namespace WebCore { | ||
|
||
RefPtr<CSSKeywordValue> CSSColorValue::colorSpace() | ||
{ | ||
// FIXME: implement this. | ||
return nullptr; | ||
} | ||
|
||
RefPtr<CSSColorValue> CSSColorValue::to(CSSKeywordish) | ||
{ | ||
// FIXME: implement this. | ||
return nullptr; | ||
} | ||
|
||
std::variant<RefPtr<CSSColorValue>, RefPtr<CSSStyleValue>> CSSColorValue::parse(const String&) | ||
{ | ||
// FIXME: implement this. | ||
return RefPtr<CSSColorValue> { nullptr }; | ||
} | ||
|
||
// https://drafts.css-houdini.org/css-typed-om-1/#rectify-a-csscolorpercent | ||
ExceptionOr<RectifiedCSSColorPercent> CSSColorValue::rectifyCSSColorPercent(CSSColorPercent&& colorPercent) | ||
{ | ||
return switchOn(WTFMove(colorPercent), [](double value) -> ExceptionOr<RectifiedCSSColorPercent> { | ||
return { RefPtr<CSSNumericValue> { CSSUnitValue::create(value * 100, CSSUnitType::CSS_PERCENTAGE) } }; | ||
}, [](RefPtr<CSSNumericValue>&& numericValue) -> ExceptionOr<RectifiedCSSColorPercent> { | ||
if (numericValue->type().matches<CSSNumericBaseType::Percent>()) | ||
return { WTFMove(numericValue) }; | ||
return Exception { SyntaxError, "Invalid CSSColorPercent"_s }; | ||
}, [](String&& string) -> ExceptionOr<RectifiedCSSColorPercent> { | ||
return { RefPtr<CSSKeywordValue> { CSSKeywordValue::rectifyKeywordish(WTFMove(string)) } }; | ||
}, [](RefPtr<CSSKeywordValue>&& keywordValue) -> ExceptionOr<RectifiedCSSColorPercent> { | ||
if (equalIgnoringASCIICase(keywordValue->value(), "none"_s)) | ||
return { WTFMove(keywordValue) }; | ||
return Exception { SyntaxError, "Invalid CSSColorPercent"_s }; | ||
}); | ||
} | ||
|
||
CSSColorPercent CSSColorValue::toCSSColorPercent(const RectifiedCSSColorPercent& component) | ||
{ | ||
return switchOn(component, [](const RefPtr<CSSKeywordValue>& keywordValue) -> CSSColorPercent { | ||
return keywordValue; | ||
}, [](const RefPtr<CSSNumericValue>& numericValue) -> CSSColorPercent { | ||
return numericValue; | ||
}); | ||
} | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.