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

Cannot augment typed array (browser incompatibility) #10221

Closed
josephrocca opened this issue Apr 17, 2021 · 5 comments
Closed

Cannot augment typed array (browser incompatibility) #10221

josephrocca opened this issue Apr 17, 2021 · 5 comments

Comments

@josephrocca
Copy link
Contributor

josephrocca commented Apr 17, 2021

While trying to run some browser code in Deno, I noticed that some browserify code was checking for typed array support by checking if this code snippet throws an error:

var arr = new Uint8Array(1)
arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
arr.foo() === 42

It does throw an error in Deno (and Node), but not in browsers.

(Edit: Woops, it does actually work in Node.js too)

I have no idea why this is the type of check they decided to use to check for typed array support, and it's hard to see any real world use case for augmenting typed arrays like this (it seems inadvisable), but I thought I'd report this browser incompatibility in case it's a bug. Please close this issue right away if it' is expected behavior.

Cheers!

@crowlKats
Copy link
Member

This is intended behaviour. See #4324

@lucacasonato
Copy link
Member

Deno does not support the __proto__ property. Instead to create an object with a given prototype, use a class, or Object.extends.

@josephrocca
Copy link
Contributor Author

@crowlKats @lucacasonato Ah, thank you both - lightening fast replies!

@kitsonk
Copy link
Contributor

kitsonk commented Apr 17, 2021

@lucacasonato you mean Object.create() right?

@lucacasonato
Copy link
Member

@lucacasonato you mean Object.create() right?

Ah yes. My bad.

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

No branches or pull requests

4 participants