зеркало из https://github.com/mozilla/gecko-dev.git
Bug 891110 - Detecting attempts to pass undefined in declareFFI. r=Yoric
This commit is contained in:
Родитель
4bbc4f0b87
Коммит
ac49340292
|
@ -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");
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче