Bug 1065883: Fail if we try to import variables in the global section without a stdlib parameter; r=luke

--HG--
extra : rebase_source : c73ee1741babec4a4234f0e452dc64714ef7702d
This commit is contained in:
Benjamin Bouvier 2014-09-11 17:50:37 +02:00
parent fbbb2e69ed
commit c8e4a0f8a4
2 changed files with 9 additions and 4 deletions

View File

@ -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))

View File

@ -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');