<commit_before>/*jshint globalstrict: true*/
'use strict';
(function(idbModules){

    /**
     * IndexedDB Object Store
     * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBObjectStore
     * @param {Object} name
     * @param {Object} transaction
     */
    var IDBObjectStore = function(name, idbTransaction, ready){
        this.name = name;
        this.transaction = idbTransaction;
        this.__ready = {};
        this.__setReadyState("createObjectStore", typeof ready === "undefined" ? true : ready);
        this.indexNames = new idbModules.util.StringList();
    };
    
    /**
     * Need this flag as createObjectStore is synchronous. So, we simply return when create ObjectStore is called
     * but do the processing in the background. All other operations should wait till ready is set
     * @param {Object} val
     */
    IDBObjectStore.prototype.__setReadyState = function(key, val){
        this.__ready[key] = val;
    };
    
    /**
     * Called by all operations on the object store, waits till the store is ready, and then performs the operation
     * @param {Object} callback
     */
    IDBObjectStore.prototype.__waitForReady = function(callback, key){
        var ready = true;
        if (typeof key !== "undefined") {
            ready = (typeof this.__ready[key] === "undefined") ? true : this.__ready[key];
        }
        else {
            for (var x in this.__ready) {
                if (!this.__ready[x]) {
                    ready = false;
                }
            }
        }
        
        if (ready) {
            callback();
        }
        else {
            idbModules.DEBUG && console.log("Waiting for to be ready", key);
            var me = this;
            window.setTimeout(function(){
                me.__waitForReady(callback, key);
            }, 100);
        }
    };
    
    /**
     * Gets (and optionally caches) the properties like keyPath, autoincrement, etc for this objectStore
     * @param {Object} callback
     */
    IDBObjectStore.prototype.__getStoreProps = function(tx, callback, waitOnProperty){
        var me = this;
        this.__waitForReady(function(){
            if (me.__storeProps) {
                idbModules.DEBUG && console.log("Store properties - cached", me.__storeProps);
                callback(me.__storeProps);
            }
            else {
                tx.executeSql("SELECT * FROM __sys__ where name = ?", [me.name], function(tx, data){
                    if (data.rows.length !== 1) {
                        callback();
                    }
                    else {
                        me.__storeProps = {
                            "name": data.rows.item(0).name,
                            "indexList": data.rows.item(0).indexList,
                            "autoInc": data.rows.item(0).autoInc,
                            "keyPath": data.rows.item(0).keyPath
                        };
                        idbModules.DEBUG && console.log("Store properties", me.__storeProps);
                        callback(me.__storeProps);
                    }
                }, function(){
                    callback();
                });
            }
        }, waitOnProperty);
    };
    
    /**
     * From the store properties and object, extracts the value for the key in hte object Store
     * If the table has auto increment, get the next in sequence
     * @param {Object} props
     * @param {Object} value
     * @param {Object} key
     */
    IDBObjectStore.prototype.__deriveKey = function(tx, value, key, callback){
        function getNextAutoIncKey(){
            tx.executeSql("SELECT * FROM sqlite_sequence where name like ?", [me.name], function(tx, data){
                if (data.rows.length !== 1) {
                    callback(0);
                }
                else {
                    callback(data.rows.item(0).seq);
                }
            }, function(tx, error){
                idbModules.util.throwDOMException(0, "Data Error - Could not get the auto increment value for key", error);
            });
        }
        
        var me = this;
        me.__getStoreProps(tx, function(props){
            if (!props) {
                idbModules.util.throwDOMException(0, "Data Error - Could not locate defination for this table", props);
            }
            if (props.keyPath) {
                if (typeof key !== "undefined") {
                    idbModules.util.throwDOMException(0, "Data Error - The object store uses in-line keys and the key parameter was provided", props);
                }
                if (value) {
                    try {
                        var primaryKey = eval("value['" + props.keyPath + "']");
                        if (!primaryKey) {
                            if (props.autoInc === "true") {
                                getNextAutoIncKey();
                            }
                            else {
                                idbModules.util.throwDOMException(0, "Data Error - Could not eval key from keyPath");
                            }
                        }
                        else {
                            callback(primaryKey);
                        }
                    } 
                    catch (e) {
                        idbModules.util.throwDOMException(0, "Data Error - Could not eval key from keyPath", e);
                    }
                }
                else {
                    idbModules.util.throwDOMException(0, "Data Error - KeyPath was specified, but value was not");
                }
            }
            else {
                if (typeof key !== "undefined") {
                    callback(key);<commit_msg>Update IDBObjectStore.js<commit_after>/*jshint globalstrict: true*/
'use strict';
(function(idbModules){

    /**
     * IndexedDB Object Store
     * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBObjectStore
     * @param {Object} name
     * @param {Object} transaction
     */
    var IDBObjectStore = function(name, idbTransaction, ready){
        this.name = name;
        this.transaction = idbTransaction;
        this.__ready = {};
        this.__setReadyState("createObjectStore", typeof ready === "undefined" ? true : ready);
        this.indexNames = new idbModules.util.StringList();
    };
    
    /**
     * Need this flag as createObjectStore is synchronous. So, we simply return when create ObjectStore is called
     * but do the processing in the background. All other operations should wait till ready is set
     * @param {Object} val
     */
    IDBObjectStore.prototype.__setReadyState = function(key, val){
        this.__ready[key] = val;
    };
    
    /**
     * Called by all operations on the object store, waits till the store is ready, and then performs the operation
     * @param {Object} callback
     */
    IDBObjectStore.prototype.__waitForReady = function(callback, key){
        var ready = true;
        if (typeof key !== "undefined") {
            ready = (typeof this.__ready[key] === "undefined") ? true : this.__ready[key];
        }
        else {
            for (var x in this.__ready) {
                if (!this.__ready[x]) {
                    ready = false;
                }
            }
        }
        
        if (ready) {
            callback();
        }
        else {
            idbModules.DEBUG && console.log("Waiting for to be ready", key);
            var me = this;
            window.setTimeout(function(){
                me.__waitForReady(callback, key);
            }, 100);
        }
    };
    
    /**
     * Gets (and optionally caches) the properties like keyPath, autoincrement, etc for this objectStore
     * @param {Object} callback
     */
    IDBObjectStore.prototype.__getStoreProps = function(tx, callback, waitOnProperty){
        var me = this;
        this.__waitForReady(function(){
            if (me.__storeProps) {
                idbModules.DEBUG && console.log("Store properties - cached", me.__storeProps);
                callback(me.__storeProps);
            }
            else {
                tx.executeSql("SELECT * FROM __sys__ where name = ?", [me.name], function(tx, data){
                    if (data.rows.length !== 1) {
                        callback();
                    }
                    else {
                        me.__storeProps = {
                            "name": data.rows.item(0).name,
                            "indexList": data.rows.item(0).indexList,
                            "autoInc": data.rows.item(0).autoInc,
                            "keyPath": data.rows.item(0).keyPath
                        };
                        idbModules.DEBUG && console.log("Store properties", me.__storeProps);
                        callback(me.__storeProps);
                    }
                }, function(){
                    callback();
                });
            }
        }, waitOnProperty);
    };
    
    /**
     * From the store properties and object, extracts the value for the key in hte object Store
     * If the table has auto increment, get the next in sequence
     * @param {Object} props
     * @param {Object} value
     * @param {Object} key
     */
    IDBObjectStore.prototype.__deriveKey = function(tx, value, key, callback){
        function getNextAutoIncKey(){
            tx.executeSql("SELECT * FROM sqlite_sequence where name like ?", [me.name], function(tx, data){
                if (data.rows.length !== 1) {
                    callback(0);
                }
                else {
                    callback(data.rows.item(0).seq);
                }
            }, function(tx, error){
                idbModules.util.throwDOMException(0, "Data Error - Could not get the auto increment value for key", error);
            });
        }
        
        var me = this;
        me.__getStoreProps(tx, function(props){
            if (!props) {
                idbModules.util.throwDOMException(0, "Data Error - Could not locate defination for this table", props);
            }
            if (props.keyPath) {
                if (typeof key !== "undefined") {
                    idbModules.util.throwDOMException(0, "Data Error - The object store uses in-line keys and the key parameter was provided", props);
                }
                if (value) {
                    try {
                        var primaryKey = eval("value['" + props.keyPath + "']");
                        if (primaryKey === undefined) {
                            if (props.autoInc === "true") {
                                getNextAutoIncKey();
                            }
                            else {
                                idbModules.util.throwDOMException(0, "Data Error - Could not eval key from keyPath");
                            }
                        }
                        else {
                            callback(primaryKey);
                        }
                    } 
                    catch (e) {
                        idbModules.util.throwDOMException(0, "Data Error - Could not eval key from keyPath", e);
                    }
                }
                else {
                    idbModules.util.throwDOMException(0, "Data Error - KeyPath was specified, but value was not");
                }
            }
            else {
                if (typeof key !== "undefined") {
                    callback(key);
{'fraction_non_alphanumeric': 0.10438032330957761, 'fraction_numerical': 0.0031288023639840083, 'mean_word_length': 1.3478881860844725, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '2447439', 'n_tokens_mistral': 2929, 'n_tokens_neox': 2814, 'n_words': 743}