mirror of https://github.com/zulip/zulip.git
js: Use hasOwnProperty correctly or not at all.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
080abf4a1e
commit
62fcf98b6f
|
@ -170,7 +170,7 @@ exports.check_form = function (form_selector, expected, test_name) {
|
|||
var values = casper.getFormValues(form_selector);
|
||||
var k;
|
||||
for (k in expected) {
|
||||
if (expected.hasOwnProperty(k)) {
|
||||
if (Object.prototype.hasOwnProperty.call(expected, k)) {
|
||||
casper.test.assertEqual(values[k], expected[k],
|
||||
test_name ? test_name + ": " + k : undefined);
|
||||
}
|
||||
|
|
|
@ -267,8 +267,7 @@ run_test('basics', () => {
|
|||
};
|
||||
|
||||
// stub functions to see how may time they are called
|
||||
for (const method in call_count) {
|
||||
if (!call_count.hasOwnProperty(method)) { continue; }
|
||||
for (const method of Object.keys(call_count)) {
|
||||
typing_status.__Rewire__(method, function () {
|
||||
call_count[method] += 1;
|
||||
});
|
||||
|
|
|
@ -191,9 +191,9 @@ BlueslipError.prototype = Object.create(Error.prototype);
|
|||
|
||||
exports.exception_msg = function blueslip_exception_msg(ex) {
|
||||
let message = ex.message;
|
||||
if (ex.hasOwnProperty('fileName')) {
|
||||
if (ex.fileName !== undefined) {
|
||||
message += " at " + ex.fileName;
|
||||
if (ex.hasOwnProperty('lineNumber')) {
|
||||
if (ex.lineNumber !== undefined) {
|
||||
message += ":" + ex.lineNumber;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ let warned_of_localstorage = false;
|
|||
|
||||
localstorage.supported = function supports_localstorage() {
|
||||
try {
|
||||
return window.hasOwnProperty('localStorage') && window.localStorage !== null;
|
||||
return window.localStorage !== undefined && window.localStorage !== null;
|
||||
} catch (e) {
|
||||
if (!warned_of_localstorage) {
|
||||
blueslip.error("Client browser does not support local storage, will lose socket message on reload");
|
||||
|
|
|
@ -21,7 +21,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {
|
|||
const elsewhere_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]);
|
||||
new_messages.push(elem);
|
||||
} else {
|
||||
|
|
|
@ -42,11 +42,7 @@ function elem_to_user_id(elem) {
|
|||
};
|
||||
|
||||
// add back all shallow properties of $.fn.popover to the new proxied version.
|
||||
for (const x in popover) {
|
||||
if (popover.hasOwnProperty(x)) {
|
||||
$.fn.popover[x] = popover[x];
|
||||
}
|
||||
}
|
||||
Object.assign($.fn.popover, popover);
|
||||
}($.fn.popover));
|
||||
|
||||
function copy_email_handler(e) {
|
||||
|
|
|
@ -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
|
||||
function compute_summary_chart_data(time_series_data, num_steps, labels_) {
|
||||
const data = new Map();
|
||||
for (const key in time_series_data) {
|
||||
if (!time_series_data.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
if (time_series_data[key].length < num_steps) {
|
||||
num_steps = time_series_data[key].length;
|
||||
for (const [key, array] of Object.entries(time_series_data)) {
|
||||
if (array.length < num_steps) {
|
||||
num_steps = array.length;
|
||||
}
|
||||
let sum = 0;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -576,7 +576,7 @@ exports.initialize = function () {
|
|||
function invite_success(data) {
|
||||
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!"));
|
||||
// The rest of the work is done via the subscription -> add event we will get
|
||||
} else {
|
||||
|
|
|
@ -91,7 +91,7 @@ exports.initialize = function (params) {
|
|||
};
|
||||
|
||||
exports.is_user_group = function (item) {
|
||||
return item.hasOwnProperty('members');
|
||||
return item.members !== undefined;
|
||||
};
|
||||
|
||||
window.user_groups = exports;
|
||||
|
|
Loading…
Reference in New Issue