Bug 65523 - Redeclaration of var should have explicit test case.
Summary: Redeclaration of var should have explicit test case.
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-02 02:01 PDT by Jakob Kummerow
Modified: 2011-09-06 15:27 PDT (History)
5 users (show)

See Also:


Attachments
Proposed patch (4.20 KB, patch)
2011-08-02 02:07 PDT, Jakob Kummerow
no flags Details | Formatted Diff | Diff
Proposed patch (with correct file paths) (4.43 KB, patch)
2011-08-02 08:59 PDT, Jakob Kummerow
abarth: review-
abarth: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakob Kummerow 2011-08-02 02:01:41 PDT
According to EcmaScript 5 Section 15.1.1.3, "undefined" is a read-only property of the global object and as such cannot be re-declared as a global variable. Some layout tests, however, do precisely this. This has become an issue because V8 does, as of now, properly set the read-only flag of "undefined", and therefore throws an exception when the re-declaration attempt occurs. Fortunately, the fix is easy: since "undefined" is available as a value anyway, the conflicting redeclarations can simply be removed.

Affected tests:
* editing/pasteboard/data-transfer-items
* editing/pasteboard/onpaste-text-html
* fast/events/ondrop-text-html
* fast/js/char-at
Comment 1 Jakob Kummerow 2011-08-02 02:07:34 PDT
Created attachment 102628 [details]
Proposed patch
Comment 2 Adam Barth 2011-08-02 02:45:42 PDT
Comment on attachment 102628 [details]
Proposed patch

This looks fine, but the patch isn't based in the correct directory, so we won't be able to land this patch automatically.  Please see these instructions for preparing patches:

http://www.webkit.org/coding/contributing.html

If you're using a Chromium checkout, you might not be able to create correct WebKit patches.  Please see http://www.webkit.org/building/checkout.html for instructions on creating a WebKit working copy.

Thanks for the patch.
Comment 3 Jakob Kummerow 2011-08-02 08:59:25 PDT
Created attachment 102658 [details]
Proposed patch (with correct file paths)

Re-created the patch based on a WebKit (rather than Chromium) checkout. No other changes.
Comment 4 Alexey Proskuryakov 2011-08-02 09:42:42 PDT
CC'ing potential reviewers. The patch makes sense, but it doesn't make sense to shortcut the review process by not letting ECMAScript experts weigh in.
Comment 5 Adam Barth 2011-08-02 11:40:42 PDT
Comment on attachment 102658 [details]
Proposed patch (with correct file paths)

No one's short circuiting any review process.  There are a couple of questions here:

1) Should we add a test for this behavior specifically?  None of these tests appear to be testing this behavior intentionally.
2) Should we change JSC to match Firefox (and shortly V8) in throwing an exception here.

Neither of these questions need to block this patch.
Comment 6 Oliver Hunt 2011-08-02 11:56:19 PDT
Redeclaration should only throw an exception in strict mode -- why is an exception being thrown now?
Comment 7 Adam Barth 2011-08-02 12:07:24 PDT
@jkummerow, you say that Firefox throws as well, but the following code shows the alert in Firefox 5.0.1:

<script>
var undefined;
alert('done');
</script>
Comment 8 Jakob Kummerow 2011-08-02 14:13:39 PDT
(In reply to comment #7)

I said: Firefox throws when you redeclare a const, and V8 doesn't distinguish internally between consts and read-only properties of the global object, so it'll throw also when redeclaring a read-only property of the global object.

This code will throw in Firefox:
<script>
const undefined;
var undefined;  // <- exception
alert("boo");
</script>

Regardless of this, the proposed patch doesn't break anything, as the removed declarations are ignored anyway (or at least *should* be ignored, and indeed are at least on Firefox and bleeding-edge V8; I'm at home now and don't have Safari around for testing):
<script>
var undefined = 42;
alert("undefined: " + undefined);  // prints "undefined: undefined"
</script>
Comment 9 Adam Barth 2011-08-02 14:30:06 PDT
So these declarations don't cause problems in any browser, but they will in bleeding edge V8?  That sounds like a compat problem with bleeding edge V8 that should be fixed.  We want to match the behavior of other browsers.  If no one throws on this input, then we shouldn't either.
Comment 10 Gavin Barraclough 2011-08-02 16:06:51 PDT
Based on the above comments it seems that these tests are currently correctly passing, and in doing so are ensuring correct behavior in the browser (that non-strict code can redeclare a var).

I guess an argument could be made that checking of this behavior shouldn't be scattered amongst pasteboard/events tests, so we could create a new test case to explicitly test this.

Otherwise this bug is probably invalid.
Comment 11 Adam Barth 2011-08-02 16:13:04 PDT
> Otherwise this bug is probably invalid.

That's my sense at the moment as well, but we should confirm with jkummerow to make sure we're not misunderstanding.
Comment 12 Jakob Kummerow 2011-08-03 07:46:33 PDT
You have a valid point regarding throwing behavior (comment #9). Somehow this has slipped through. We have reverted the V8 patch in question and will come up with some other solution.

Nonetheless, the tests affected by my proposed patch contain unnecessary and ignored variable declarations. My suggestion to remove these still stands. As comment #10 says, a dedicated test would make more sense, if this behavior needs to be tested at all. But I don't feel strongly about this -- feel free to abandon/close this bug if you prefer.
Comment 13 Gavin Barraclough 2011-08-03 08:49:49 PDT
Seems like a sensible thing to do.  Renaming bug as appropriate.
Comment 14 Eric Seidel (no email) 2011-09-06 15:27:24 PDT
Comment on attachment 102628 [details]
Proposed patch

Cleared Adam Barth's review+ from obsolete attachment 102628 [details] so that this bug does not appear in http://webkit.org/pending-commit.