Index: src/asmjs/asm-typer.cc |
diff --git a/src/asmjs/asm-typer.cc b/src/asmjs/asm-typer.cc |
index 01c8caed6e1eb2c0a8988f0c65a4d29d4a125f52..4415c30ac6a32b3c6ea59981e7aaa59d11a8f1bc 100644 |
--- a/src/asmjs/asm-typer.cc |
+++ b/src/asmjs/asm-typer.cc |
@@ -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); |