libfoundation: Fixed bug in array creation from object list.

Cherry-picked from commit 06ab0a944f44.