Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cases of {} being used to store arbitrary names with Object.create(null) #1121

Open
ssalbdivad opened this issue Sep 6, 2024 · 0 comments

Comments

@ssalbdivad
Copy link
Member

I just found a bug with this code:

const nameCounts: Record<string, number | undefined> = {};

export const register = (value: object | symbol): string => {
  const existingName = namesByResolution.get(value);
  if (existingName) return existingName;

  let name = baseNameFor(value);
  if (nameCounts[name]) name = `${name}${nameCounts[name]!++}`;
  else nameCounts[name] = 1;

  registry[name] = value;
  namesByResolution.set(value, name);
  return name;
};

Where attempting to register a function called toString results in a registered name of toStringNaN☠️

We frequently use objects like this to keep track of cached entries. Many of them don't overlap with object method names like toString, but we should review those we have and switch them to Object.create(null) and implement a lint rule if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant