Bug 769072: retroactively apply strict mode to defaults. r=njn

This commit is contained in:
Benjamin Peterson
2012-07-09 23:43:06 -07:00
parent 643a651be7
commit 39068ba4c6
11 changed files with 354 additions and 180 deletions

View File

@@ -101,7 +101,7 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain, StackFrame *call
if (!parser.init())
return NULL;
SharedContext sc(cx, scopeChain, /* fun = */ NULL, /* funbox = */ NULL);
SharedContext sc(cx, scopeChain, /* fun = */ NULL, /* funbox = */ NULL, StrictModeFromContext(cx));
TreeContext tc(&parser, &sc, staticLevel, /* bodyid = */ 0);
if (!tc.init())
@@ -133,7 +133,7 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain, StackFrame *call
/* If this is a direct call to eval, inherit the caller's strictness. */
if (callerFrame && callerFrame->isScriptFrame() && callerFrame->script()->strictModeCode)
sc.setInStrictMode();
sc.strictModeState = StrictMode::STRICT;
if (compileAndGo) {
if (source) {
@@ -169,9 +169,18 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain, StackFrame *call
onlyXML = true;
#endif
bool inDirectivePrologue = true;
TokenStream &tokenStream = parser.tokenStream;
tokenStream.setOctalCharacterEscape(false);
{
ParseNode *stringsAtStart = ListNode::create(PNK_STATEMENTLIST, &parser);
if (!stringsAtStart)
return NULL;
stringsAtStart->makeEmpty();
bool ok = parser.processDirectives(stringsAtStart) && EmitTree(cx, &bce, stringsAtStart);
parser.freeTree(stringsAtStart);
if (!ok)
return NULL;
}
JS_ASSERT(sc.strictModeState != StrictMode::UNKNOWN);
for (;;) {
TokenKind tt = tokenStream.peekToken(TSF_OPERAND);
if (tt <= TOK_EOF) {
@@ -185,9 +194,6 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain, StackFrame *call
if (!pn)
return NULL;
if (inDirectivePrologue && !parser.recognizeDirectivePrologue(pn, &inDirectivePrologue))
return NULL;
if (!FoldConstants(cx, pn, &parser))
return NULL;
@@ -263,7 +269,8 @@ frontend::CompileFunctionBody(JSContext *cx, HandleFunction fun,
return false;
JS_ASSERT(fun);
SharedContext funsc(cx, /* scopeChain = */ NULL, fun, /* funbox = */ NULL);
SharedContext funsc(cx, /* scopeChain = */ NULL, fun, /* funbox = */ NULL,
StrictModeFromContext(cx));
funsc.bindings.transfer(bindings);
fun->setArgCount(funsc.bindings.numArgs());