archives

« Bugzilla Issues Index

#4041 — 15.1 super and new.target should not be allowed in direct evals


15.1 explicitly allows for 'super' and 'new.taget' to appear within direct eval'ed scripts within function bodies.

This is probably a bad idea that either is going to add complexity to implementations or perhaps limit optimization opportunities.

I think we should remove the "unless..." clause's in the 3rd and 4th bullets of 15.1.

(BTW, if somebody really needs to eval some code that needs to use super or 'new.target' there are workarounds such as:

let nt = ()=>new.target;
let superMethodCall = (m,...args)=>super[m](...args);

instead of:
eval("if (!new.target) super.foo();");

says:
eval("if (!nt()) superMethodCall('foo');");


What optimization opportunities should we be worried about here? Keep in mind that the presence of direct eval already inhibits virtually every optimization we've got. Methods that do not call direct eval will be unaffected either way, right?

As for direct eval implementation complexity, 'new.target' and 'super' don't seem any worse than 'this' and 'arguments', and given that we have to implement them all in arrow functions anyway, it probably won't be much harder to add direct eval support.

Admittedly, for any given weird corner case, throwing a SyntaxError is even easier.

----

I'd consider dropping [[NeedsSuper]] and NeedsSuperBinding altogether and calling MakeMethod on every method. The fact that this can be skipped for methods that don't use 'super' is worth a NOTE, but not normative text, in my view.


One of the problems (when implementing new.target) is that we need to statically know whether the function will need access to the NewTarget. We could treat the presence of direct eval the same way we would do new.target though.

As an end user I think we should allow super and new.target in direct evals.

----

I agree with Jason, I don't think the spec needs to mention [[NeedsSuper]]. An implementation can skip adding the [[HomeObject]] as long as it isn't observable.


fixed in rev35 editor's draft

got rid of NeedsSuperBinding and make all MakeMethod calls unconditional

keeping the 15.1 early errors


fixed in rev35