function getBackendState(doc, callerName = null, argPos = 'first') {
  if (doc[OBJECT_ID] !== '_root') {
    // Most likely cause of passing an array here is forgetting to deconstruct the return value of
    // Automerge.applyChanges().
    const extraMsg = Array.isArray(doc) ? '. Note: Automerge.applyChanges now returns an array.' : ''
    if (callerName) {
      throw new TypeError(`The ${argPos} argument to Automerge.${callerName} must be the document root${extraMsg}`)
    } else {
      throw new TypeError(`Argument is not an Automerge document root${extraMsg}`)
    }
  }
  return doc[STATE].backendState
}
Returns the backend state associated with the document `doc` (only used if
a backend implementation is passed to `init()`).