Directive prologue members, escapes, and retroactive syntax errors

Jeff Walden jwalden+es at MIT.EDU
Thu Oct 14 14:46:10 PDT 2010

On 10/14/2010 12:40 AM, Peter van der Zee wrote:
> Can't we just say directive prologues are unaffected by strict mode altogether? They have unobservable side-effects (they're strings, it's what they do). That would prevent backtracking. But I agree that at least some clear cut decision should be made regarding the directives in strict mode.
> So basically what I propose is that as long as you are still parsing directive prologues, strict mode does not apply and no errors are thrown because of it. The active check for strict mode strictness could then be activated on the first token that's not a string.

SpiderMonkey detects, and rejects, octal string syntax within the tokenizer.  This seems like the right place to me.  Ignoring strict mode in the directive prologue would mean you'd have to move octal-string rejection out of the tokenizer.  But you can't remove it completely, because then you run into the limited-rollback problem.  So as far as I can tell your idea would require saving a flag to record strings containing octal escapes, then only checking that if not in the directive prologue -- but you don't even know if you're in the directive prologue if you've just parsed a string this way!  Consider:

function foo()
   "use strict";
   + "0" + 5;

You don't know if "\145" is part of the DP (and thus whether the escape should be ignored) until a bit after the string.  At that point it seems like you need a post-DP check to permit the escape, and you need to store *yet more* state to indicate you're definitely parsing after the DP.  This seems possibly even more problematic to me than the retroactive syntax error which triggered this entire discussion, but maybe I'm missing some clever technique to keep it simple.


More information about the es5-discuss mailing list