diff --git a/js/src/jit-test/tests/asm.js/testFunctionPtr.js b/js/src/jit-test/tests/asm.js/testFunctionPtr.js index b181af119d7..9998356f044 100644 --- a/js/src/jit-test/tests/asm.js/testFunctionPtr.js +++ b/js/src/jit-test/tests/asm.js/testFunctionPtr.js @@ -12,7 +12,7 @@ assertAsmTypeFail(USE_ASM + "function f() {} function g(i) {i=i|0} var tbl=[f,g] assertAsmTypeFail(USE_ASM + "function f() {} function g() {return 0} var tbl=[f,g]; return f"); assertAsmTypeFail(USE_ASM + "function f(i) {i=i|0} function g(i) {i=+i} var tbl=[f,g]; return f"); assertAsmTypeFail(USE_ASM + "function f() {return 0} function g() {return 0.0} var tbl=[f,g]; return f"); -assertAsmTypeFail(USE_ASM + "var tbl=0; function g() {tbl[0&1]()} return g"); +assertAsmTypeFail(USE_ASM + "var tbl=0; function g() {tbl[0&1]()|0} return g"); assertEq(asmLink(asmCompile(USE_ASM + "function f() { return 42 } var tbl=[f]; return f"))(), 42); assertEq(asmLink(asmCompile(USE_ASM + "function f() {return 0} function g() {return 1} var tbl=[f,g]; return f"))(), 0); @@ -26,6 +26,7 @@ assertAsmTypeFail(USE_ASM + "function f() {return 42} function g(i) { i=i|0; ret assertAsmTypeFail(USE_ASM + "function f(i) {i=i|0} function g(i) { i=i|0; return tbl[i&1]()|0 } var tbl=[f,f]; return g"); assertAsmTypeFail(USE_ASM + "function f(i) {i=i|0} function g(i) { i=i|0; return tbl[i&1](3.0)|0 } var tbl=[f,f]; return g"); assertAsmTypeFail(USE_ASM + "function f(d) {d=+d} function g(i) { i=i|0; return tbl[i&1](3)|0 } var tbl=[f,f]; return g"); +assertAsmTypeFail(USE_ASM + "function g() {tbl[0&1]()|0} return g"); assertEq(asmLink(asmCompile(USE_ASM + "function f() {return 42} function g(i) { i=i|0; return tbl[i&1]()|0 } var tbl=[f,f]; return g"))(0), 42); assertEq(asmLink(asmCompile(USE_ASM + "function f() {return 42} function g(i) { i=i|0; return tbl[i&1]()|0 } const tbl=[f,f]; return g"))(0), 42); assertEq(asmLink(asmCompile(USE_ASM + "function f() {return 42} function g() {return 13} function h(i) { i=i|0; return tbl[i&1]()|0 } var tbl=[f,g]; return h"))(1), 13); diff --git a/js/src/jit/AsmJS.cpp b/js/src/jit/AsmJS.cpp index f2e304e60df..2565f754f72 100644 --- a/js/src/jit/AsmJS.cpp +++ b/js/src/jit/AsmJS.cpp @@ -1209,8 +1209,9 @@ class MOZ_STACK_CLASS ModuleCompiler unsigned mask() const { return mask_; } unsigned globalDataOffset() const { return globalDataOffset_; } - void initElems(FuncPtrVector &&elems) { elems_ = Move(elems); JS_ASSERT(!elems_.empty()); } - unsigned numElems() const { JS_ASSERT(!elems_.empty()); return elems_.length(); } + bool initialized() const { return !elems_.empty(); } + void initElems(FuncPtrVector &&elems) { elems_ = Move(elems); JS_ASSERT(initialized()); } + unsigned numElems() const { JS_ASSERT(initialized()); return elems_.length(); } const Func &elem(unsigned i) const { return *elems_[i]; } }; @@ -5702,6 +5703,11 @@ CheckFuncPtrTables(ModuleCompiler &m) } } + for (unsigned i = 0; i < m.numFuncPtrTables(); i++) { + if (!m.funcPtrTable(i).initialized()) + return m.fail(nullptr, "expecting function-pointer table"); + } + return true; }