Simplify load_from_json: Accept json object directly, don't run asynchronously
This commit is contained in:
parent
44bbeb20e6
commit
d2f86799e9
|
@ -165,40 +165,25 @@ FS.prototype.load_from_json = function(fs, done)
|
|||
console.assert(fs, "Invalid fs passed to load_from_json");
|
||||
}
|
||||
|
||||
//console.time("parse");
|
||||
var fsdata = JSON.parse(fs);
|
||||
//console.timeEnd("parse");
|
||||
|
||||
if(fsdata["version"] !== JSONFS_VERSION)
|
||||
if(fs["version"] !== JSONFS_VERSION)
|
||||
{
|
||||
throw "The filesystem JSON format has changed. " +
|
||||
"Please update your fs2json (https://github.com/copy/fs2json) and recreate the filesystem JSON.";
|
||||
}
|
||||
|
||||
var fsroot = fsdata["fsroot"];
|
||||
this.used_size = fsdata["size"];
|
||||
var fsroot = fs["fsroot"];
|
||||
this.used_size = fs["size"];
|
||||
|
||||
var me = this;
|
||||
for(var i = 0; i < fsroot.length; i++) {
|
||||
this.LoadRecursive(fsroot[i], 0);
|
||||
}
|
||||
|
||||
setTimeout(function()
|
||||
{
|
||||
//console.time("Load");
|
||||
//console.profile("Load");
|
||||
for(var i = 0; i < fsroot.length; i++) {
|
||||
me.LoadRecursive(fsroot[i], 0);
|
||||
}
|
||||
//console.profileEnd("Load");
|
||||
//console.timeEnd("Load");
|
||||
//if(DEBUG)
|
||||
//{
|
||||
// this.Check();
|
||||
//}
|
||||
|
||||
//if(DEBUG)
|
||||
//{
|
||||
// console.time("Check");
|
||||
// me.Check();
|
||||
// console.timeEnd("Check");
|
||||
//}
|
||||
|
||||
done();
|
||||
}, 0);
|
||||
done && done();
|
||||
};
|
||||
|
||||
FS.prototype.LoadRecursive = function(data, parentid)
|
||||
|
|
|
@ -53,7 +53,15 @@ var ASYNC_SAFE = false;
|
|||
|
||||
http.open(options.method || "get", filename, true);
|
||||
|
||||
if(!options.as_text)
|
||||
if(options.as_text)
|
||||
{
|
||||
// the default
|
||||
}
|
||||
else if(options.as_json)
|
||||
{
|
||||
http.responseType = "json";
|
||||
}
|
||||
else
|
||||
{
|
||||
http.responseType = "arraybuffer";
|
||||
}
|
||||
|
|
|
@ -475,7 +475,7 @@ V86Starter.prototype.continue_init = function(emulator, options)
|
|||
name: "fs9p_json",
|
||||
url: fs_url,
|
||||
size: size,
|
||||
as_text: true,
|
||||
as_json: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ V86Starter.prototype.continue_init = function(emulator, options)
|
|||
v86util.load_file(f.url, {
|
||||
done: function(result)
|
||||
{
|
||||
put_on_settings.call(this, f.name, f.as_text ? result : new SyncBuffer(result));
|
||||
put_on_settings.call(this, f.name, f.as_json ? result : new SyncBuffer(result));
|
||||
cont(index + 1);
|
||||
}.bind(this),
|
||||
progress: function progress(e)
|
||||
|
@ -534,7 +534,7 @@ V86Starter.prototype.continue_init = function(emulator, options)
|
|||
});
|
||||
}
|
||||
},
|
||||
as_text: f.as_text,
|
||||
as_json: f.as_json,
|
||||
});
|
||||
}
|
||||
}.bind(this);
|
||||
|
@ -1083,7 +1083,7 @@ V86Starter.prototype.mount_fs = function(path, baseurl, basefs, callback)
|
|||
};
|
||||
if(baseurl)
|
||||
{
|
||||
dbg_assert(typeof basefs === "string", "Filesystem: basefs must be a JSON string");
|
||||
dbg_assert(typeof basefs === "object", "Filesystem: basefs must be a JSON object");
|
||||
newfs.load_from_json(basefs, () => mount());
|
||||
}
|
||||
else
|
||||
|
|
|
@ -5,7 +5,7 @@ process.on("unhandledRejection", exn => { throw exn; });
|
|||
const V86 = require("../../build/libv86-debug.js").V86;
|
||||
const fs = require("fs");
|
||||
|
||||
const testfsjson = JSON.stringify(require('./testfs.json'));
|
||||
const testfsjson = require("./testfs.json");
|
||||
const SHOW_LOGS = false;
|
||||
|
||||
function log_pass(msg, ...args)
|
||||
|
|
Loading…
Reference in a new issue