Bug 13790 - Function declarations are not treated as statements (used to affect starcraft2.com)
Summary: Function declarations are not treated as statements (used to affect starcraft...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 523.x (Safari 3)
Hardware: Macintosh OS X 10.4
: P2 Normal
Assignee: Cameron Zwarich (cpst)
URL:
Keywords: InRadar
: 14090 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-05-20 07:44 PDT by Darin Adler
Modified: 2008-11-24 23:23 PST (History)
4 users (show)

See Also:


Attachments
JavaScript file that causes a syntax error unexpectedly using an inline defined named function (250 bytes, application/javascript)
2008-02-18 06:40 PST, Robbert Broersma
mail: review-
Details
Proposed patch (without test) (4.57 KB, patch)
2008-11-24 19:16 PST, Cameron Zwarich (cpst)
no flags Details | Formatted Diff | Diff
Proposed patch (10.88 KB, patch)
2008-11-24 23:02 PST, Cameron Zwarich (cpst)
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2007-05-20 07:44:01 PDT
I was having problems at the new Starcraft II site <http://www.starcraft2.com>.

I narrowed it down to a problem in <http://www.starcraft2.com/js/tooltip.js>, which is a modified copy of the Dynamic Drive DHTML tooltip script. Here's an excerpt:

    if (ie||ns6)
    //var tipobj =  document.getElementById("dhtmltooltip");

    function ietruebody(){

This boils down to "if (x) function y()", which is a syntax error in our implementation, but works fine in Firefox at least. I didn't test IE, but I'm pretty sure it works fine there.

This is a case where matching the ECMAScript standard is causing compatibility problems.
Comment 1 Darin Adler 2007-05-20 07:45:14 PDT
<rdar://problem/5216063>
Comment 2 David Kilzer (:ddkilzer) 2007-05-20 07:53:11 PDT
Another Starcraft II bug:  Bug 13787.  Not sure if they're related or not.
Comment 3 Robbert Broersma 2008-02-18 06:40:35 PST
Created attachment 19187 [details]
JavaScript file that causes a syntax error unexpectedly using an inline defined named function

I have attached an example where the SyntaxError occurs. This is a weird ECMAScript implementation issue. The script doesn't cause errors in IE7 and FF3.
Comment 4 Cameron Zwarich (cpst) 2008-07-02 02:17:37 PDT
If you look at http://www.starcraft2.com/js/tooltip.js, you will notice that the 'if' is also commented. It seems that they did not mean to comment only the var statement. The original source for that JS library also seems to support this: http://www.dynamicdrive.com/dynamicindex5/dhtmltooltip.htm.

Can we close this bug?
Comment 5 Darin Adler 2008-07-02 12:47:29 PDT
If we understand that we're different from the other JavaScript engines (with higher market share) and our considered decision is that we don't want to match their behavior, then sure, we can close the bug.

I'm sure others will make this mistake again in the future on other websites. But maybe it's OK if we behave differently.
Comment 6 Cameron Zwarich (cpst) 2008-11-24 16:16:08 PST
*** Bug 14090 has been marked as a duplicate of this bug. ***
Comment 7 Cameron Zwarich (cpst) 2008-11-24 16:17:32 PST
I will probably just do this. It will avoid future compatibility issues and it will even simplify our grammar.
Comment 8 Cameron Zwarich (cpst) 2008-11-24 19:16:05 PST
Created attachment 25467 [details]
Proposed patch (without test)

Here is a patch that fixes this problem. I will add some tests for this new behaviour and put it up for review.
Comment 9 Cameron Zwarich (cpst) 2008-11-24 23:02:50 PST
Created attachment 25474 [details]
Proposed patch
Comment 10 Geoffrey Garen 2008-11-24 23:12:56 PST
Comment on attachment 25474 [details]
Proposed patch

r=me

JavaScript stinks.
Comment 11 Cameron Zwarich (cpst) 2008-11-24 23:23:53 PST
Landed in r38747.