Bug 891110 - Detecting attempts to pass undefined in declareFFI. r=Yoric

This commit is contained in:
Avinash Kundaliya 2013-11-11 09:18:22 -05:00
parent 85f5063885
commit d4a1c11a35
3 changed files with 46 additions and 2 deletions

View File

@ -926,8 +926,13 @@ let declareFFI = function declareFFI(lib, symbol, abi,
}
try {
let fun = lib.declare.apply(lib, signature);
let result = function ffi(/*arguments*/) {
let result = fun.apply(fun, arguments);
let result = function ffi(...args) {
for (let i = 0; i < args.length; i++) {
if (typeof args[i] == "undefined") {
throw new TypeError("Argument " + i + " of " + symbol + " is undefined");
}
}
let result = fun.apply(fun, args);
return returnType.importFromC(result, symbol);
};
LOG("Function", symbol, "declared");

View File

@ -14,6 +14,7 @@ self.onmessage = function(msg) {
test_create_file();
test_access();
test_read_write();
test_passing_undefined();
finish();
};
@ -181,3 +182,20 @@ function test_read_write()
info("test_read_write cleanup complete");
}
function test_passing_undefined()
{
info("Testing that an exception gets thrown when an FFI function is passed undefined");
let exceptionRaised = false;
try {
let file = OS.Unix.File.open(undefined, OS.Constants.libc.O_RDWR
| OS.Constants.libc.O_CREAT
| OS.Constants.libc.O_TRUNC,
OS.Constants.libc.S_IRWXU);
} catch(e if e instanceof TypeError && e.message.indexOf("open") > -1) {
exceptionRaised = true;
}
ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
}

View File

@ -13,6 +13,7 @@ self.onmessage = function(msg) {
test_OpenClose();
test_CreateFile();
test_ReadWrite();
test_passing_undefined();
finish();
};
@ -188,3 +189,23 @@ function test_ReadWrite()
info("test_ReadWrite cleanup complete");
}
function test_passing_undefined()
{
info("Testing that an exception gets thrown when an FFI function is passed undefined");
let exceptionRaised = false;
try {
let file = OS.Win.File.CreateFile(
undefined,
OS.Constants.Win.GENERIC_READ,
0,
null,
OS.Constants.Win.OPEN_EXISTING,
0,
null);
} catch(e if e instanceof TypeError && e.message.indexOf("CreateFile") > -1) {
exceptionRaised = true;
}
ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
}