On Tue, Nov 26, 2013 at 1:38 PM, Brendan Eich <[email protected]> wrote:
> Jason Orendorff wrote:
>> Implementation note: It is super obnoxious.
>
> Just to confirm, not in the backtracking/re-lexing-based-on-parser-feedback
> sense, right? Just on the "must implement strict checks in a parse tree
> walker as well as during parsing" sense?

SpiderMonkey rewinds the token stream and re-parses.

I'm past the point of feeling sheepish about it, honestly. The code
would have to be super strange for us to rewind much (but yes, in the
worst case we can be O(n^2)). The rewinding code is fairly clean and
localized. It's also "obviously correct", as long as strict mode is
syntactically a subset of sloppy mode. This was true in ES5 and I
think it's true in ES6.

Doing it the other way effectively makes a third mode in the parser:
strict, non-strict, and "we don't know yet". That's the obnoxious bit.
Not hard to make it correct, perhaps; but impossible to make it
obviously correct.

> Duplicating strict mode implementation to be both during parsing, and
> post-processing on a parse tree, does sound bad. How bad, can you say more?

I'd do it by noting syntactic strict violations during parsing, when
in "we don't know yet" mode, and storing them in the parser until we
become sure we weren't in strict mode. We might also need to walk the
AST to mark descendent functions as strict retroactively. As long as
it's impossible to have code that parses in both modes, with different
meanings, it's not so bad.

-j
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to