Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Shorten Object.prototype.hasOwnProperty.call to Object.hasOwn.
Anders Kaseorg0b03628324f0
diff --git a/babel.config.js b/babel.config.jsindex bf418f3dddc..52978e86fc4 100644--- a/babel.config.js+++ b/babel.config.js@@ -14,7 +14,7 @@ module.exports = {["@babel/preset-env",{- corejs: "3.6",+ corejs: "3.19",loose: true, // Loose mode for…of loops are 5× faster in FirefoxshippedProposals: true,useBuiltIns: "usage",diff --git a/frontend_tests/zjsunit/mdiff.js b/frontend_tests/zjsunit/mdiff.jsindex 54e469577f7..a588a0cd22b 100644--- a/frontend_tests/zjsunit/mdiff.js+++ b/frontend_tests/zjsunit/mdiff.js@@ -133,7 +133,7 @@ if (require.main === module) {// First two args are just "node" and "mdiff.js"const argv = require("minimist")(process.argv.slice(2));- if (Object.prototype.hasOwnProperty.call(argv, "help")) {+ if (Object.hasOwn(argv, "help")) {console.log(process.argv[0] +" " +diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.jsindex 78aa2f85390..2d03d19cdfa 100644--- a/frontend_tests/zjsunit/namespace.js+++ b/frontend_tests/zjsunit/namespace.js@@ -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];try {obj[field] = val;diff --git a/frontend_tests/zjsunit/zpage_params.js b/frontend_tests/zjsunit/zpage_params.jsindex d25cc6481d7..4589c0a1d28 100644--- a/frontend_tests/zjsunit/zpage_params.js+++ b/frontend_tests/zjsunit/zpage_params.js@@ -6,17 +6,17 @@ exports.user_settings = {};exports.reset = () => {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];}}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];}}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];}}diff --git a/static/js/message_events.js b/static/js/message_events.jsindex 0aa51fa054b..6fbe5c3197f 100644--- a/static/js/message_events.js+++ b/static/js/message_events.js@@ -54,7 +54,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {const elsewhere_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]);new_messages.push(elem);} else {diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.jsindex aaf6dbb0918..dd9675b3c10 100644--- a/static/js/search_suggestion.js+++ b/static/js/search_suggestion.js@@ -32,7 +32,7 @@ function make_person_highlighter(query) {function match_criteria(operators, criteria) {const filter = new Filter(operators);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_operator(cr.operator);diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex 697638b8d8c..e747136cf8a 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -225,7 +225,7 @@ export function dispatch_normal_event(event) {};switch (event.op) {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;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") {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);}}diff --git a/static/js/user_events.js b/static/js/user_events.jsindex fe2cbbdffb9..5ea7dd63bcb 100644--- a/static/js/user_events.js+++ b/static/js/user_events.js@@ -30,7 +30,7 @@ export const update_person = function update(person) {return;}- if (Object.prototype.hasOwnProperty.call(person, "new_email")) {+ if (Object.hasOwn(person, "new_email")) {const user_id = person.user_id;const new_email = person.new_email;@@ -44,7 +44,7 @@ export const update_person = function update(person) {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;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);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.is_owner = person.role === settings_config.user_role_values.owner.code;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;if (people.is_my_user_id(person.user_id)) {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;person_obj.avatar_url = url;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);}- 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);}- if (Object.prototype.hasOwnProperty.call(person, "timezone")) {+ if (Object.hasOwn(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;}};diff --git a/static/shared/js/emoji.js b/static/shared/js/emoji.jsindex 7653e240a89..52f6b18fd5a 100644--- a/static/shared/js/emoji.js+++ b/static/shared/js/emoji.js@@ -76,7 +76,7 @@ const zulip_emoji = {export function get_emoji_name(codepoint) {// 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 undefined;@@ -84,7 +84,7 @@ export function get_emoji_name(codepoint) {export function get_emoji_codepoint(emoji_name) {// 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 undefined;