Bug 1406746 - Fix ctypes error handling when creating FunctionInfo r=sfink

This commit is contained in:
Jon Coppeard 2017-10-10 12:07:08 +01:00
parent d3627867f2
commit 3c1db04027

View File

@ -6850,15 +6850,12 @@ CreateFunctionInfo(JSContext* cx,
HandleObject returnType,
const HandleValueArray& args)
{
FunctionInfo* fninfo(cx->new_<FunctionInfo>());
auto fninfo = cx->make_unique<FunctionInfo>();
if (!fninfo) {
JS_ReportOutOfMemory(cx);
return false;
}
// Stash the FunctionInfo in a reserved slot.
JS_SetReservedSlot(typeObj, SLOT_FNINFO, PrivateValue(fninfo));
ffi_abi abi;
if (!GetABI(cx, abiType, &abi)) {
JS_ReportErrorASCII(cx, "Invalid ABI specification");
@ -6868,7 +6865,7 @@ CreateFunctionInfo(JSContext* cx,
fninfo->mReturnType = returnType;
// prepare the argument types
// Prepare the argument types.
if (!fninfo->mArgTypes.reserve(args.length()) ||
!fninfo->mFFITypes.reserve(args.length())) {
JS_ReportOutOfMemory(cx);
@ -6913,14 +6910,12 @@ CreateFunctionInfo(JSContext* cx,
fninfo->mFFITypes.infallibleAppend(ffiType);
}
if (fninfo->mIsVariadic) {
// wait to PrepareCIF until function is called
return true;
}
if (!PrepareCIF(cx, fninfo))
// For variadic functions, wait to PrepareCIF until the function is called.
if (!fninfo->mIsVariadic && !PrepareCIF(cx, fninfo.get()))
return false;
// Now the FunctionInfo has been initialized, store it in a reserved slot.
JS_SetReservedSlot(typeObj, SLOT_FNINFO, PrivateValue(fninfo.release()));
return true;
}