[modules] Infer strict mode from within scope object
Refactor the Scope object to automatically enable strict mode when initialized as a "module" scope, relieving the caller of this responsibility. BUG=v8:4941 LOG=N R=adamk@chromium.org Review URL: https://codereview.chromium.org/1906923002 Cr-Commit-Position: refs/heads/master@{#35730}
This commit is contained in:
parent
4b580cad0c
commit
b86ec74395
@ -175,7 +175,10 @@ void Scope::SetDefaults(ScopeType scope_type, Scope* outer_scope,
|
||||
asm_module_ = false;
|
||||
asm_function_ = outer_scope != NULL && outer_scope->asm_module_;
|
||||
// Inherit the language mode from the parent scope.
|
||||
language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY;
|
||||
language_mode_ =
|
||||
is_module_scope()
|
||||
? STRICT
|
||||
: (outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY);
|
||||
outer_scope_calls_sloppy_eval_ = false;
|
||||
inner_scope_calls_eval_ = false;
|
||||
scope_nonlinear_ = false;
|
||||
|
@ -243,6 +243,7 @@ class Scope: public ZoneObject {
|
||||
|
||||
// Set the language mode flag (unless disabled by a global flag).
|
||||
void SetLanguageMode(LanguageMode language_mode) {
|
||||
DCHECK(!is_module_scope());
|
||||
language_mode_ = language_mode;
|
||||
}
|
||||
|
||||
|
@ -917,15 +917,15 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
|
||||
FunctionState function_state(&function_state_, &scope_, scope,
|
||||
kNormalFunction, &function_factory);
|
||||
|
||||
// Don't count the mode in the use counters--give the program a chance
|
||||
// to enable script/module-wide strict mode below.
|
||||
scope_->SetLanguageMode(info->language_mode());
|
||||
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
|
||||
bool ok = true;
|
||||
int beg_pos = scanner()->location().beg_pos;
|
||||
if (info->is_module()) {
|
||||
ParseModuleItemList(body, &ok);
|
||||
} else {
|
||||
// Don't count the mode in the use counters--give the program a chance
|
||||
// to enable script-wide strict mode below.
|
||||
scope_->SetLanguageMode(info->language_mode());
|
||||
ParseStatementList(body, Token::EOS, &ok);
|
||||
}
|
||||
|
||||
@ -1295,7 +1295,6 @@ void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
|
||||
// ModuleItem*
|
||||
|
||||
DCHECK(scope_->is_module_scope());
|
||||
RaiseLanguageMode(STRICT);
|
||||
|
||||
while (peek() != Token::EOS) {
|
||||
Statement* stat = ParseModuleItem(CHECK_OK);
|
||||
|
@ -969,8 +969,9 @@ class PreParser : public ParserBase<PreParserTraits> {
|
||||
// success (even if parsing failed, the pre-parse data successfully
|
||||
// captured the syntax error), and false if a stack-overflow happened
|
||||
// during parsing.
|
||||
PreParseResult PreParseProgram(int* materialized_literals = 0) {
|
||||
Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
|
||||
PreParseResult PreParseProgram(int* materialized_literals = 0,
|
||||
bool is_module = false) {
|
||||
Scope* scope = NewScope(scope_, is_module ? MODULE_SCOPE : SCRIPT_SCOPE);
|
||||
PreParserFactory factory(NULL);
|
||||
FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction,
|
||||
&factory);
|
||||
|
@ -1555,8 +1555,8 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
|
||||
stack_limit);
|
||||
SetParserFlags(&preparser, flags);
|
||||
scanner.Initialize(&stream);
|
||||
i::PreParser::PreParseResult result = preparser.PreParseProgram(
|
||||
&preparser_materialized_literals);
|
||||
i::PreParser::PreParseResult result =
|
||||
preparser.PreParseProgram(&preparser_materialized_literals, is_module);
|
||||
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
|
||||
}
|
||||
bool preparse_error = log.HasError();
|
||||
|
Loading…
Reference in New Issue
Block a user