Closed Bug 514560 Opened 15 years ago Closed 14 years ago

ES5 strict mode: assignments to undeclared variables not permitted

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: jimb, Assigned: jimb)

References

(Blocks 1 open bug)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 2 obsolete files)

From ES5 Appendix C: Assignment to an undeclared identifier or otherwise unresolvable reference does not create a property in the global object. When a simple assignment occurs within strict mode code, its LeftHandSide must not evaluate to an unresolvable Reference. If it does a ReferenceError exception is thrown (8.7.2). The LeftHandSide also may not be a reference to a data property with the attribute value {[[Writable]]:false}, to an accessor property with the attribute value {[[Put]]:undefined}, nor to a non-existent property of an object whose [[Extensible]] internal property has the value false. In these cases a TypeError exception is thrown (11.13.1).
The 2009-9-12 errata for ES5 changes the [[Put]] in the paragraph above to [[Set]].
Assignee: general → jim
Depends on: 514585
Attachment #404913 - Flags: review?
Attachment #404913 - Flags: review? → review?(jorendorff)
Comment on attachment 404913 [details] [diff] [review] Forbid assignments to undeclared variables in strict mode code. Looks good!
Attachment #404913 - Flags: review?(jorendorff) → review+
Er, I mean, "This is missing tests. r=me with that fixed."
Now --- with tests! (No changes to code.)
Attachment #404913 - Attachment is obsolete: true
Attachment #406737 - Flags: review?(jorendorff)
So. Maybe I'm the only one, but I absolutely hate some of the testing-function gunk some of the JS tests use. Here you use "becomes" and "never" functions, which first of all I can't even find in any of the shell.js files, and second of all which don't imply obvious functionality (I don't remember ever seeing them before). At least in my mind. Could we just make the don't-compile tests be -n tests instead, for much greater clarity?
Actually, this is an unfortunate consequence of me having split up the strict mode work amongst a bunch of different bugs. becomes, never, always, and so on are defined in that directory's shell.js, which is added here: https://bugzilla.mozilla.org/attachment.cgi?id=406543&action=diff
In general, I think it's important to have something like 'becomes' or 'never', because the goal here is to verify that a given form is fine in loose mode, but elicits an error in strict mode. I could certainly write both halves of that out, but it's really illegible. Please check out the shell.js and see if you can find it in your heart to forgive me a little abstraction. :)
Comment on attachment 406737 [details] [diff] [review] Forbid assignments to undeclared variables in strict mode code. Bug 521868 comment 3 applies here too.
Attachment #406737 - Flags: review?(jorendorff)
Tests revised per jorendorff's and waldo's comments.
Attachment #406737 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Whiteboard: fixed-in-tracemonkey
Flags: in-testsuite+
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Depends on: 541455
No longer depends on: 541455
There are four cases this bug is meant to cover: - assignment to an undeclared idenifier - assignment to read-only properties - assignment to accessors lacking Put methods - assignment to non-existent properties on non-extensible objects The patch in this bug only addresses the first, so I'm re-opening it.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
bug 537873 covers the second and third cases.
Depends on: 579119
bug 492849 covers the fourth case.
Status: REOPENED → RESOLVED
Closed: 15 years ago14 years ago
Resolution: --- → FIXED
Depends on: 640440
Depends on: 639946, 639190
Depends on: 653801
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: