diff --git a/gi/function.c b/gi/function.c
index f03b5ff..d26f32b 100644
--- a/gi/function.c
+++ b/gi/function.c
@@ -648,6 +648,23 @@ gjs_invoke_c_function(JSContext      *context,
             gboolean arg_failed;
 
             g_assert_cmpuint(next_rval, <, function->js_out_argc);
+#if G_BYTE_ORDER == G_BIG_ENDIAN
+	    switch (return_tag) {
+	    case GI_TYPE_TAG_INT8:
+		return_value.v_int8 = return_value.v_int;
+		break;
+	    case GI_TYPE_TAG_UINT8:
+		return_value.v_uint8 = return_value.v_uint;
+		break;
+	    case GI_TYPE_TAG_INT16:
+		return_value.v_int16 = return_value.v_int;
+		break;
+	    case GI_TYPE_TAG_UINT16:
+		return_value.v_uint16 = return_value.v_uint;
+	    default:
+		break;
+	    }
+#endif
             arg_failed = !gjs_value_from_g_argument(context, &return_values[next_rval],
                                                     &return_info, (GArgument*)&return_value);
             if (arg_failed)

