jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.06k stars 215 forks source link

Use Polyfill in Browsers Without ArrayBuffer.isView() #193

Closed mittorn closed 6 years ago

mittorn commented 6 years ago

Code:

var mfs = new BrowserFS.FileSystem.MountableFileSystem();
BrowserFS.initialize(mfs);

Result:

Exception thrown: Uncaught TypeError: Object function ArrayBuffer() { [native code] } has no method 'isView'

Browser: UC Browser 11

jvilk commented 6 years ago

What environment are you running in? Is this a particular browser?

mittorn commented 6 years ago
var mfs = new BrowserFS.FileSystem.MountableFileSystem();
BrowserFS.initialize(mfs);

Using ZipFS and LocalStorage separately works, but i need both in same time

mittorn commented 6 years ago

UC Browser 11

jvilk commented 6 years ago

ArrayBuffer.isView is a standard function, but it looks like we should use a polyfill in browsers without it (IE 10 and, apparently, UC Browser 11). I'll fix this in the next minor version update.

mittorn commented 6 years ago

Browser does not have any debug tools , but in firefox this code seems to work. IsView was added in ES6?

jvilk commented 6 years ago

As far as I know, isView has been around in most ArrayBuffer implementations since typed arrays were added to browsers. But it was added later on during the specification process.

It seems easy enough to address.

mittorn commented 6 years ago

Yes, it is ES6, but i want to support ES5 because all other things work fine now and some browsers still not support latest version.

jvilk commented 6 years ago

If you need an instant workaround, I believe the following code should fix things:

if (!ArrayBuffer['isView']) {
  ArrayBuffer.isView = function(a) {
    return a !== null && typeof(a) === "object" && a['buffer'] instanceof ArrayBuffer;
  };
}

(Note: My fix to BrowserFS won't modify the global scope like this.)

mittorn commented 6 years ago

Thank you, it work now.

jvilk commented 6 years ago

This is an issue in the buffer dependency that was fixed recently:

https://github.com/feross/buffer/commit/2ac965b088d5e9019930c3d9016c7a213994e2fb

No BrowserFS-specific code calls ArrayBuffer.isView().

jvilk commented 6 years ago

The next release will use the new buffer version, and will not call isView if it does not exist.