Create object with null prototype

This commit is contained in:
Folyd 2022-10-29 12:52:53 +08:00
parent 13962f1645
commit ea9da82c38
8 changed files with 11 additions and 11 deletions

View file

@ -9,7 +9,7 @@ function calendarHeatmap() {
const MONTH_LABEL_PADDING = 6;
let now = moment().endOf('day').toDate();
let yearAgo = moment().startOf('day').subtract(1, 'year').toDate();
let counterMap = {};
let counterMap = Object.create(null)
let colorRange = [];
let tooltipEnabled = true;
let tooltipUnit = 'contribution';

View file

@ -1,7 +1,7 @@
(async function() {
document.querySelector(".btn-export").onclick = async (event) => {
let target = event.target.parentElement;
let data = {};
let data = Object.create(null)
if (target.querySelector(".settings").checked) {
data["settings"] = {
"auto-update": await settings.autoUpdate,
@ -18,7 +18,7 @@
}
if (target.querySelector(".crates").checked) {
let catalog = await CrateDocManager.getCrates();
let list = {};
let list = Object.create(null)
for (const name of Object.keys(catalog)) {
list[`@${name}`] = await CrateDocManager.getCrateSearchIndex(name);
}

View file

@ -128,7 +128,7 @@ const STATS_MAP = {
let ol = searchStatsText.querySelector("ol");
// Generate default type data.
let defaultTypeData = {};
let defaultTypeData = Object.create(null)
Object.keys(STATS_MAP).forEach(name => {
defaultTypeData[name] = 0;
});

View file

@ -32,7 +32,7 @@
const STD_CRATES = ['std', 'test', 'proc_macro'];
// Remove unnecessary std crate's search index, such as core, alloc, etc
let searchIndex = {};
let searchIndex = Object.create(null)
STD_CRATES.forEach(crate => {
searchIndex[crate] = window.searchIndex[crate];
});

View file

@ -16,7 +16,7 @@ class CrateSearch {
this.crateIndexVersion = crateIndexVersion;
this.deminifier = new Deminifier(mapping);
this.crateIndex = {};
this.crateIndex = Object.create(null)
for (let [key, value] of Object.entries(crateIndex)) {
this.crateIndex[this.deminifier.deminify(key)] = value;
}

View file

@ -297,7 +297,7 @@ class DocSearch {
let val = this.valLower;
const typeFilter = itemTypeFromName(query.type),
results = {};
results = Object.create(null)
for (let z = 0; z < this.split.length; ++z) {
if (this.split[z] === "") {

View file

@ -16,7 +16,7 @@ class CrateDocSearch {
}
async initAllCrateSearcher() {
let searchIndex = {};
let searchIndex = Object.create(null)
for (const crateName of Object.keys(await CrateDocManager.getCrates())) {
searchIndex = Object.assign(searchIndex, await CrateDocManager.getCrateSearchIndex(crateName));
}

View file

@ -43,9 +43,9 @@ function makeNumericKeyObject(start, end, initial = 0) {
class Statistics {
constructor() {
this.calendarData = {};
this.cratesData = {};
this.typeData = {};
this.calendarData = Object.create(null)
this.cratesData = Object.create(null)
this.typeData = Object.create(null)
this.weeksData = WEEKS.reduce((obj, week) => {
obj[week] = 0;
return obj;