dumbmatter / fakeIndexedDB

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

FBDCursor broken in release/minimised build #65

Closed radicalapps closed 3 years ago

radicalapps commented 3 years ago

When build in release-optimised mode, the FDB Cursor no longer works, due to erroneous runtime type-checking.

The outcome is that a null or undefined value is returned from any Cursor Read operation. No exception is thrown, so it's difficult to debug. Everything works just fine in a normal development environment. To replicate the issue something like the Webpack Terser plugin must be used to optimise the javascript output.

Summary: code similar to the following occurs 3 times in FDBCursor.cs. In an optimised build, the name of the constructor will be different, causing these conditions to never be fulfilled.

if ( !this._keyOnly && this.constructor.name === "FDBCursorWithValue" ) { Resolution: Since both FDBCursor and the derived class FDBCursorWithValue already implement a toString() function, a quick fix is as follows:

if ( !this._keyOnly && this.toString() === "[object IDBCursorWithValue]" ) {

dumbmatter commented 3 years ago

Thanks! Probably not a lot of people are minifying it, but your suggested fix sounds reasonable and all the tests still pass, so I just put it in v3.1.3.