Skip to content
Permalink
Browse files

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: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Dan Beam <dbeam@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671504}
  • Loading branch information
freshp86 authored and Commit Bot committed Jun 22, 2019
1 parent dce1ba1 commit 7b493a4d37fc1e76c9837d7baaa0e8b911ea4950
@@ -28,6 +28,22 @@ module.exports = {
'from chrome://resources/js/util.js instead of ' +
'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'],

@@ -3332,33 +3332,6 @@ def _CheckNoDeprecatedCss(input_api, output_api):
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):
bad_files = {}
for f in input_api.AffectedFiles(include_deletes=False):
@@ -3789,7 +3762,6 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckForAnonymousVariables(input_api, output_api))
results.extend(_CheckUserActionUpdate(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(_CheckForIPCRules(input_api, output_api))
results.extend(_CheckForLongPathnames(input_api, output_api))
@@ -391,6 +391,7 @@ cr.define('wallpapers', function() {
}
}

// eslint-disable-next-line no-restricted-properties
var parentSetter = cr.ui.Grid.prototype.__lookupSetter__('dataModel');
parentSetter.call(this, dataModel);
},
@@ -317,6 +317,7 @@ cr.define('ntp', function() {

// TODO(crbug.com/425829): Remove above suppression once we no longer use
// deprecated function defineGetter.
// eslint-disable-next-line no-restricted-properties
this.appContents_.__defineGetter__('contextMenu', function() {
return self.contextMenu;
});
@@ -215,11 +215,15 @@ var cr = cr || function(global) {
// TODO(crbug.com/425829): Remove above suppression once we no longer use
// deprecated functions lookupGetter, defineGetter, lookupSetter, and
// defineSetter.
// eslint-disable-next-line no-restricted-properties
if (!obj.__lookupGetter__(name)) {
// eslint-disable-next-line no-restricted-properties
obj.__defineGetter__(name, getGetter(name, kind));
}

// eslint-disable-next-line no-restricted-properties
if (!obj.__lookupSetter__(name)) {
// eslint-disable-next-line no-restricted-properties
obj.__defineSetter__(name, getSetter(name, kind, opt_setHook));
}
}
@@ -236,9 +236,11 @@ cr.define('cr.ui', function() {
elementOrClass.prototype :
elementOrClass;

// eslint-disable-next-line no-restricted-properties
target.__defineGetter__('contextMenu', function() {
return this.contextMenu_;
});
// eslint-disable-next-line no-restricted-properties
target.__defineSetter__('contextMenu', function(menu) {
const oldContextMenu = this.contextMenu;

@@ -118,6 +118,7 @@ cr.define('cr.ui.overlay', function() {
// TODO(crbug.com/425829): Remove above suppression once we no longer use
// deprecated functions defineSetter, and defineGetter.
// Remove the 'pulse' animation any time the overlay is hidden or shown.
// eslint-disable-next-line no-restricted-properties
overlay.__defineSetter__('hidden', function(value) {
this.classList.remove('pulse');
if (value) {
@@ -126,6 +127,7 @@ cr.define('cr.ui.overlay', function() {
this.removeAttribute('hidden');
}
});
// eslint-disable-next-line no-restricted-properties
overlay.__defineGetter__('hidden', function() {
return this.hasAttribute('hidden');
});

0 comments on commit 7b493a4

Please sign in to comment.
You can’t perform that action at this time.