From d72d0006b6d62dedc3c3d2e50327a19884005c12 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 11 Sep 2014 17:50:37 +0200 Subject: [PATCH] Bug 1065883: Fail if we try to import variables in the global section without a stdlib parameter; r=luke --HG-- extra : rebase_source : c73ee1741babec4a4234f0e452dc64714ef7702d --- js/src/asmjs/AsmJSValidate.cpp | 12 ++++++++---- js/src/jit-test/tests/asm.js/testBasic.js | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/js/src/asmjs/AsmJSValidate.cpp b/js/src/asmjs/AsmJSValidate.cpp index 169d85a3e498..92b52a3c8941 100644 --- a/js/src/asmjs/AsmJSValidate.cpp +++ b/js/src/asmjs/AsmJSValidate.cpp @@ -3588,19 +3588,23 @@ CheckGlobalDotImport(ModuleCompiler &m, PropertyName *varName, ParseNode *initNo ParseNode *global = DotBase(base); PropertyName *mathOrSimd = DotMember(base); - if (!IsUseOfName(global, m.module().globalArgumentName())) { + PropertyName *globalName = m.module().globalArgumentName(); + if (!globalName) + return m.fail(base, "import statement requires the module have a stdlib parameter"); + + if (!IsUseOfName(global, globalName)) { if (global->isKind(PNK_DOT)) { return m.failName(base, "imports can have at most two dot accesses " - "(e.g. %s.Math.sin)", m.module().globalArgumentName()); + "(e.g. %s.Math.sin)", globalName); } - return m.failName(base, "expecting %s.*", m.module().globalArgumentName()); + return m.failName(base, "expecting %s.*", globalName); } if (mathOrSimd == m.cx()->names().Math) return CheckGlobalMathImport(m, initNode, varName, field); if (mathOrSimd == m.cx()->names().SIMD) return CheckGlobalSimdImport(m, initNode, varName, field); - return m.failName(base, "expecting %s.{Math|SIMD}", m.module().globalArgumentName()); + return m.failName(base, "expecting %s.{Math|SIMD}", globalName); } if (!base->isKind(PNK_NAME)) diff --git a/js/src/jit-test/tests/asm.js/testBasic.js b/js/src/jit-test/tests/asm.js/testBasic.js index 70e83ba6e80c..75341d4d4b9d 100644 --- a/js/src/jit-test/tests/asm.js/testBasic.js +++ b/js/src/jit-test/tests/asm.js/testBasic.js @@ -11,6 +11,7 @@ assertAsmTypeFail(USE_ASM + 'function f(){} return g'); assertAsmTypeFail(USE_ASM + 'function f(){} function f(){} return f'); assertAsmTypeFail(USE_ASM + 'function f(){}; function g(){}; return {f, g}'); assertAsmTypeFail(USE_ASM + 'var f=0; function f(){} return f'); +assertAsmTypeFail(USE_ASM + 'var f=glob.Math.imul; return {}'); assertAsmTypeFail('glob', USE_ASM + 'var f=glob.Math.imul; function f(){} return f'); assertAsmTypeFail('glob','foreign', USE_ASM + 'var f=foreign.foo; function f(){} return f'); assertAsmTypeFail(USE_ASM + 'function f(){} var f=[f,f]; return f');