Opened 14 years ago

Closed 14 years ago

#7084 closed defect (invalid)

dojo.isArray([]) returns false in webkit/safari

Reported by: Sam Foster Owned by: anonymous
Priority: high Milestone: 1.2
Component: Core Version: 1.1.1
Keywords: Cc: alex
Blocked By: Blocking:


Since I'm not sure when, dojo.isArray([]) returns false in Safari 3.1.1 (mac) and the webkit currently bundled in AIR. This is because [] instanceof Array returns false (which is surely a webkit bug???)

So this test case fails: true == dojo.isArray(["some", "values"];

Change History (12)

comment:1 Changed 14 years ago by Sam Foster

I tried patching lang.js, dojo.isArray to use

return it && (it instanceof Array
typeof it == "array" it.constructor === [].constructor);

but this too returns false for me, for reasons I'm struggling to understand.

comment:2 Changed 14 years ago by Adam Peller

My Safari 3.1.1 (no AIR involved) says:

[] instanceof Array


comment:3 Changed 14 years ago by Sam Foster

Resolution: invalid
Status: newclosed

Yeah, I just tried it on Safari on windows, and on another mac - worked just fine in both . Somehow (worryingly) my safari/webkit javascript engine has gotten screwed up. I'll close as invalid and re-open if I find a meaningful way to reproduce

comment:4 Changed 14 years ago by bitranch

Resolution: invalid
Status: closedreopened

I started looking at this ticket because I ran into this same behavior. On two different Macs (one running Safari 3.1 and the other Safari 3.1.2) I get

> [] instanceof Array

Also, note that on both FF3 and Safari 3, typeof it is "object" and not "array" Checking dojo.isObject() on an array always returns true on both FF3 and Safari. (Is that correct behavior?)

It appears that dojo.isArrayLike() returns true for both [] and Array on Safari. So it appears that the current dojo.isArray isn't reliable on Safari 3.

comment:5 Changed 14 years ago by bitranch

A further note, this evaluates to true on both FF3 and Safari 3:

>>> (new Array) instanceof [].constructor

And obviously this does too:

>>> [] instanceof [].constructor

(Or maybe it isn't so obvious, considering the twisted nature of this bug.)

comment:6 Changed 14 years ago by dylan

Milestone: 1.2

comment:7 Changed 14 years ago by Adam Peller

Well, I'm now running 3.1.2 and I still get true for [] instanceof Array and for dojo.isArray([]). What are we doing differently? Dylan, can you reproduce this?

comment:8 Changed 14 years ago by dylan

I get false for both in Safari 3.1.2 on Leopard...

comment:9 Changed 14 years ago by Adam Peller

ok, fwiw, I'm on Tiger, and this would be the second time I've seen Safari behave differently on Tiger vs. Leopard.

comment:10 Changed 14 years ago by dylan

ok, even stranger... within Safari's Web Inspector, both return false, but with window.alert, they both return true, with Safari 3.1.2 on Leopard.

comment:11 Changed 14 years ago by Adam Peller

sfoster, bitranch, can you include a test case with specific setup info? Is it possible this is just an artifact of tools or iframes or something of that sort? I know you can get in a situation like this if you compare types across iframes, for example. And if we can prove this is a Safari bug, we should file something in their bugzilla for investigation, but I can't see it yet.

comment:12 Changed 14 years ago by Adam Peller

Resolution: invalid
Status: reopenedclosed

I suggest we come up with a real (web page-based) test case. If it's limited to safari's web inspector, and can be reproduced without Dojo (e.g. [] instanceof Array is false) then I suggest we file a bug with webkit instead.

Note: See TracTickets for help on using tickets.