archives

« Bugzilla Issues Index

#4418 — 15.1.1 Early error WRT super in eval code too restrictive


On Jul 8, 2015, at 11:04 AM, Brian Terlson wrote:

Hi Allen,

Curious what the rationale behind the early error for super inside eval inside arrow functions was. See here: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-scripts-static-semantics-early-errors. Currently supported in V8 and Chakra, so presumably we’d both have to do work to implement this error. But, why would we?

---

"It is a Syntax Error if StatementList Contains super unless the source code containing super is eval code that is being processed by a direct eval that is contained in function code that is not the function code of an ArrowFunction."

I think the actual wording is a bit bogus, but let's see if we can reverse engineer the intent...

The first part, "It is a Syntax Error if StatementList Contains super" is saying that `super` is illegal in the top-level code of actual scripts and is also illegal in arrow functions (because Contains drills into them) that are contained in such top-level code. Basically, we want all of the following to be illegal in Scripts:

let x=super.foo();
let y = ()=>super.foo();
let z=()=>()=>super.foo();

That part seems fine. But it needs to be restricted because Script is used to parse eval code and we want to be able to say things like:

let obj = {
foo() {
eval(`
let x=super.foo();
let y = ()=>super.foo();
let z=()=>()=>super.foo();
`);
};

without generating a early error. So, I have the clause "...unless the source code containing super is eval code that is being processed by a direct eval that is contained in function code..."

But that, by it self, would allow

let y1= ()=>eval("super.foo()");

which should be illegal. So, I finished the "unless" clause with the restriction "...that is not the function code of an ArrowFunction."

That correctly handles top-level arrow functions, but it unintentionally also makes things like this illegal:

let obj = {
foo() {
eval(`
let y = ()=>eval("super.foo()");
`);
};

There is the additional problem, that (because of the instantiation reform changes) this should be illegal:

function f() {
eval("super.foo()");
}

But, the above rule for StatementList will not produce an early error for it. (I think this is something I missed updating when I did the Instantiation reform work in January).

I think, what we really need to say for direct eval is something along the lines of: it is an early error if the StatementList contains `super` and replacing the direct eval with a super reference would have produced an early error. (but I think it is more complicated to state than this). However we state it, it should be part of the eval semantics and not included in 15.1.1. Then the 15.1.1 rule could be:

It is a Syntax Error if StatementList Contains super unless the source code containing super is eval code that is being processed by a direct eval.