Commit 1e7c2506 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Prevent further uses of old downcast helpers

Type casting related functions like IsHTMLXXXXElement,
ToHTMLXXXXElement, and ToHTMLXXXXElementOrNull are being phased out in
favor of new downcast helpers in t_p/blink/renderer/platform/casting.h.
There is still a long run to fully remove old type casting mechanism,
but this CL aims at preventing new uses to take place.

Bug: 891908
Change-Id: I6a079b9524d2e94805528bdcf17baaa66fe091da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879628Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#710345}
parent 838863f5
...@@ -1074,6 +1074,33 @@ _BANNED_CPP_FUNCTIONS = ( ...@@ -1074,6 +1074,33 @@ _BANNED_CPP_FUNCTIONS = (
r'^third_party/blink/renderer/.*\.(cc|h)$', r'^third_party/blink/renderer/.*\.(cc|h)$',
), ),
), ),
(
r'/\bIsHTML.+Element\(\b',
(
'Function IsHTMLXXXXElement is deprecated. Instead, use downcast ',
' helpers IsA<HTMLXXXXElement> from ',
'//third_party/blink/renderer/platform/casting.h.'
),
False,
(
r'^third_party/blink/renderer/.*\.(cc|h)$',
),
),
(
r'/\bToHTML.+Element(|OrNull)\(\b',
(
'Function ToHTMLXXXXElement and ToHTMLXXXXElementOrNull are '
'deprecated. Instead, use downcast helpers To<HTMLXXXXElement> '
'and DynamicTo<HTMLXXXXElement> from ',
'//third_party/blink/renderer/platform/casting.h.'
'auto* html_xxxx_ele = To<HTMLXXXXElement>(n)'
'auto* html_xxxx_ele_or_null = DynamicTo<HTMLXXXXElement>(n)'
),
False,
(
r'^third_party/blink/renderer/.*\.(cc|h)$',
),
),
( (
r'/\bmojo::DataPipe\b', r'/\bmojo::DataPipe\b',
( (
......
...@@ -1932,6 +1932,38 @@ class BannedTypeCheckTest(unittest.TestCase): ...@@ -1932,6 +1932,38 @@ class BannedTypeCheckTest(unittest.TestCase):
self.assertTrue('some/cpp/problematic/file.c' in errors[0].message) self.assertTrue('some/cpp/problematic/file.c' in errors[0].message)
self.assertTrue('some/cpp/ok/file.cc' not in errors[0].message) self.assertTrue('some/cpp/ok/file.cc' not in errors[0].message)
def testBannedBlinkDowncastHelpers(self):
input_api = MockInputApi()
input_api.files = [
MockFile('some/cpp/problematic/file1.cc',
['DEFINE_TYPE_CASTS(ToType, FromType, from_argument,'
'PointerPredicate(), ReferencePredicate());']),
MockFile('some/cpp/problematic/file2.cc',
['bool is_test_ele = IsHTMLTestElement(n);']),
MockFile('some/cpp/problematic/file3.cc',
['auto* html_test_ele = ToHTMLTestElement(n);']),
MockFile('some/cpp/problematic/file4.cc',
['auto* html_test_ele_or_null = ToHTMLTestElementOrNull(n);']),
MockFile('some/cpp/ok/file1.cc',
['bool is_test_ele = IsA<HTMLTestElement>(n);']),
MockFile('some/cpp/ok/file2.cc',
['auto* html_test_ele = To<HTMLTestElement>(n);']),
MockFile('some/cpp/ok/file3.cc',
['auto* html_test_ele_or_null = ',
'DynamicTo<HTMLTestElement>(n);']),
]
# warnings are errors[0], errors are errors[1]
errors = PRESUBMIT._CheckNoBannedFunctions(input_api, MockOutputApi())
self.assertEqual(2, len(errors))
self.assertTrue('some/cpp/problematic/file1.cc' in errors[1].message)
self.assertTrue('some/cpp/problematic/file2.cc' in errors[0].message)
self.assertTrue('some/cpp/problematic/file3.cc' in errors[0].message)
self.assertTrue('some/cpp/problematic/file4.cc' in errors[0].message)
self.assertTrue('some/cpp/ok/file1.cc' not in errors[0].message)
self.assertTrue('some/cpp/ok/file2.cc' not in errors[0].message)
self.assertTrue('some/cpp/ok/file3.cc' not in errors[0].message)
def testBannedIosObjcFunctions(self): def testBannedIosObjcFunctions(self):
input_api = MockInputApi() input_api = MockInputApi()
input_api.files = [ input_api.files = [
......
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