зеркало из https://github.com/mozilla/gecko-dev.git
Bug 891110 - Detect attempts to pass undefined in declareFFI. r=yoric
This commit is contained in:
Родитель
8594b8c7ea
Коммит
fa3e1096d4
|
@ -885,7 +885,12 @@ let declareFFI = function declareFFI(lib, symbol, abi,
|
|||
}
|
||||
try {
|
||||
let fun = lib.declare.apply(lib, signature);
|
||||
let result = function ffi(/*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, arguments);
|
||||
return returnType.importFromC(result, symbol);
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ self.onmessage = function(msg) {
|
|||
test_getcwd();
|
||||
test_open_close();
|
||||
test_create_file();
|
||||
test_passing_undefined();
|
||||
test_access();
|
||||
test_read_write();
|
||||
finish();
|
||||
|
@ -36,6 +37,23 @@ function test_open_close() {
|
|||
is(ctypes.errno, OS.Constants.libc.ENOENT, "test_open_close: error is ENOENT");
|
||||
}
|
||||
|
||||
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) {
|
||||
exceptionRaised = true;
|
||||
}
|
||||
|
||||
ok(exceptionRaised, "test_passing_undefined: exception gets thrown")
|
||||
}
|
||||
|
||||
function test_create_file()
|
||||
{
|
||||
info("Starting test_create_file");
|
||||
|
|
Загрузка…
Ссылка в новой задаче