js: Use hasOwnProperty correctly or not at all.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-05-26 15:50:02 -07:00 committed by Tim Abbott
parent 080abf4a1e
commit 62fcf98b6f
9 changed files with 13 additions and 21 deletions

View File

@ -170,7 +170,7 @@ exports.check_form = function (form_selector, expected, test_name) {
var values = casper.getFormValues(form_selector); var values = casper.getFormValues(form_selector);
var k; var k;
for (k in expected) { for (k in expected) {
if (expected.hasOwnProperty(k)) { if (Object.prototype.hasOwnProperty.call(expected, k)) {
casper.test.assertEqual(values[k], expected[k], casper.test.assertEqual(values[k], expected[k],
test_name ? test_name + ": " + k : undefined); test_name ? test_name + ": " + k : undefined);
} }

View File

@ -267,8 +267,7 @@ run_test('basics', () => {
}; };
// stub functions to see how may time they are called // stub functions to see how may time they are called
for (const method in call_count) { for (const method of Object.keys(call_count)) {
if (!call_count.hasOwnProperty(method)) { continue; }
typing_status.__Rewire__(method, function () { typing_status.__Rewire__(method, function () {
call_count[method] += 1; call_count[method] += 1;
}); });

View File

@ -191,9 +191,9 @@ BlueslipError.prototype = Object.create(Error.prototype);
exports.exception_msg = function blueslip_exception_msg(ex) { exports.exception_msg = function blueslip_exception_msg(ex) {
let message = ex.message; let message = ex.message;
if (ex.hasOwnProperty('fileName')) { if (ex.fileName !== undefined) {
message += " at " + ex.fileName; message += " at " + ex.fileName;
if (ex.hasOwnProperty('lineNumber')) { if (ex.lineNumber !== undefined) {
message += ":" + ex.lineNumber; message += ":" + ex.lineNumber;
} }
} }

View File

@ -164,7 +164,7 @@ let warned_of_localstorage = false;
localstorage.supported = function supports_localstorage() { localstorage.supported = function supports_localstorage() {
try { try {
return window.hasOwnProperty('localStorage') && window.localStorage !== null; return window.localStorage !== undefined && window.localStorage !== null;
} catch (e) { } catch (e) {
if (!warned_of_localstorage) { if (!warned_of_localstorage) {
blueslip.error("Client browser does not support local storage, will lose socket message on reload"); blueslip.error("Client browser does not support local storage, will lose socket message on reload");

View File

@ -21,7 +21,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 (data.messages.hasOwnProperty(elem.id)) { if (Object.prototype.hasOwnProperty.call(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

@ -42,11 +42,7 @@ function elem_to_user_id(elem) {
}; };
// add back all shallow properties of $.fn.popover to the new proxied version. // add back all shallow properties of $.fn.popover to the new proxied version.
for (const x in popover) { Object.assign($.fn.popover, popover);
if (popover.hasOwnProperty(x)) {
$.fn.popover[x] = popover[x];
}
}
}($.fn.popover)); }($.fn.popover));
function copy_email_handler(e) { function copy_email_handler(e) {

View File

@ -337,16 +337,13 @@ function round_to_percentages(values, total) {
// Last label will turn into "Other" if time_series data has a label not in labels // Last label will turn into "Other" if time_series data has a label not in labels
function compute_summary_chart_data(time_series_data, num_steps, labels_) { function compute_summary_chart_data(time_series_data, num_steps, labels_) {
const data = new Map(); const data = new Map();
for (const key in time_series_data) { for (const [key, array] of Object.entries(time_series_data)) {
if (!time_series_data.hasOwnProperty(key)) { if (array.length < num_steps) {
continue; num_steps = array.length;
}
if (time_series_data[key].length < num_steps) {
num_steps = time_series_data[key].length;
} }
let sum = 0; let sum = 0;
for (let i = 1; i <= num_steps; i += 1) { for (let i = 1; i <= num_steps; i += 1) {
sum += time_series_data[key][time_series_data[key].length - i]; sum += array[array.length - i];
} }
data.set(key, sum); data.set(key, sum);
} }

View File

@ -576,7 +576,7 @@ exports.initialize = function () {
function invite_success(data) { function invite_success(data) {
text_box.val(''); text_box.val('');
if (data.subscribed.hasOwnProperty(principal)) { if (Object.prototype.hasOwnProperty.call(data.subscribed, principal)) {
stream_subscription_info_elem.text(i18n.t("Subscribed successfully!")); stream_subscription_info_elem.text(i18n.t("Subscribed successfully!"));
// The rest of the work is done via the subscription -> add event we will get // The rest of the work is done via the subscription -> add event we will get
} else { } else {

View File

@ -91,7 +91,7 @@ exports.initialize = function (params) {
}; };
exports.is_user_group = function (item) { exports.is_user_group = function (item) {
return item.hasOwnProperty('members'); return item.members !== undefined;
}; };
window.user_groups = exports; window.user_groups = exports;