tc39 / proposal-ptc-syntax

Discussion and specification for an explicit syntactic opt-in for Tail Calls.
http://tc39.github.io/proposal-ptc-syntax/
169 stars 8 forks source link

Statically ban `return continue eval("...")` #18

Closed littledan closed 8 years ago

littledan commented 8 years ago

Closes #14

bterlson commented 8 years ago

Sounds good!

claudepache commented 8 years ago

That looks buggy to me:

I think that some more static analysis is needed. Something like the following:

And:

Static semantics: MayBeDirectEvalReference

Identifier : IdentifierName

    1. If StringValue of IdentifierName is "eval" return true.
    2. Return false.

CoverParenthesizedExpressionAndArrowParameterList[Yield] :  (  Expression[In, ?Yield]  )

    1. Return MayBeDirectEvalReference of Expression[In, ?Yield].

SomeNonTerminal : SomeOtherNonTerminal

    1. Return MayBeDirectEvalReference of SomeOtherNonTerminal.

Anything else

    1. Return false.        
littledan commented 8 years ago

I guess we have more detailed cases like continue (1, eval)("...") as well. We implementations statically detect direct eval possibilities, so this should be possible somehow, but it's not clear how the spec text should be worded. @claudepache wanna write a PR?

claudepache commented 8 years ago

I guess we have more detailed cases like continue (1, eval)("...") as well.

(1, eval) triggers an indirect eval.

implementations statically detect direct eval possibilities, so this should be possible somehow, but it's not clear how the spec text should be worded. @claudepache wanna write a PR?

Detailing MayBeDirectEvalReference for each production, following the model of IsValidSimpleAssignmentTarget, is easy but tedious. However, one could instead use a formulation similar to what is done for the delete operator (12.5.3.1). OK, I'll write a PR soon.