<commit_before>/*
 * IDBWrapper - A cross-browser wrapper for IndexedDB
 * Copyright (c) 2011 <NAME>
 * http://jensarps.de/
 *
 * Licensed under the MIT (X11) license
 */

(function(name, definition, global){
	if (typeof define === 'function'){
		define(definition);
	} else {
		global[name] = definition();
	}
})('IDBStore', function(){

	var IDBStore;
	
	var defaults = {
		dbName: 'IDB',
		storeName: 'Store',
		dbVersion: 1,
		keyPath: 'id',
		autoIncrement: true,
		onStoreReady: function(){}
	};
	
	IDBStore = function(kwArgs, onStoreReady){
		function fixupConstants(object, constants) {
			for (var prop in constants) {
				if (!(prop in object))
					object[prop] = constants[prop];
                        }
		}
          
		mixin(this, defaults);
		mixin(this, kwArgs);
		onStoreReady && (this.onStoreReady = onStoreReady);
		this.idb = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
		this.consts = window.IDBTransaction || window.webkitIDBTransaction;
		fixupConstants(this.consts, {'READ_ONLY': 'readonly',
						'READ_WRITE': 'readwrite',
						'VERSION_CHANGE': 'versionchange'});
		this.cursor = window.IDBCursor || window.webkitIDBCursor;
		fixupConstants(this.cursor, {'NEXT': 'next',
						'NEXT_NO_DUPLICATE': 'nextunique',
						'PREV': 'prev',
						'PREV_NO_DUPLICATE': 'prevunique'});
		this.openDB();
	};
	
	IDBStore.prototype = {
		
		db: null,
		
		dbName: null,
		
		dbDescription: null,
		
		dbVersion: null,
		
		store: null,
		
		storeName: null,
		
		keyPath: null,
		
		autoIncrement: null,
		
		features: null,
		
		onStoreReady: null,
		
		openDB: function(){
      // need to check for FF10, which implements the new setVersion API
      this.newVersionAPI = !!(window.IDBFactory && IDBFactory.prototype.deleteDatabase);

      var features = this.features = {};
      features.hasAutoIncrement = !window.mozIndexedDB; // TODO: Still, really?

      var openRequest;
      if (this.newVersionAPI) {
        this.dbVersion = parseInt(this.dbVersion, 10);
        openRequest = this.idb.open(this.dbName, this.dbVersion, this.dbDescription);
      } else {
        openRequest = this.idb.open(this.dbName, this.dbDescription);
      }

			openRequest.onerror = hitch(this, function(error){
        if(error.target.errorCode == 12){ // TODO: Use const
          this.dbVersion++;
          setTimeout(hitch(this, 'openDB'));
        }else{
          console.error('Could not open database, error', error);
        }
      });

			openRequest.onsuccess = hitch(this, function(event){
				this.db = event.target.result;

        this.db.onversionchange = function(event){
          event.target.close();
        };

        if(this.newVersionAPI){
          this.getObjectStore(hitch(this, function(){
            setTimeout(this.onStoreReady);
          }));
        }else{
          this.checkVersion(hitch(this, function(){
            this.getObjectStore(hitch(this, function(){
              setTimeout(this.onStoreReady);
            }));
          }));
        }
			});
		},

    enterMutationState: function(onSuccess, onError){
      if(this.newVersionAPI){<commit_msg>Adjust for removal of IDBDatabaseException in Firefox nightlies.<commit_after>/*
 * IDBWrapper - A cross-browser wrapper for IndexedDB
 * Copyright (c) 2011 <NAME>
 * http://jensarps.de/
 *
 * Licensed under the MIT (X11) license
 */

(function(name, definition, global){
	if (typeof define === 'function'){
		define(definition);
	} else {
		global[name] = definition();
	}
})('IDBStore', function(){

	var IDBStore;
	
	var defaults = {
		dbName: 'IDB',
		storeName: 'Store',
		dbVersion: 1,
		keyPath: 'id',
		autoIncrement: true,
		onStoreReady: function(){}
	};
	
	IDBStore = function(kwArgs, onStoreReady){
		function fixupConstants(object, constants) {
			for (var prop in constants) {
				if (!(prop in object))
					object[prop] = constants[prop];
                        }
		}
          
		mixin(this, defaults);
		mixin(this, kwArgs);
		onStoreReady && (this.onStoreReady = onStoreReady);
		this.idb = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
		this.consts = window.IDBTransaction || window.webkitIDBTransaction;
		fixupConstants(this.consts, {'READ_ONLY': 'readonly',
						'READ_WRITE': 'readwrite',
						'VERSION_CHANGE': 'versionchange'});
		this.cursor = window.IDBCursor || window.webkitIDBCursor;
		fixupConstants(this.cursor, {'NEXT': 'next',
						'NEXT_NO_DUPLICATE': 'nextunique',
						'PREV': 'prev',
						'PREV_NO_DUPLICATE': 'prevunique'});
		this.openDB();
	};
	
	IDBStore.prototype = {
		
		db: null,
		
		dbName: null,
		
		dbDescription: null,
		
		dbVersion: null,
		
		store: null,
		
		storeName: null,
		
		keyPath: null,
		
		autoIncrement: null,
		
		features: null,
		
		onStoreReady: null,
		
		openDB: function(){
      // need to check for FF10, which implements the new setVersion API
      this.newVersionAPI = !!(window.IDBFactory && IDBFactory.prototype.deleteDatabase);

      var features = this.features = {};
      features.hasAutoIncrement = !window.mozIndexedDB; // TODO: Still, really?

      var openRequest;
      if (this.newVersionAPI) {
        this.dbVersion = parseInt(this.dbVersion, 10);
        openRequest = this.idb.open(this.dbName, this.dbVersion, this.dbDescription);
      } else {
        openRequest = this.idb.open(this.dbName, this.dbDescription);
      }

			openRequest.onerror = hitch(this, function(error){
        var gotVersionErr = false;
        if('error' in error.target) {
          gotVersionErr = error.target.error.name == "VersionError";
        } else if('errorCode' in error.target) {
          gotVersionErr = error.target.errorCode == 12; // TODO: Use const
        }
        if(gotVersionErr){ 
          this.dbVersion++;
          setTimeout(hitch(this, 'openDB'));
        }else{
          console.error('Could not open database, error', error);
        }
      });

			openRequest.onsuccess = hitch(this, function(event){
				this.db = event.target.result;

        this.db.onversionchange = function(event){
          event.target.close();
        };

        if(this.newVersionAPI){
          this.getObjectStore(hitch(this, function(){
            setTimeout(this.onStoreReady);
          }));
        }else{
          this.checkVersion(hitch(this, function(){
            this.getObjectStore(hitch(this, function(){
              setTimeout(this.onStoreReady);
            }));
          }));
        }
			});
		},

    enterMutationState: function(onSuccess, onError){
      if(this.newVersionAPI){
{'fraction_non_alphanumeric': 0.1364052487030821, 'fraction_numerical': 0.003967043027158987, 'mean_word_length': 2.7672413793103448, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6903688', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2021, 'n_words': 417}