TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

iOS 8 length bug breaks jQuery and Underscore object iteration

63 pointsby gadr90about 10 years ago

13 comments

hahainternetabout 10 years ago
The thing that shocks me most in this article is the subtleness of the bug inducing this behaviour: <a href="http:&#x2F;&#x2F;trac.webkit.org&#x2F;changeset&#x2F;182058" rel="nofollow">http:&#x2F;&#x2F;trac.webkit.org&#x2F;changeset&#x2F;182058</a>
评论 #9301247 未加载
BinaryIdiotabout 10 years ago
I didn&#x27;t realize anyone used integers as keys. That feels so unnatural to me. I&#x27;m also surprised any libraries would check for .length to see if it&#x27;s an array or not; there are plenty of objects you may want to create with a length property. It seems to me this would be a more accurate check:<p>Object.prototype.toString.call(maybeArray) === &quot;[object Array]&quot;<p>Also sometimes I feel like I&#x27;m the only one who doesn&#x27;t like to use underscore or jQuery for things like this; iterating over properties is so easy it seems weird to me to use a library to create a new object for me to then iterate through.
评论 #9302702 未加载
startswithajabout 10 years ago
I came across an equally strange bug a year or so ago.<p><a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;22139746&#x2F;ios-javascript-engine-parsefloat1-returns-negative-number&#x2F;22159620#22159620" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;22139746&#x2F;ios-javascript-e...</a><p>I found a way to reproduce it, put in a bug report with apple and never got a response.
joeframbachabout 10 years ago
The workaround in the article was:<p><pre><code> var thingsGroupedById = _.groupBy(things, function(t){ return &#x27;seller&#x27; + t.sellerId }); &#x2F;&#x2F; { seller1: [...], seller2: [...] } </code></pre> But I actually would have failed this in code review:<p><pre><code> _.map(thingsGroupedById, function (things) { &#x2F;&#x2F; ... }); </code></pre> and replaced it with:<p><pre><code> _.map(_.keys(thingsGroupedById), function (thingKey) { var thing = thingsGroupedById[thingKey]; &#x2F;&#x2F; ... }); </code></pre> because although mapping over objects is &quot;normal&quot;, it has never been 100%.
评论 #9301381 未加载
评论 #9301352 未加载
评论 #9301367 未加载
johnthedebsabout 10 years ago
I ran into this bug myself, and I spent an afternoon or so debugging it.<p>A simple library upgrade (Underscore 1.7.0 -&gt; 1.8.2) broke a key feature of a site I was working on, but only on my iPhone. It worked just fine on my iPad running the <i>same exact</i> version of iOS.<p>I ended up using git bisect to narrow down the commit, which consisted of several minor updates to various packages. Of those packages, it was my 3rd or 4th guess as to which would have caused that failure (it wasn&#x27;t clear since I was having trouble connecting the Safari debugger).
arsabout 10 years ago
The crazy bug aside, I could have done without the animated image macros.
评论 #9301663 未加载
wildpeaksabout 10 years ago
Array.isArray() would be more reliable than testing if it has a property &quot;length&quot; :&#x2F;<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;isArray" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Refe...</a>
评论 #9301816 未加载
评论 #9301448 未加载
booleanbetrayalabout 10 years ago
For an equally crazy bug that&#x27;s affecting Angular and several other major libraries:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;angular&#x2F;angular.js&#x2F;issues&#x2F;9128#issuecomment-77524687" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;angular&#x2F;angular.js&#x2F;issues&#x2F;9128#issuecomme...</a><p>Basically strict mode blows up webkit in odd ways.
jackjeffabout 10 years ago
I noticed an instance of _.size(obj) returning &quot;undefined&quot; on a collection using number indices, but in each instance_.keys(obj).length would work fine.<p>This was occurring on iOS 7.1.2 on a single device, from time to time. I realize after reading this, that this might be related to the WebKit bug, since it was the only 64 bit ARM device we had at the time.<p>The bug disappeared when I simply used _.keys(obj).length instead of _.size(obj). It was very hard to reproduce and I could never isolate it in a sample...<p>It&#x27;s NOT the same bug though. It&#x27;s kind of the opposite. The &quot;length&quot; property would disappear. Would that be caused by the same WebKit bug? Or that&#x27;s a new one?
tambourine_manabout 10 years ago
Not to be a jerk, but why not use objects for key value and arrays for int value?<p>Yes, JavaScript object&#x2F;array system has it&#x27;s warts, but to me that&#x27;s clearly the way it was intended to be used.
评论 #9302095 未加载
supercoderabout 10 years ago
Be great if there was an AdBlock but for animated gifs in blog articles.
评论 #9302815 未加载
hayksaakianabout 10 years ago
I think the OP likes Emma Stone
jessegavinabout 10 years ago
People still use Underscore?
评论 #9301483 未加载
评论 #9302875 未加载