Closed Bug 229006 Opened 21 years ago Closed 21 years ago

JS parser has problems parsing i++ when line number greater than 2^16

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla1.7alpha

People

(Reporter: dbaron, Assigned: brendan)

Details

Attachments

(4 files)

The JS parser has problems parsing i++ in a for loop, and perhaps other things,
when the line number is greater than 2^16.  (Asa ran into this on bugzilla
mass-change forms -- the "Check All" and "Uncheck All" bugs are document.written.)

Steps to reproduce:
  load attached testcase

Actual results:
  JS error on console:
Error: missing ) after for-loop control
Source File: file:///home/dbaron/webtest/docwrite2.html
Line: 65540, Column: 20
Source Code:
for (var i=0; i<2; i++) {

Expected results:
  no error
Attached patch patch (hack!)Splinter Review
This fixes the problem, but brendan isn't crazy about it. :-)
I'll try for a better patch, but no promises -- dbaron's may land (perhaps with
some macro magic to consolidate the awful truth).

/be
Assignee: general → brendan
Priority: -- → P3
Target Milestone: --- → mozilla1.7alpha
I'm inclined to check this in and move on.  Fancier fix ideas I'll record here
but not bother with:

1.  Store line number delta relative to first line of script, not file or url
relative (absolute) line number, in JSTokenPtr.lineno (rename it to linedelta
or some such name).

2.  Use a uint32 for JSTokenPtr and split its bits dynamically, according to
how many lines are in the script (or file/url, if 1 isn't done).  We'd need to
know how many lines total up front, or else keep revising the number of bits as
we go (somehow).  Note that with eval, it's easy to get a script contained on
one very long line, so the JSTokenPtr.index field might easily need more bits
than 16.

If anyone has a brainstorm, speak up.

/be
Attachment #138324 - Flags: review?(shaver)
Comment on attachment 138324 [details] [diff] [review]
hack dressed up via a macro

DO NOT LOOK INTO MACRO WITH REMAINING EYE.

r=shaver.
Attachment #138324 - Flags: review?(shaver) → review+
Fixed.

/be
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Thanks to dbaron.
js1_5/Regress/regress-229006.js checked in.
Flags: testcase+
verified fixed.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: