diff --git a/src/asmjs/asm-parser.cc b/src/asmjs/asm-parser.cc index 025576f2dc..7ebc5a06ce 100644 --- a/src/asmjs/asm-parser.cc +++ b/src/asmjs/asm-parser.cc @@ -41,7 +41,6 @@ namespace wasm { #define FAIL(msg) FAIL_AND_RETURN(, msg) #define FAILn(msg) FAIL_AND_RETURN(nullptr, msg) -#define FAILf(msg) FAIL_AND_RETURN(false, msg) #define EXPECT_TOKEN_OR_RETURN(ret, token) \ do { \ @@ -53,7 +52,6 @@ namespace wasm { #define EXPECT_TOKEN(token) EXPECT_TOKEN_OR_RETURN(, token) #define EXPECT_TOKENn(token) EXPECT_TOKEN_OR_RETURN(nullptr, token) -#define EXPECT_TOKENf(token) EXPECT_TOKEN_OR_RETURN(false, token) #define RECURSE_OR_RETURN(ret, call) \ do { \ @@ -67,7 +65,6 @@ namespace wasm { #define RECURSE(call) RECURSE_OR_RETURN(, call) #define RECURSEn(call) RECURSE_OR_RETURN(nullptr, call) -#define RECURSEf(call) RECURSE_OR_RETURN(false, call) #define TOK(name) AsmJsScanner::kToken_##name @@ -469,8 +466,8 @@ void AsmJsParser::ValidateModuleVar(bool mutable_variable) { } else if (Check(stdlib_name_)) { EXPECT_TOKEN('.'); RECURSE(ValidateModuleVarStdlib(info)); - } else if (ValidateModuleVarImport(info, mutable_variable)) { - // Handled inside. + } else if (Peek(foreign_name_) || Peek('+')) { + RECURSE(ValidateModuleVarImport(info, mutable_variable)); } else if (scanner_.IsGlobal()) { RECURSE(ValidateModuleVarFromGlobal(info, mutable_variable)); } else { @@ -527,32 +524,30 @@ void AsmJsParser::ValidateModuleVarFromGlobal(VarInfo* info, } // 6.1 ValidateModule - foreign imports -bool AsmJsParser::ValidateModuleVarImport(VarInfo* info, +void AsmJsParser::ValidateModuleVarImport(VarInfo* info, bool mutable_variable) { if (Check('+')) { - EXPECT_TOKENf(foreign_name_); - EXPECT_TOKENf('.'); + EXPECT_TOKEN(foreign_name_); + EXPECT_TOKEN('.'); Vector name = CopyCurrentIdentifierString(); AddGlobalImport(name, AsmType::Double(), kWasmF64, mutable_variable, info); scanner_.Next(); - return true; - } else if (Check(foreign_name_)) { - EXPECT_TOKENf('.'); + } else { + EXPECT_TOKEN(foreign_name_); + EXPECT_TOKEN('.'); Vector name = CopyCurrentIdentifierString(); scanner_.Next(); if (Check('|')) { if (!CheckForZero()) { - FAILf("Expected |0 type annotation for foreign integer import"); + FAIL("Expected |0 type annotation for foreign integer import"); } AddGlobalImport(name, AsmType::Int(), kWasmI32, mutable_variable, info); - return true; + } else { + info->kind = VarKind::kImportedFunction; + info->import = new (zone()->New(sizeof(FunctionImportInfo))) + FunctionImportInfo({name, WasmModuleBuilder::SignatureMap(zone())}); } - info->kind = VarKind::kImportedFunction; - info->import = new (zone()->New(sizeof(FunctionImportInfo))) - FunctionImportInfo({name, WasmModuleBuilder::SignatureMap(zone())}); - return true; } - return false; } // 6.1 ValidateModule - one variable diff --git a/src/asmjs/asm-parser.h b/src/asmjs/asm-parser.h index 4bcc97a779..07b7b5d6d6 100644 --- a/src/asmjs/asm-parser.h +++ b/src/asmjs/asm-parser.h @@ -276,7 +276,7 @@ class AsmJsParser { void ValidateModuleParameters(); void ValidateModuleVars(); void ValidateModuleVar(bool mutable_variable); - bool ValidateModuleVarImport(VarInfo* info, bool mutable_variable); + void ValidateModuleVarImport(VarInfo* info, bool mutable_variable); void ValidateModuleVarStdlib(VarInfo* info); void ValidateModuleVarNewStdlib(VarInfo* info); void ValidateModuleVarFromGlobal(VarInfo* info, bool mutable_variable); diff --git a/test/message/asm-import-wrong-annotation.js b/test/message/asm-import-wrong-annotation.js new file mode 100644 index 0000000000..0b57c1a986 --- /dev/null +++ b/test/message/asm-import-wrong-annotation.js @@ -0,0 +1,11 @@ +// Copyright 2017 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. + +// Flags: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages + +function Module(stdlib, foreign, heap) { + "use asm" + var x = foreign.x | 1; +} +Module(this, { x:0 }); diff --git a/test/message/asm-import-wrong-annotation.out b/test/message/asm-import-wrong-annotation.out new file mode 100644 index 0000000000..dec52ddb49 --- /dev/null +++ b/test/message/asm-import-wrong-annotation.out @@ -0,0 +1,5 @@ +# Copyright 2017 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. + +*%(basename)s:9: Invalid asm.js: Expected |0 type annotation for foreign integer import diff --git a/test/message/asm-import-wrong-object.js b/test/message/asm-import-wrong-object.js new file mode 100644 index 0000000000..d077e04d91 --- /dev/null +++ b/test/message/asm-import-wrong-object.js @@ -0,0 +1,11 @@ +// Copyright 2017 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. + +// Flags: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages + +function Module(stdlib, foreign, heap) { + "use asm" + var x = +stdlib.x; +} +Module(this, { x:0 }); diff --git a/test/message/asm-import-wrong-object.out b/test/message/asm-import-wrong-object.out new file mode 100644 index 0000000000..f72d0863f9 --- /dev/null +++ b/test/message/asm-import-wrong-object.out @@ -0,0 +1,5 @@ +# Copyright 2017 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. + +*%(basename)s:9: Invalid asm.js: Unexpected token