nl_tokens: Handles opening the connection to the database and wraps the whole process in a promise .
pl_tokens: function openConnection ( databaseName , sortedSchemaDescriptors ) { let version = sortedSchemaDescriptors . slice ( ) . pop ( ) . version let request = NativeDBAccessor . indexedDB . open ( databaseName , version ) return new Promise ( ( resolve , reject ) => { let wasBlocked = false let upgradeTriggered = false let migrationPromiseResolver , migrationPromiseRejector let migrationPromise = new Promise ( ( resolve , reject ) => { migrationPromiseResolver = resolve migrationPromiseRejector = reject } ) // prevent leaking the same error to the console twice migrationPromise . catch ( ( ) => { } ) request . onsuccess = ( ) => { let database = new Database ( request . result ) resolve ( database ) migrationPromiseResolver ( ) } request . onupgradeneeded = ( event ) => { if ( ! wasBlocked ) { upgradeTriggered = true } let database = request . <mask> let transaction = request . transaction if ( wasBlocked ) { transaction . abort ( ) return } upgradeDatabaseSchema ( databaseName , event , migrationPromise , database , transaction , sortedSchemaDescriptors , migrationPromiseResolver , migrationPromiseRejector ) . catch ( ( error ) => { transaction . abort ( ) } ) } request . onerror = ( event ) => { handleConnectionError ( event , request . error , wasBlocked , upgradeTriggered , reject , migrationPromiseRejector ) } request . onblocked = ( ) => { wasBlocked = true let error = new Error ( "A database upgrade was needed, but could not " + "be performed, because the attempt was blocked by a connection " + "that remained opened after receiving the notification" ) reject ( error ) migrationPromiseRejector ( error ) } } ) }