dumbmatter / fakeIndexedDB

A pure JS in-memory implementation of the IndexedDB API
Apache License 2.0
562 stars 69 forks source link

FakeDOMStringList should not support array methods #66

Open shadow-light opened 2 years ago

shadow-light commented 2 years ago

FakeDOMStringList seems to be extending array, but a number of array methods aren't available. Such that tests can pass and then result in failure in production.

I had a migration that executed transaction.objectStoreNames.includes('...') and didn't cause any issues, but then failed in production as should have been transaction.objectStoreNames.contains('...'). Didn't pick up on it with types due to a bug in idb

dumbmatter commented 2 years ago

This is a good point.

I think FakeDOMStringList does need to subclass/extend the built-in Array, because otherwise I don't know how you'd get various proper behaviors like destructuring. Please correct me if I'm wrong.

But it should either delete the Array-specific methods from the class or if that's not possible manually override them to throw errors. I think that should be possible, at least.

I was planning on doing a new release soon, I will try to include this.

shadow-light commented 2 years ago

That sounds good, thanks for looking into it

dumbmatter commented 2 years ago

Turns out the solution I came up with in 7879a2459cc287d46076ec124a635c004ed55413 causes some problems when used with Dexie. I'm not sure why. But I guess it'll be safer to not do this, unless someone can help me figure out a better way.

dumbmatter commented 2 years ago

[].slice.call(arrayLike) is the problem, that is supposed to turn a DOMStringList into an array, but was not actually restoring the deleted methods.