diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index 6a29f769f3fb..48f5177613ec 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -6850,15 +6850,12 @@ CreateFunctionInfo(JSContext* cx, HandleObject returnType, const HandleValueArray& args) { - FunctionInfo* fninfo(cx->new_()); + auto fninfo = cx->make_unique(); 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; }