Backed out changeset 3b19f13cf22a (bug 1406746) for rooting hazards
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 10 Oct 2017 13:03:36 +0100
changeset 427917 2a21d7780597b9760df66a084095fbedfc446517
parent 427916 82957b8ff351cee2f42e8668b0593ae007594656
child 427918 7774c8002d5fad2626b7778c86602546af0cebdb
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
bugs1406746
milestone58.0a1
backs out3b19f13cf22a8ceb6597115563ac5ace6da2c872
Backed out changeset 3b19f13cf22a (bug 1406746) for rooting hazards
js/src/ctypes/CTypes.cpp
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -6845,32 +6845,35 @@ FunctionType::BuildSymbolName(JSString* 
 
 static bool
 CreateFunctionInfo(JSContext* cx,
                    HandleObject typeObj,
                    HandleValue abiType,
                    HandleObject returnType,
                    const HandleValueArray& args)
 {
-  auto fninfo = cx->make_unique<FunctionInfo>();
+  FunctionInfo* fninfo(cx->new_<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");
     return false;
   }
   fninfo->mABI = abiType.toObjectOrNull();
 
   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);
     return false;
   }
 
   fninfo->mIsVariadic = false;
 
@@ -6905,22 +6908,24 @@ CreateFunctionInfo(JSContext* cx,
     ffi_type* ffiType = CType::GetFFIType(cx, argType);
     if (!ffiType)
       return false;
 
     fninfo->mArgTypes.infallibleAppend(argType);
     fninfo->mFFITypes.infallibleAppend(ffiType);
   }
 
-  // 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()));
+  if (fninfo->mIsVariadic) {
+    // wait to PrepareCIF until function is called
+    return true;
+  }
+
+  if (!PrepareCIF(cx, fninfo))
+    return false;
+
   return true;
 }
 
 bool
 FunctionType::Create(JSContext* cx, unsigned argc, Value* vp)
 {
   // Construct and return a new FunctionType object.
   CallArgs args = CallArgsFromVp(argc, vp);