Commit 7b493a4d authored by dpapad's avatar dpapad Committed by Commit Bot

Use ESLint to disallow __defineGetter__, __defineSetter__ and friends.

Previously these checks were customly implemented in PRESUBMIT.py

Bug: 720034,425829
Change-Id: I04a11f680ace0a6b7d250f4116562ce3710eb27a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1670274
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671504}
parent dce1ba17
...@@ -28,6 +28,22 @@ module.exports = { ...@@ -28,6 +28,22 @@ module.exports = {
'from chrome://resources/js/util.js instead of ' + 'from chrome://resources/js/util.js instead of ' +
'document.getElementById(\'id\')', 'document.getElementById(\'id\')',
}, },
{
'property': '__lookupGetter__',
'message': 'Use Object.getOwnPropertyDescriptor',
},
{
'property': '__lookupSetter__',
'message': 'Use Object.getOwnPropertyDescriptor',
},
{
'property': '__defineGetter__',
'message': 'Use Object.defineProperty',
},
{
'property': '__defineSetter__',
'message': 'Use Object.defineProperty',
},
], ],
'semi': ['error', 'always'], 'semi': ['error', 'always'],
......
...@@ -3332,33 +3332,6 @@ def _CheckNoDeprecatedCss(input_api, output_api): ...@@ -3332,33 +3332,6 @@ def _CheckNoDeprecatedCss(input_api, output_api):
return results return results
_DEPRECATED_JS = [
( "__lookupGetter__", "Object.getOwnPropertyDescriptor" ),
( "__defineGetter__", "Object.defineProperty" ),
( "__lookupSetter__", "Object.getOwnPropertyDescriptor" ),
( "__defineSetter__", "Object.defineProperty" ),
]
# TODO: add unit tests
def _CheckNoDeprecatedJs(input_api, output_api):
"""Make sure that we don't use deprecated JS in Chrome code."""
results = []
file_inclusion_pattern = [r".+\.js$"] # TODO(dbeam): .html?
black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS +
input_api.DEFAULT_BLACK_LIST)
file_filter = lambda f: input_api.FilterSourceFile(
f, white_list=file_inclusion_pattern, black_list=black_list)
for fpath in input_api.AffectedFiles(file_filter=file_filter):
for lnum, line in fpath.ChangedContents():
for (deprecated, replacement) in _DEPRECATED_JS:
if deprecated in line:
results.append(output_api.PresubmitError(
"%s:%d: Use of deprecated JS %s, use %s instead" %
(fpath.LocalPath(), lnum, deprecated, replacement)))
return results
def _CheckForRelativeIncludes(input_api, output_api): def _CheckForRelativeIncludes(input_api, output_api):
bad_files = {} bad_files = {}
for f in input_api.AffectedFiles(include_deletes=False): for f in input_api.AffectedFiles(include_deletes=False):
...@@ -3789,7 +3762,6 @@ def _CommonChecks(input_api, output_api): ...@@ -3789,7 +3762,6 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckForAnonymousVariables(input_api, output_api)) results.extend(_CheckForAnonymousVariables(input_api, output_api))
results.extend(_CheckUserActionUpdate(input_api, output_api)) results.extend(_CheckUserActionUpdate(input_api, output_api))
results.extend(_CheckNoDeprecatedCss(input_api, output_api)) results.extend(_CheckNoDeprecatedCss(input_api, output_api))
results.extend(_CheckNoDeprecatedJs(input_api, output_api))
results.extend(_CheckParseErrors(input_api, output_api)) results.extend(_CheckParseErrors(input_api, output_api))
results.extend(_CheckForIPCRules(input_api, output_api)) results.extend(_CheckForIPCRules(input_api, output_api))
results.extend(_CheckForLongPathnames(input_api, output_api)) results.extend(_CheckForLongPathnames(input_api, output_api))
......
...@@ -391,6 +391,7 @@ cr.define('wallpapers', function() { ...@@ -391,6 +391,7 @@ cr.define('wallpapers', function() {
} }
} }
// eslint-disable-next-line no-restricted-properties
var parentSetter = cr.ui.Grid.prototype.__lookupSetter__('dataModel'); var parentSetter = cr.ui.Grid.prototype.__lookupSetter__('dataModel');
parentSetter.call(this, dataModel); parentSetter.call(this, dataModel);
}, },
......
...@@ -317,6 +317,7 @@ cr.define('ntp', function() { ...@@ -317,6 +317,7 @@ cr.define('ntp', function() {
// TODO(crbug.com/425829): Remove above suppression once we no longer use // TODO(crbug.com/425829): Remove above suppression once we no longer use
// deprecated function defineGetter. // deprecated function defineGetter.
// eslint-disable-next-line no-restricted-properties
this.appContents_.__defineGetter__('contextMenu', function() { this.appContents_.__defineGetter__('contextMenu', function() {
return self.contextMenu; return self.contextMenu;
}); });
......
...@@ -215,11 +215,15 @@ var cr = cr || function(global) { ...@@ -215,11 +215,15 @@ var cr = cr || function(global) {
// TODO(crbug.com/425829): Remove above suppression once we no longer use // TODO(crbug.com/425829): Remove above suppression once we no longer use
// deprecated functions lookupGetter, defineGetter, lookupSetter, and // deprecated functions lookupGetter, defineGetter, lookupSetter, and
// defineSetter. // defineSetter.
// eslint-disable-next-line no-restricted-properties
if (!obj.__lookupGetter__(name)) { if (!obj.__lookupGetter__(name)) {
// eslint-disable-next-line no-restricted-properties
obj.__defineGetter__(name, getGetter(name, kind)); obj.__defineGetter__(name, getGetter(name, kind));
} }
// eslint-disable-next-line no-restricted-properties
if (!obj.__lookupSetter__(name)) { if (!obj.__lookupSetter__(name)) {
// eslint-disable-next-line no-restricted-properties
obj.__defineSetter__(name, getSetter(name, kind, opt_setHook)); obj.__defineSetter__(name, getSetter(name, kind, opt_setHook));
} }
} }
......
...@@ -236,9 +236,11 @@ cr.define('cr.ui', function() { ...@@ -236,9 +236,11 @@ cr.define('cr.ui', function() {
elementOrClass.prototype : elementOrClass.prototype :
elementOrClass; elementOrClass;
// eslint-disable-next-line no-restricted-properties
target.__defineGetter__('contextMenu', function() { target.__defineGetter__('contextMenu', function() {
return this.contextMenu_; return this.contextMenu_;
}); });
// eslint-disable-next-line no-restricted-properties
target.__defineSetter__('contextMenu', function(menu) { target.__defineSetter__('contextMenu', function(menu) {
const oldContextMenu = this.contextMenu; const oldContextMenu = this.contextMenu;
......
...@@ -118,6 +118,7 @@ cr.define('cr.ui.overlay', function() { ...@@ -118,6 +118,7 @@ cr.define('cr.ui.overlay', function() {
// TODO(crbug.com/425829): Remove above suppression once we no longer use // TODO(crbug.com/425829): Remove above suppression once we no longer use
// deprecated functions defineSetter, and defineGetter. // deprecated functions defineSetter, and defineGetter.
// Remove the 'pulse' animation any time the overlay is hidden or shown. // Remove the 'pulse' animation any time the overlay is hidden or shown.
// eslint-disable-next-line no-restricted-properties
overlay.__defineSetter__('hidden', function(value) { overlay.__defineSetter__('hidden', function(value) {
this.classList.remove('pulse'); this.classList.remove('pulse');
if (value) { if (value) {
...@@ -126,6 +127,7 @@ cr.define('cr.ui.overlay', function() { ...@@ -126,6 +127,7 @@ cr.define('cr.ui.overlay', function() {
this.removeAttribute('hidden'); this.removeAttribute('hidden');
} }
}); });
// eslint-disable-next-line no-restricted-properties
overlay.__defineGetter__('hidden', function() { overlay.__defineGetter__('hidden', function() {
return this.hasAttribute('hidden'); return this.hasAttribute('hidden');
}); });
......
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