Use modern ES syntax rather than `.call` (#29368)

main-rebase-security-fix
Renaud Chaput 2024-02-27 16:42:05 +01:00 committed by GitHub
parent 6f7615ba86
commit 899eac1a92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 34 additions and 28 deletions

View File

@ -80,7 +80,7 @@ export default class MediaContainer extends PureComponent {
return ( return (
<IntlProvider> <IntlProvider>
<> <>
{[].map.call(components, (component, i) => { {Array.from(components).map((component, i) => {
const componentName = component.getAttribute('data-component'); const componentName = component.getAttribute('data-component');
const Component = MEDIA_COMPONENTS[componentName]; const Component = MEDIA_COMPONENTS[componentName];
const { media, card, poll, hashtag, ...props } = JSON.parse(component.getAttribute('data-props')); const { media, card, poll, hashtag, ...props } = JSON.parse(component.getAttribute('data-props'));

View File

@ -36,7 +36,7 @@ Object.keys(emojiIndex.emojis).forEach(key => {
let emoji = emojiIndex.emojis[key]; let emoji = emojiIndex.emojis[key];
// Emojis with skin tone modifiers are stored like this // Emojis with skin tone modifiers are stored like this
if (Object.prototype.hasOwnProperty.call(emoji, '1')) { if (Object.hasOwn(emoji, '1')) {
emoji = emoji['1']; emoji = emoji['1'];
} }
@ -88,7 +88,7 @@ Object.keys(emojiIndex.emojis).forEach(key => {
let emoji = emojiIndex.emojis[key]; let emoji = emojiIndex.emojis[key];
// Emojis with skin tone modifiers are stored like this // Emojis with skin tone modifiers are stored like this
if (Object.prototype.hasOwnProperty.call(emoji, '1')) { if (Object.hasOwn(emoji, '1')) {
emoji = emoji['1']; emoji = emoji['1'];
} }

View File

@ -135,19 +135,19 @@ function getData(emoji, skin, set) {
} }
} }
if (Object.prototype.hasOwnProperty.call(data.short_names, emoji)) { if (Object.hasOwn(data.short_names, emoji)) {
emoji = data.short_names[emoji]; emoji = data.short_names[emoji];
} }
if (Object.prototype.hasOwnProperty.call(data.emojis, emoji)) { if (Object.hasOwn(data.emojis, emoji)) {
emojiData = data.emojis[emoji]; emojiData = data.emojis[emoji];
} }
} else if (emoji.id) { } else if (emoji.id) {
if (Object.prototype.hasOwnProperty.call(data.short_names, emoji.id)) { if (Object.hasOwn(data.short_names, emoji.id)) {
emoji.id = data.short_names[emoji.id]; emoji.id = data.short_names[emoji.id];
} }
if (Object.prototype.hasOwnProperty.call(data.emojis, emoji.id)) { if (Object.hasOwn(data.emojis, emoji.id)) {
emojiData = data.emojis[emoji.id]; emojiData = data.emojis[emoji.id];
skin = skin || emoji.skin; skin = skin || emoji.skin;
} }
@ -216,7 +216,7 @@ function deepMerge(a, b) {
let originalValue = a[key], let originalValue = a[key],
value = originalValue; value = originalValue;
if (Object.prototype.hasOwnProperty.call(b, key)) { if (Object.hasOwn(b, key)) {
value = b[key]; value = b[key];
} }

View File

@ -46,7 +46,7 @@ const hideSelectAll = () => {
Rails.delegate(document, '#batch_checkbox_all', 'change', ({ target }) => { Rails.delegate(document, '#batch_checkbox_all', 'change', ({ target }) => {
const selectAllMatchingElement = document.querySelector('.batch-table__select-all'); const selectAllMatchingElement = document.querySelector('.batch-table__select-all');
[].forEach.call(document.querySelectorAll(batchCheckboxClassName), (content) => { document.querySelectorAll(batchCheckboxClassName).forEach((content) => {
content.checked = target.checked; content.checked = target.checked;
}); });
@ -81,8 +81,11 @@ Rails.delegate(document, batchCheckboxClassName, 'change', () => {
const selectAllMatchingElement = document.querySelector('.batch-table__select-all'); const selectAllMatchingElement = document.querySelector('.batch-table__select-all');
if (checkAllElement) { if (checkAllElement) {
checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked); const allCheckboxes = Array.from(
checkAllElement.indeterminate = !checkAllElement.checked && [].some.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked); document.querySelectorAll(batchCheckboxClassName)
);
checkAllElement.checked = allCheckboxes.every((content) => content.checked);
checkAllElement.indeterminate = !checkAllElement.checked && allCheckboxes.some((content) => content.checked);
if (selectAllMatchingElement) { if (selectAllMatchingElement) {
if (checkAllElement.checked) { if (checkAllElement.checked) {
@ -133,11 +136,11 @@ Rails.delegate(document, '#form_admin_settings_enable_bootstrap_timeline_account
const onChangeRegistrationMode = (target) => { const onChangeRegistrationMode = (target) => {
const enabled = target.value === 'approved'; const enabled = target.value === 'approved';
[].forEach.call(document.querySelectorAll('.form_admin_settings_registrations_mode .warning-hint'), (warning_hint) => { document.querySelectorAll('.form_admin_settings_registrations_mode .warning-hint').forEach((warning_hint) => {
warning_hint.style.display = target.value === 'open' ? 'inline' : 'none'; warning_hint.style.display = target.value === 'open' ? 'inline' : 'none';
}); });
[].forEach.call(document.querySelectorAll('#form_admin_settings_require_invite_text'), (input) => { document.querySelectorAll('#form_admin_settings_require_invite_text').forEach((input) => {
input.disabled = !enabled; input.disabled = !enabled;
if (enabled) { if (enabled) {
let element = input; let element = input;
@ -183,8 +186,9 @@ ready(() => {
const checkAllElement = document.querySelector('#batch_checkbox_all'); const checkAllElement = document.querySelector('#batch_checkbox_all');
if (checkAllElement) { if (checkAllElement) {
checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked); const allCheckboxes = Array.from(document.querySelectorAll(batchCheckboxClassName));
checkAllElement.indeterminate = !checkAllElement.checked && [].some.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked); checkAllElement.checked = allCheckboxes.every( (content) => content.checked);
checkAllElement.indeterminate = !checkAllElement.checked && allCheckboxes.some((content) => content.checked);
} }
document.querySelector('a#add-instance-button')?.addEventListener('click', (e) => { document.querySelector('a#add-instance-button')?.addEventListener('click', (e) => {
@ -197,7 +201,7 @@ ready(() => {
} }
}); });
[].forEach.call(document.querySelectorAll('input[type="datetime-local"]'), element => { document.querySelectorAll('input[type="datetime-local"]').forEach(element => {
if (element.value) { if (element.value) {
element.value = convertUTCDateTimeToLocal(element.value); element.value = convertUTCDateTimeToLocal(element.value);
} }
@ -207,7 +211,7 @@ ready(() => {
}); });
Rails.delegate(document, 'form', 'submit', ({ target }) => { Rails.delegate(document, 'form', 'submit', ({ target }) => {
[].forEach.call(target.querySelectorAll('input[type="datetime-local"]'), element => { target.querySelectorAll('input[type="datetime-local"]').forEach(element => {
if (element.value && element.validity.valid) { if (element.value && element.validity.valid) {
element.value = convertLocalDatetimeToUTC(element.value); element.value = convertLocalDatetimeToUTC(element.value);
} }
@ -219,7 +223,7 @@ ready(() => {
setAnnouncementEndsAttributes(announcementStartsAt); setAnnouncementEndsAttributes(announcementStartsAt);
} }
[].forEach.call(document.querySelectorAll('[data-admin-component]'), element => { document.querySelectorAll('[data-admin-component]').forEach(element => {
const componentName = element.getAttribute('data-admin-component'); const componentName = element.getAttribute('data-admin-component');
const componentProps = JSON.parse(element.getAttribute('data-props')); const componentProps = JSON.parse(element.getAttribute('data-props'));

View File

@ -73,11 +73,11 @@ function loaded() {
return messageFormat.format(values); return messageFormat.format(values);
}; };
[].forEach.call(document.querySelectorAll('.emojify'), (content) => { document.querySelectorAll('.emojify').forEach((content) => {
content.innerHTML = emojify(content.innerHTML); content.innerHTML = emojify(content.innerHTML);
}); });
[].forEach.call(document.querySelectorAll('time.formatted'), (content) => { document.querySelectorAll('time.formatted').forEach((content) => {
const datetime = new Date(content.getAttribute('datetime')); const datetime = new Date(content.getAttribute('datetime'));
const formattedDate = dateTimeFormat.format(datetime); const formattedDate = dateTimeFormat.format(datetime);
@ -94,7 +94,7 @@ function loaded() {
}; };
const todayFormat = new IntlMessageFormat(localeData['relative_format.today'] || 'Today at {time}', locale); const todayFormat = new IntlMessageFormat(localeData['relative_format.today'] || 'Today at {time}', locale);
[].forEach.call(document.querySelectorAll('time.relative-formatted'), (content) => { document.querySelectorAll('time.relative-formatted').forEach((content) => {
const datetime = new Date(content.getAttribute('datetime')); const datetime = new Date(content.getAttribute('datetime'));
let formattedContent; let formattedContent;
@ -111,7 +111,7 @@ function loaded() {
content.textContent = formattedContent; content.textContent = formattedContent;
}); });
[].forEach.call(document.querySelectorAll('time.time-ago'), (content) => { document.querySelectorAll('time.time-ago').forEach((content) => {
const datetime = new Date(content.getAttribute('datetime')); const datetime = new Date(content.getAttribute('datetime'));
const now = new Date(); const now = new Date();
@ -128,8 +128,8 @@ function loaded() {
if (reactComponents.length > 0) { if (reactComponents.length > 0) {
import(/* webpackChunkName: "containers/media_container" */ '../mastodon/containers/media_container') import(/* webpackChunkName: "containers/media_container" */ '../mastodon/containers/media_container')
.then(({ default: MediaContainer }) => { .then(({ default: MediaContainer }) => {
[].forEach.call(reactComponents, (component) => { reactComponents.forEach((component) => {
[].forEach.call(component.children, (child) => { Array.from(component.children).forEach((child) => {
component.removeChild(child); component.removeChild(child);
}); });
}); });
@ -185,7 +185,7 @@ function loaded() {
return false; return false;
}); });
[].forEach.call(document.querySelectorAll('.status__content__spoiler-link'), (spoilerLink) => { document.querySelectorAll('.status__content__spoiler-link').forEach((spoilerLink) => {
const statusEl = spoilerLink.parentNode.parentNode; const statusEl = spoilerLink.parentNode.parentNode;
const message = (statusEl.dataset.spoiler === 'expanded') ? (localeData['status.show_less'] || 'Show less') : (localeData['status.show_more'] || 'Show more'); const message = (statusEl.dataset.spoiler === 'expanded') ? (localeData['status.show_less'] || 'Show less') : (localeData['status.show_more'] || 'Show more');
spoilerLink.textContent = (new IntlMessageFormat(message, locale)).format(); spoilerLink.textContent = (new IntlMessageFormat(message, locale)).format();

View File

@ -31,6 +31,8 @@
var iframe = iframes.get(data.id); var iframe = iframes.get(data.id);
if(!iframe) return;
if ('source' in e && iframe.contentWindow !== e.source) { if ('source' in e && iframe.contentWindow !== e.source) {
return; return;
} }
@ -38,7 +40,7 @@
iframe.height = data.height; iframe.height = data.height;
}); });
[].forEach.call(document.querySelectorAll('iframe.mastodon-embed'), function (iframe) { document.querySelectorAll('iframe.mastodon-embed').forEach(iframe => {
// select unique id for each iframe // select unique id for each iframe
var id = 0, failCount = 0, idBuffer = new Uint32Array(1); var id = 0, failCount = 0, idBuffer = new Uint32Array(1);
while (id === 0 || iframes.has(id)) { while (id === 0 || iframes.has(id)) {

View File

@ -192,7 +192,7 @@ const pgConfigFromEnv = (env) => {
if (!baseConfig.password && env.DB_PASS) { if (!baseConfig.password && env.DB_PASS) {
baseConfig.password = env.DB_PASS; baseConfig.password = env.DB_PASS;
} }
} else if (Object.hasOwnProperty.call(pgConfigs, environment)) { } else if (Object.hasOwn(pgConfigs, environment)) {
baseConfig = pgConfigs[environment]; baseConfig = pgConfigs[environment];
if (env.DB_SSLMODE) { if (env.DB_SSLMODE) {
@ -912,7 +912,7 @@ const startServer = async () => {
// If the payload already contains the `filtered` property, it means // If the payload already contains the `filtered` property, it means
// that filtering has been applied on the ruby on rails side, as // that filtering has been applied on the ruby on rails side, as
// such, we don't need to construct or apply the filters in streaming: // such, we don't need to construct or apply the filters in streaming:
if (Object.prototype.hasOwnProperty.call(payload, "filtered")) { if (Object.hasOwn(payload, "filtered")) {
transmit(event, payload); transmit(event, payload);
return; return;
} }