js: Shorten Object.prototype.hasOwnProperty.call to Object.hasOwn.

https://github.com/tc39/proposal-accessible-object-hasownproperty

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-01-23 23:23:22 -08:00 committed by Tim Abbott
parent 4922632601
commit 0b03628324
9 changed files with 21 additions and 21 deletions

View File

@ -14,7 +14,7 @@ module.exports = {
[ [
"@babel/preset-env", "@babel/preset-env",
{ {
corejs: "3.6", corejs: "3.19",
loose: true, // Loose mode for…of loops are 5× faster in Firefox loose: true, // Loose mode for…of loops are 5× faster in Firefox
shippedProposals: true, shippedProposals: true,
useBuiltIns: "usage", useBuiltIns: "usage",

View File

@ -133,7 +133,7 @@ if (require.main === module) {
// First two args are just "node" and "mdiff.js" // First two args are just "node" and "mdiff.js"
const argv = require("minimist")(process.argv.slice(2)); const argv = require("minimist")(process.argv.slice(2));
if (Object.prototype.hasOwnProperty.call(argv, "help")) { if (Object.hasOwn(argv, "help")) {
console.log( console.log(
process.argv[0] + process.argv[0] +
" " + " " +

View File

@ -327,7 +327,7 @@ exports.with_field = function (obj, field, val, f) {
); );
} }
const had_val = Object.prototype.hasOwnProperty.call(obj, field); const had_val = Object.hasOwn(obj, field);
const old_val = obj[field]; const old_val = obj[field];
try { try {
obj[field] = val; obj[field] = val;

View File

@ -6,17 +6,17 @@ exports.user_settings = {};
exports.reset = () => { exports.reset = () => {
for (const field in exports.page_params) { for (const field in exports.page_params) {
if (Object.prototype.hasOwnProperty.call(exports.page_params, field)) { if (Object.hasOwn(exports.page_params, field)) {
delete exports.page_params[field]; delete exports.page_params[field];
} }
} }
for (const field in exports.user_settings) { for (const field in exports.user_settings) {
if (Object.prototype.hasOwnProperty.call(exports.user_settings, field)) { if (Object.hasOwn(exports.user_settings, field)) {
delete exports.user_settings[field]; delete exports.user_settings[field];
} }
} }
for (const field in exports.realm_user_settings_defaults) { for (const field in exports.realm_user_settings_defaults) {
if (Object.prototype.hasOwnProperty.call(exports.realm_user_settings_defaults, field)) { if (Object.hasOwn(exports.realm_user_settings_defaults, field)) {
delete exports.realm_user_settings_defaults[field]; delete exports.realm_user_settings_defaults[field];
} }
} }

View File

@ -54,7 +54,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {
const elsewhere_messages = []; const elsewhere_messages = [];
for (const elem of messages) { for (const elem of messages) {
if (Object.prototype.hasOwnProperty.call(data.messages, elem.id)) { if (Object.hasOwn(data.messages, elem.id)) {
util.set_match_data(elem, data.messages[elem.id]); util.set_match_data(elem, data.messages[elem.id]);
new_messages.push(elem); new_messages.push(elem);
} else { } else {

View File

@ -32,7 +32,7 @@ function make_person_highlighter(query) {
function match_criteria(operators, criteria) { function match_criteria(operators, criteria) {
const filter = new Filter(operators); const filter = new Filter(operators);
return criteria.some((cr) => { return criteria.some((cr) => {
if (Object.prototype.hasOwnProperty.call(cr, "operand")) { if (Object.hasOwn(cr, "operand")) {
return filter.has_operand(cr.operator, cr.operand); return filter.has_operand(cr.operator, cr.operand);
} }
return filter.has_operator(cr.operator); return filter.has_operator(cr.operator);

View File

@ -225,7 +225,7 @@ export function dispatch_normal_event(event) {
}; };
switch (event.op) { switch (event.op) {
case "update": case "update":
if (Object.prototype.hasOwnProperty.call(realm_settings, event.property)) { if (Object.hasOwn(realm_settings, event.property)) {
page_params["realm_" + event.property] = event.value; page_params["realm_" + event.property] = event.value;
realm_settings[event.property](); realm_settings[event.property]();
settings_org.sync_realm_settings(event.property); settings_org.sync_realm_settings(event.property);
@ -258,7 +258,7 @@ export function dispatch_normal_event(event) {
if (key === "allow_message_editing") { if (key === "allow_message_editing") {
message_edit.update_message_topic_editing_pencil(); message_edit.update_message_topic_editing_pencil();
} }
if (Object.prototype.hasOwnProperty.call(realm_settings, key)) { if (Object.hasOwn(realm_settings, key)) {
settings_org.sync_realm_settings(key); settings_org.sync_realm_settings(key);
} }
} }

View File

@ -30,7 +30,7 @@ export const update_person = function update(person) {
return; return;
} }
if (Object.prototype.hasOwnProperty.call(person, "new_email")) { if (Object.hasOwn(person, "new_email")) {
const user_id = person.user_id; const user_id = person.user_id;
const new_email = person.new_email; const new_email = person.new_email;
@ -44,7 +44,7 @@ export const update_person = function update(person) {
people.update_email(user_id, new_email); people.update_email(user_id, new_email);
} }
if (Object.prototype.hasOwnProperty.call(person, "delivery_email")) { if (Object.hasOwn(person, "delivery_email")) {
const delivery_email = person.delivery_email; const delivery_email = person.delivery_email;
if (people.is_my_user_id(person.user_id)) { if (people.is_my_user_id(person.user_id)) {
@ -54,7 +54,7 @@ export const update_person = function update(person) {
} }
} }
if (Object.prototype.hasOwnProperty.call(person, "full_name")) { if (Object.hasOwn(person, "full_name")) {
people.set_full_name(person_obj, person.full_name); people.set_full_name(person_obj, person.full_name);
settings_users.update_user_data(person.user_id, person); settings_users.update_user_data(person.user_id, person);
@ -67,7 +67,7 @@ export const update_person = function update(person) {
} }
} }
if (Object.prototype.hasOwnProperty.call(person, "role")) { if (Object.hasOwn(person, "role")) {
person_obj.role = person.role; person_obj.role = person.role;
person_obj.is_owner = person.role === settings_config.user_role_values.owner.code; person_obj.is_owner = person.role === settings_config.user_role_values.owner.code;
person_obj.is_admin = person_obj.is_admin =
@ -99,14 +99,14 @@ export const update_person = function update(person) {
} }
} }
if (Object.prototype.hasOwnProperty.call(person, "is_billing_admin")) { if (Object.hasOwn(person, "is_billing_admin")) {
person_obj.is_billing_admin = person.is_billing_admin; person_obj.is_billing_admin = person.is_billing_admin;
if (people.is_my_user_id(person.user_id)) { if (people.is_my_user_id(person.user_id)) {
page_params.is_billing_admin = person_obj.is_billing_admin; page_params.is_billing_admin = person_obj.is_billing_admin;
} }
} }
if (Object.prototype.hasOwnProperty.call(person, "avatar_url")) { if (Object.hasOwn(person, "avatar_url")) {
const url = person.avatar_url; const url = person.avatar_url;
person_obj.avatar_url = url; person_obj.avatar_url = url;
person_obj.avatar_version = person.avatar_version; person_obj.avatar_version = person.avatar_version;
@ -121,15 +121,15 @@ export const update_person = function update(person) {
message_live_update.update_avatar(person_obj.user_id, person.avatar_url); message_live_update.update_avatar(person_obj.user_id, person.avatar_url);
} }
if (Object.prototype.hasOwnProperty.call(person, "custom_profile_field")) { if (Object.hasOwn(person, "custom_profile_field")) {
people.set_custom_profile_field_data(person.user_id, person.custom_profile_field); people.set_custom_profile_field_data(person.user_id, person.custom_profile_field);
} }
if (Object.prototype.hasOwnProperty.call(person, "timezone")) { if (Object.hasOwn(person, "timezone")) {
person_obj.timezone = person.timezone; person_obj.timezone = person.timezone;
} }
if (Object.prototype.hasOwnProperty.call(person, "bot_owner_id")) { if (Object.hasOwn(person, "bot_owner_id")) {
person_obj.bot_owner_id = person.bot_owner_id; person_obj.bot_owner_id = person.bot_owner_id;
} }
}; };

View File

@ -76,7 +76,7 @@ const zulip_emoji = {
export function get_emoji_name(codepoint) { export function get_emoji_name(codepoint) {
// get_emoji_name('1f384') === 'holiday_tree' // get_emoji_name('1f384') === 'holiday_tree'
if (Object.prototype.hasOwnProperty.call(emoji_codes.codepoint_to_name, codepoint)) { if (Object.hasOwn(emoji_codes.codepoint_to_name, codepoint)) {
return emoji_codes.codepoint_to_name[codepoint]; return emoji_codes.codepoint_to_name[codepoint];
} }
return undefined; return undefined;
@ -84,7 +84,7 @@ export function get_emoji_name(codepoint) {
export function get_emoji_codepoint(emoji_name) { export function get_emoji_codepoint(emoji_name) {
// get_emoji_codepoint('avocado') === '1f951' // get_emoji_codepoint('avocado') === '1f951'
if (Object.prototype.hasOwnProperty.call(emoji_codes.name_to_codepoint, emoji_name)) { if (Object.hasOwn(emoji_codes.name_to_codepoint, emoji_name)) {
return emoji_codes.name_to_codepoint[emoji_name]; return emoji_codes.name_to_codepoint[emoji_name];
} }
return undefined; return undefined;