Bug 1065883 - Fail if we try to import variables in the global section without a stdlib parameter. r=luke, a=lmandel
authorBenjamin Bouvier <benj@benj.me>
Thu, 11 Sep 2014 17:50:37 +0200
changeset 224867 7ab5f992dec0036dcc1fd9a2e8edca71aa5e9c2c
parent 224866 815df9795446a5ee5aaffcf92037002cb3558c65
child 224868 f55c10f49f50384b2fedd680f6bef61ebd64cfe7
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke, lmandel
bugs1065883
milestone34.0a2
Bug 1065883 - Fail if we try to import variables in the global section without a stdlib parameter. r=luke, a=lmandel
js/src/asmjs/AsmJSValidate.cpp
js/src/jit-test/tests/asm.js/testBasic.js
--- a/js/src/asmjs/AsmJSValidate.cpp
+++ b/js/src/asmjs/AsmJSValidate.cpp
@@ -3518,29 +3518,33 @@ CheckGlobalDotImport(ModuleCompiler &m, 
 {
     ParseNode *base = DotBase(initNode);
     PropertyName *field = DotMember(initNode);
 
     if (base->isKind(PNK_DOT)) {
         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))
         return m.fail(base, "expected name of variable or parameter");
 
     if (base->name() == m.module().globalArgumentName()) {
         if (field == m.cx()->names().NaN)
             return m.addGlobalConstant(varName, GenericNaN(), field);
--- a/js/src/jit-test/tests/asm.js/testBasic.js
+++ b/js/src/jit-test/tests/asm.js/testBasic.js
@@ -6,16 +6,17 @@ assertAsmTypeFail(USE_ASM + 'return');
 assertAsmTypeFail(USE_ASM + 'function f() 0');
 assertAsmTypeFail(USE_ASM + 'function f(){}');
 assertAsmTypeFail(USE_ASM + 'function f(){} return 0');
 assertAsmTypeFail(USE_ASM + 'function f() 0; return 0');
 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');
 assertAsmTypeFail(USE_ASM + 'function f() 0; return f');
 assertAsmTypeFail('"use strict";' + USE_ASM + 'function f() {} return f');
 assertAsmTypeFail(USE_ASM + '"use strict"; function f() {} return f');
 assertEq(asmLink(asmCompile(USE_ASM + 'function f(){} return f'))(), undefined);
 assertEq(asmLink(asmCompile(USE_ASM + 'function f(){;} return f'))(), undefined);