WebUI: Use ESLint to disallow JSON.parse(JSON.stringify()) to clone.
When ESLint encounters this pattern, it will throw the following error "Don't use JSON.parse(JSON.stringify(...)) to clone objects. Use structuredClone() instead" Bug: 720034,1491559 Change-Id: I377639ec257640a5ff10e5f6258c6af87d60c260 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5005072 Reviewed-by: Mitsuru Oshima <oshima@chromium.org> Reviewed-by: Rebekah Potter <rbpotter@chromium.org> Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org> Cr-Commit-Position: refs/heads/main@{#1220531}
This commit is contained in:
@ -63,6 +63,10 @@ module.exports = {
|
||||
'message': 'Use ES modules or cr.define() instead',
|
||||
},
|
||||
],
|
||||
'no-restricted-syntax': ['error', {
|
||||
'selector': 'CallExpression[callee.object.name=JSON][callee.property.name=parse] > CallExpression[callee.object.name=JSON][callee.property.name=stringify]',
|
||||
'message': 'Don\'t use JSON.parse(JSON.stringify(...)) to clone objects. Use structuredClone() instead.',
|
||||
}],
|
||||
'no-throw-literal': 'error',
|
||||
'no-trailing-spaces': 'error',
|
||||
'no-var': 'error',
|
||||
|
2
third_party/lottie/lottie_worker.js
vendored
2
third_party/lottie/lottie_worker.js
vendored
@ -1638,6 +1638,7 @@ const lottiejs = (function(window) {
|
||||
comps[i].layers.__used = true;
|
||||
return comps[i].layers;
|
||||
}
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return JSON.parse(JSON.stringify(comps[i].layers));
|
||||
}
|
||||
i += 1;
|
||||
@ -4417,6 +4418,7 @@ const lottiejs = (function(window) {
|
||||
RepeaterModifier.prototype.cloneElements = function(elements) {
|
||||
let i;
|
||||
const len = elements.length;
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
const newElements = JSON.parse(JSON.stringify(elements));
|
||||
this.resetElements(newElements);
|
||||
return newElements;
|
||||
|
Reference in New Issue
Block a user