Bug 953104 - OdinMonkey: report validation failure for missing function-pointer tables (r=bbouvier)

--HG--
extra : rebase_source : 4d3c08640274629bd44393aee2234c4f6f829cb0
This commit is contained in:
Luke Wagner 2014-01-02 17:20:36 -06:00
parent 5ab78a1a10
commit 7384b47bfa
2 changed files with 10 additions and 3 deletions

View File

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

View File

@ -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;
}