2012-11-20 39 views
2

在Chrome23/Mac OS 10.8.2中this fiddle記錄錯誤,我想知道原因。Chrome文件系統API中的QUOTA_EXCEEDED_ERR

令人驚訝的是,如果我在表示'// BREAKPOINT'的行上放置斷點並簡單地恢復執行,則不會發生錯誤。

JS有可能超過Chrome中的一些通話速率限制嗎?我想不出更好的解釋。

的完整代碼(我用lodash,看到它的_.bind and _.bindAll文檔):

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 
window.LocalFileSystem = window.LocalFileSystem || {PERSISTENT: window.PERSISTENT}; 

fs = { 
initFS: function() { 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 
          1024 * 1024, this.gotFS, this.fail); 
}, 

fail: function(source, err) { 
    err.source = source; 
    var msg = ''; 

    switch (err.code) { 
     case FileError.QUOTA_EXCEEDED_ERR: 
     msg = 'QUOTA_EXCEEDED_ERR'; 
     break; 
     case FileError.NOT_FOUND_ERR: 
     msg = 'NOT_FOUND_ERR'; 
     break; 
     case FileError.SECURITY_ERR: 
     msg = 'SECURITY_ERR'; 
     break; 
     case FileError.INVALID_MODIFICATION_ERR: 
     msg = 'INVALID_MODIFICATION_ERR'; 
     break; 
     case FileError.INVALID_STATE_ERR: 
     msg = 'INVALID_STATE_ERR'; 
     break; 
     default: 
     msg = 'Unknown Error'; 
     break; 
    }; 
    err.msg = msg; 
    console.log('err ', JSON.stringify(err)); 
}, 
failarg: function(msg) { 
    return _.bind(this.fail, this, msg); 
}, 

gotFS: function(fs) { 
    this.fs = this.fs || fs; 
    this.readConfig(); 
    this.listApps(fs.root); // BREAKPOINT 
}, 

listApps: function(fsroot) { 
    this.rootReader = this.rootReader || fsroot.createReader(); 
    this.rootReader.readEntries(this.gotRootEntries, this.fail); 
}, 

gotRootEntries: function(entries) { 
    _(entries).forEach(function(entry) { 
     if (entry.isDirectory && this.controller) { 
      // TODO 
     } 
    }); 
}, 

readConfig: function() { 
    this.fs.root.getFile('config.json', {create:true}, this.gotConfigFileEntry, this.failarg('getFile')); 
}, 
gotConfigFileEntry: function(entry) { 
    entry.file(this.gotConfigFile, this.failarg('entry.file')); 
}, 
gotConfigFile: function(file) { 
    this.configFile = file; 

    var reader = new FileReader(); 
    reader.onloaded = function(evt) { 
     if (evt.target.result) { 
      this.config = JSON.parse(evt.target.result); 
     } 
    }; 
    reader.readAsText(this.configFile); 
}, 
}; 
_.bindAll(fs); 

$(function() { 
    fs.initFS(); 
});​ 
+1

你有沒有明確授予的持久性文件系統訪問?除非您使用配額API或讓Chrome應用授予無限存儲空間(請參閱https://developers.google.com/chrome/whitepapers/storage),否則您將無法使用持久性文件系統。 –

+0

如果這是原因,那麼當我試圖調試腳本時爲什麼行爲會有所不同? – Paul

+0

不確定。無論如何,如果你沒有明確的配額管理,你會遇到問題。 –

回答

相關問題