Skip to content

Conversation

@YuriGor
Copy link

@YuriGor YuriGor commented Feb 27, 2021

No description provided.

@juodumas
Copy link
Owner

Usage is low enough, no need to keep backwards compatibility in this case, I can increment the major version.

Yes, with current code these keys will exist in an empty cache: constructor, hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString, toString, valueOf [1]. Do you need them for your use case?

With your change the above top-level cache keys won't exist in an empty cache, but these will still be present: __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__, __proto__ [2].

So I see 2 possible improvements:

  1. Mark [1] and [2] keys from Object prototype as reserved by throwing an exception on them in get()/set() of the proxy.
  2. Use your change, but also mark [2] as reserved.

To mark them as reserved you would need to know when you are at top-level in the proxy.

I am ok with either change if you want to finish your PR. Please also run eslint on your changes.

@YuriGor
Copy link
Author

YuriGor commented Feb 27, 2021

About doing this optionally - we don't know how this cache may be used by folks, maybe someone will want to traverse cached data using some lib like lodash and it will not work properly because of missing base object functionality, so better keep standart objects by default and give a choice.

I my case I use your lib to cache translations / nlp, so only 'constructor' was a real issue and I don't expect someone will try keywords from JS.
I actually could handle this case manually outside of the lib, but I think it's a related stuff and lib should care.

Since we already are using proxy - maybe it makes sense to intercept this edge cases in the code explicitly and store them somehow separately?

Let me add more tests first and understand why some cases are not still covered..

@YuriGor
Copy link
Author

YuriGor commented Feb 27, 2021

I added all the cases listed by you and it's still passing.
Maybe your list [2] makes sense only for browsers?
btw eslint found no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants