paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 388 forks source link

Array.find not working in all cases #420

Open belugabob opened 8 years ago

belugabob commented 8 years ago

I'm using es6-shim to polyfill Array.find for broswers that don't support it. The issue that I'm having is that some arrays are not being polyfilled. Further investigation reveals that arrays which I create in my own code are being polyfilled, but arrays withing object structures being sent to the browser via signalr (2.2.0) are not. Is this a known issue, or am I being stupid, and misunderstanding something?

Internet Explorer 11.0.9600.18314 - update 11.0.31 es6-shim 0.35.0

ljharb commented 8 years ago

@belugabob can you explain "arrays with object structures"? I'm not familiar with signalr, but if you try Array.isArray(foo), then unless it returns true, it's not actually an array.

belugabob commented 8 years ago

Forgive my typo - should read "arrays within object structures"

Off the top of my head, as I'm not at my computer, and abbreviated for simplicity...

{ Category: "Staff", Entrants: [ { Name: "Fred", Id: 1},{ Name: "Bert", Id: 2}], }

SignalR is a server to browser communication library which effectively"pushes" data to the browser. I suspect that my issue is related to the way that SignalR deserializes the JSON payload When I get back to my desk, I'll investigate the Array.isArray situation, but I'm pretty sure that 'Entrants' was showing up as an Array, in the browser debugger

ljharb commented 8 years ago

It is possible, if SignalR is creating those arrays in a different realm (like an iframe, or a web worker) then they'd have an un-shimmed Array.prototype. If so, you could use Array.prototype.find.call instead, or, also run the es6-shim in the realm they're using.

belugabob commented 8 years ago

Ok, that sounds possible - will investigate further

cvanleeuwen commented 8 years ago

I've the encountered this exact same issue using SignalR 2.2.1.

But this seems to be more of an SignalR issue rather than es6-shim correct?

ljharb commented 8 years ago

@cvanleeuwen yes, that seems to be the case. An issue should be filed on SignalR, and this one closed.