Closed Bug 422501 Opened 16 years ago Closed 9 years ago

"redeclaration of var arguments" caught at runtime rather than compile-time

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
minor

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: jruderman, Unassigned)

Details

(Keywords: testcase)

Most "redeclaration" errors are caught when the function is compiled:

js> function f() { try { const a=1; const a=2; } catch(e) { print(e); } }
typein:15: TypeError: redeclaration of const a:
typein:15: function f() { try { const a=1; const a=2; } catch(e) { print(e); } }
typein:15: ......................................^

But for |arguments|, it is caught only when the function is called:

js> function f() { try { const arguments=null } catch(e) { print(e); } }   
js> f()
typein:13: TypeError: redeclaration of var arguments

This confuses an extension to jsfunfuzz, which expects that if X compiles, then try{X}catch(e){} does not throw.  It also seems inefficient.

Related to bug 355480?
(In reply to comment #0)
> This confuses an extension to jsfunfuzz, which expects that if X compiles, then
> try{X}catch(e){} does not throw.

  Object = function () { throw 1 };
  try { throw 2 } catch (e) {}

probably should throw 1 (but doesn't).
(In reply to comment #1)
> (In reply to comment #0)
> > This confuses an extension to jsfunfuzz, which expects that if X compiles, then
> > try{X}catch(e){} does not throw.
> 
>   Object = function () { throw 1 };
>   try { throw 2 } catch (e) {}
> 
> probably should throw 1 (but doesn't).

ECMA-262 Edition 3 is flawed in reflecting on Object and constructing an instance of it to make the scope object for the catch clause, and Edition 4 as proposed changes this part of the spec to use lexical scope (let, block scope). So you have to go back to MOZILLA_1_8_0_BRANCH, Firefox 1.5, to see the ES3 behavior:

js> Object = function () { throw 1 };
function () {
    throw 1;
}
js> try { throw 2 } catch (e) { print(e) }
uncaught exception: 1

In Firefox 2 and 3, JS1.7 and 1.8, we changed to match ES4:

js> Object = function () { throw 1 };
function () {
    throw 1;
}
js> try { throw 2 } catch (e) { print(e) }
2

See bug 336379.

But what does any of this have to do with comment 0?

/be
OS: Mac OS X → All
Hardware: x86 → All
Assignee: general → nobody
No longer reproducible - Resolving as WFM.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.