Move asm_module_ and asm_function_ down to DeclarationScope

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2253913002
Cr-Commit-Position: refs/heads/master@{#38753}
This commit is contained in:
verwaest 2016-08-19 06:29:12 -07:00 committed by Commit bot
parent b0ce5d9daa
commit 10c72887b5
5 changed files with 57 additions and 31 deletions

View File

@ -83,13 +83,17 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
Factory* factory = isolate->factory();
Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
bool has_simple_parameters =
scope->is_function_scope() &&
scope->AsDeclarationScope()->has_simple_parameters();
FunctionKind function_kind =
scope->is_declaration_scope()
? scope->AsDeclarationScope()->function_kind()
: kNormalFunction;
bool has_simple_parameters = false;
bool asm_module = false;
bool asm_function = false;
FunctionKind function_kind = kNormalFunction;
if (scope->is_function_scope()) {
DeclarationScope* function_scope = scope->AsDeclarationScope();
has_simple_parameters = function_scope->has_simple_parameters();
asm_module = function_scope->asm_module();
asm_function = function_scope->asm_function();
function_kind = function_scope->function_kind();
}
// Encode the flags.
int flags = ScopeTypeField::encode(scope->scope_type()) |
@ -100,8 +104,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
HasNewTargetField::encode(has_new_target) |
FunctionVariableField::encode(function_name_info) |
FunctionVariableMode::encode(function_variable_mode) |
AsmModuleField::encode(scope->asm_module()) |
AsmFunctionField::encode(scope->asm_function()) |
AsmModuleField::encode(asm_module) |
AsmFunctionField::encode(asm_function) |
HasSimpleParametersField::encode(has_simple_parameters) |
FunctionKindField::encode(function_kind);
scope_info->SetFlags(flags);

View File

@ -87,7 +87,6 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type)
// scope must be a script scope.
DCHECK_EQ(SCRIPT_SCOPE, scope_type);
} else {
asm_function_ = outer_scope_->asm_module_;
set_language_mode(outer_scope->language_mode());
force_context_allocation_ =
!is_function_scope() && outer_scope->has_forced_context_allocation();
@ -111,6 +110,7 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
params_(4, zone),
sloppy_block_function_map_(zone) {
SetDefaults();
if (outer_scope != nullptr) asm_function_ = outer_scope_->IsAsmModule();
}
ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope,
@ -177,6 +177,8 @@ Scope::Scope(Zone* zone, Scope* inner_scope,
void DeclarationScope::SetDefaults() {
is_declaration_scope_ = true;
has_simple_parameters_ = true;
asm_module_ = false;
asm_function_ = false;
receiver_ = nullptr;
new_target_ = nullptr;
function_ = nullptr;
@ -210,8 +212,6 @@ void Scope::SetDefaults() {
scope_calls_eval_ = false;
scope_uses_super_property_ = false;
has_arguments_parameter_ = false;
asm_module_ = false;
asm_function_ = false;
scope_nonlinear_ = false;
is_hidden_ = false;
is_debug_evaluate_scope_ = false;
@ -229,6 +229,14 @@ bool Scope::HasSimpleParameters() {
return !scope->is_function_scope() || scope->has_simple_parameters();
}
bool Scope::IsAsmModule() const {
return is_function_scope() && AsDeclarationScope()->asm_module();
}
bool Scope::IsAsmFunction() const {
return is_function_scope() && AsDeclarationScope()->asm_function();
}
Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
Context* context,
DeclarationScope* script_scope,
@ -259,10 +267,11 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
} else if (context->IsFunctionContext()) {
Handle<ScopeInfo> scope_info(context->closure()->shared()->scope_info(),
isolate);
current_scope = new (zone)
DeclarationScope* function_scope = new (zone)
DeclarationScope(zone, current_scope, FUNCTION_SCOPE, scope_info);
if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true;
if (scope_info->IsAsmModule()) current_scope->asm_module_ = true;
if (scope_info->IsAsmFunction()) function_scope->set_asm_function();
if (scope_info->IsAsmModule()) function_scope->set_asm_module();
current_scope = function_scope;
} else if (context->IsBlockContext()) {
Handle<ScopeInfo> scope_info(context->scope_info(), isolate);
if (scope_info->is_declaration_scope()) {
@ -1160,8 +1169,8 @@ void Scope::Print(int n) {
if (is_strict(language_mode())) {
Indent(n1, "// strict mode scope\n");
}
if (asm_module_) Indent(n1, "// scope is an asm module\n");
if (asm_function_) Indent(n1, "// scope is an asm function\n");
if (IsAsmModule()) Indent(n1, "// scope is an asm module\n");
if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n");
if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
if (scope_uses_super_property_)
@ -1491,8 +1500,8 @@ void Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval) {
if (inner->force_eager_compilation_) {
force_eager_compilation_ = true;
}
if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
inner->asm_function_ = true;
if (IsAsmModule() && inner->is_function_scope()) {
inner->AsDeclarationScope()->set_asm_function();
}
}
}

View File

@ -233,9 +233,6 @@ class Scope: public ZoneObject {
set_language_mode(language_mode);
}
// Set the ASM module flag.
void SetAsmModule() { asm_module_ = true; }
// Inform the scope that the scope may execute declarations nonlinearly.
// Currently, the only nonlinear scope is a switch statement. The name is
// more general in case something else comes up with similar control flow,
@ -316,9 +313,8 @@ class Scope: public ZoneObject {
bool outer_scope_calls_sloppy_eval() const {
return outer_scope_calls_sloppy_eval_;
}
bool asm_module() const { return asm_module_; }
bool asm_function() const { return asm_function_; }
bool IsAsmModule() const;
bool IsAsmFunction() const;
// Does this scope access "super" property (super.foo).
bool uses_super_property() const { return scope_uses_super_property_; }
// Does this scope have the potential to execute declarations non-linearly?
@ -514,10 +510,6 @@ class Scope: public ZoneObject {
bool scope_uses_super_property_ : 1;
// This scope has a parameter called "arguments".
bool has_arguments_parameter_ : 1;
// This scope contains an "use asm" annotation.
bool asm_module_ : 1;
// This scope's outer context is an asm module.
bool asm_function_ : 1;
// This scope's declarations might not be executed in order (e.g., switch).
bool scope_nonlinear_ : 1;
bool is_hidden_ : 1;
@ -684,6 +676,11 @@ class DeclarationScope : public Scope {
IsClassConstructor(function_kind())));
}
bool asm_module() const { return asm_module_; }
void set_asm_module() { asm_module_ = true; }
bool asm_function() const { return asm_function_; }
void set_asm_function() { asm_module_ = true; }
void DeclareThis(AstValueFactory* ast_value_factory);
void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory);
@ -860,6 +857,10 @@ class DeclarationScope : public Scope {
const FunctionKind function_kind_;
bool has_simple_parameters_ : 1;
// This scope contains an "use asm" annotation.
bool asm_module_ : 1;
// This scope's outer context is an asm module.
bool asm_function_ : 1;
// Info about the parameter list of a function.
int arity_;

View File

@ -1317,7 +1317,8 @@ void Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
// Store the usage count; The actual use counter on the isolate is
// incremented after parsing is done.
++use_counts_[v8::Isolate::kUseAsm];
this->scope()->SetAsmModule();
DCHECK(this->scope()->is_declaration_scope());
this->scope()->AsDeclarationScope()->set_asm_module();
} else {
// Should not change mode, but will increment UseCounter
// if appropriate. Ditto usages below.
@ -4307,7 +4308,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
extension_ == NULL && allow_lazy() &&
function_type == FunctionLiteral::kDeclaration &&
eager_compile_hint != FunctionLiteral::kShouldEagerCompile &&
!(FLAG_validate_asm && scope()->asm_module());
!(FLAG_validate_asm && scope()->IsAsmModule());
DeclarationScope* main_scope = nullptr;
if (use_temp_zone) {

View File

@ -0,0 +1,11 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Realm.eval(Realm.current(), '"use asm"');
function f() { "use asm" }
() => "use asm"
if (true) "use asm"
with ({}) "use asm"
try { } catch (e) { "use asm" }
Realm.eval(Realm.current(), 'eval(\'"use asm"\')');