3

In Chrome23/Mac OS 10.8.2 this fiddle logs an error, and I want to know why.

Surprisingly enough, error does not occur if I put a breakpoint on the line that says '// BREAKPOINT' and simply resume execution.

Is it possible for JS to exceed some call rate limit in Chrome? I couldn't think of a better explanation.

Full code (I am using lodash, see its documentation of _.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();
});​
4

1 回答 1

3

以下 Fiddle 基于原始 HTML 5 Rocks 文章 ( http://www.html5rocks.com/en/tutorials/file/filesystem/ ),演示了如何调用配额系统。

http://jsfiddle.net/kim3er/h76qq/1/

window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
  //window.requestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
  initFS(grantedBytes);
}, function(e) {
  console.log('Error', e);
});
于 2013-05-29T14:20:54.127 回答