emoji: Abstract all name_to_codepoint, codepoint_to_name accesses.

Computed indexes into these raw objects should be guarded with
Object.prototype.hasOwnProperty; make our accessors do this
automatically and use them consistently.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-05-26 19:17:29 -07:00
committed by Tim Abbott
parent e5e1a05e74
commit 080abf4a1e
6 changed files with 51 additions and 68 deletions

View File

@@ -109,10 +109,9 @@ exports.generate_emoji_picker_data = function (realm_emojis) {
for (const [category, codepoints] of Object.entries(emoji_codes.emoji_catalog)) {
const emojis = [];
for (const codepoint of codepoints) {
if (emoji_codes.codepoint_to_name.hasOwnProperty(codepoint)) {
const emoji_dict = emoji.emojis_by_name.get(
emoji_codes.codepoint_to_name[codepoint]
);
const name = emoji.get_emoji_name(codepoint);
if (name !== undefined) {
const emoji_dict = emoji.emojis_by_name.get(name);
if (emoji_dict !== undefined && emoji_dict.is_realm_emoji !== true) {
emojis.push(emoji_dict);
}
@@ -123,8 +122,9 @@ exports.generate_emoji_picker_data = function (realm_emojis) {
const popular = [];
for (const codepoint of typeahead.popular_emojis) {
if (emoji_codes.codepoint_to_name.hasOwnProperty(codepoint)) {
const emoji_dict = emoji.emojis_by_name.get(emoji_codes.codepoint_to_name[codepoint]);
const name = emoji.get_emoji_name(codepoint);
if (name !== undefined) {
const emoji_dict = emoji.emojis_by_name.get(name);
if (emoji_dict !== undefined) {
popular.push(emoji_dict);
}