Index: src/asmjs/asm-typer.cc |
diff --git a/src/asmjs/asm-typer.cc b/src/asmjs/asm-typer.cc |
index 88879ab84d4a190c6954bcecdf41e1543d521e1d..4415c30ac6a32b3c6ea59981e7aaa59d11a8f1bc 100644 |
--- a/src/asmjs/asm-typer.cc |
+++ b/src/asmjs/asm-typer.cc |
@@ -326,6 +326,7 @@ AsmTyper::VariableInfo* AsmTyper::ImportLookup(Property* import) { |
if (i == stdlib->end()) { |
return nullptr; |
} |
+ stdlib_uses_.insert(i->second->standard_member()); |
return i->second; |
} |
@@ -429,7 +430,6 @@ AsmTyper::StandardMember AsmTyper::VariableAsStandardMember(Variable* var) { |
return kNone; |
} |
StandardMember member = var_info->standard_member(); |
- stdlib_uses_.insert(member); |
return member; |
} |
@@ -597,7 +597,21 @@ AsmType* AsmTyper::ValidateModule(FunctionLiteral* fun) { |
ZoneVector<Assignment*> function_pointer_tables(zone_); |
FlattenedStatements iter(zone_, fun->body()); |
auto* use_asm_directive = iter.Next(); |
- if (use_asm_directive == nullptr || !IsUseAsmDirective(use_asm_directive)) { |
+ if (use_asm_directive == nullptr) { |
+ FAIL(fun, "Missing \"use asm\"."); |
+ } |
+ // Check for extra assignment inserted by the parser when in this form: |
+ // (function Module(a, b, c) {... }) |
+ ExpressionStatement* estatement = use_asm_directive->AsExpressionStatement(); |
+ if (estatement != nullptr) { |
+ Assignment* assignment = estatement->expression()->AsAssignment(); |
+ if (assignment != nullptr && assignment->target()->IsVariableProxy() && |
+ assignment->target()->AsVariableProxy()->var()->mode() == |
+ CONST_LEGACY) { |
+ use_asm_directive = iter.Next(); |
+ } |
+ } |
+ if (!IsUseAsmDirective(use_asm_directive)) { |
FAIL(fun, "Missing \"use asm\"."); |
} |
source_layout.AddUseAsm(*use_asm_directive); |