Add state functions to synchronous buffers

This commit is contained in:
Fabian 2020-12-31 19:14:31 -06:00
parent d746431c93
commit bb529ccfec
3 changed files with 33 additions and 6 deletions

View file

@ -442,21 +442,23 @@ var ASYNC_SAFE = false;
AsyncXHRBuffer.prototype.get_state = function()
{
const state = [];
const loaded_blocks = [];
for(let [index, block] of Object.values(this.loaded_blocks))
for(let [index, block] of Object.entries(this.loaded_blocks))
{
dbg_assert(isFinite(+index));
loaded_blocks.push([+index, block]);
}
state[0] = loaded_blocks;
state[0] = loaded_blocks;
return state;
};
AsyncXHRBuffer.prototype.set_state = function(state)
{
const loaded_blocks = state[0];
this.loaded_blocks = Object.create(null);
for(let [index, block] of Object.values(loaded_blocks))
{
this.loaded_blocks[index] = block;
@ -557,6 +559,20 @@ var ASYNC_SAFE = false;
fn(this.buffer);
};
SyncFileBuffer.prototype.get_state = function()
{
const state = [];
state[0] = this.byteLength;
state[1] = new Uint8Array(this.buffer);
return state;
};
SyncFileBuffer.prototype.set_state = function(state)
{
this.byteLength = state[0];
this.buffer = state[1].slice().buffer;
};
/**
* Asynchronous access to File, loading blocks from the input type=file
*

View file

@ -155,7 +155,19 @@ SyncBuffer.prototype.get_buffer = function(fn)
fn(this.buffer);
};
SyncBuffer.prototype.get_state = function()
{
const state = [];
state[0] = this.byteLength;
state[1] = new Uint8Array(this.buffer);
return state;
};
SyncBuffer.prototype.set_state = function(state)
{
this.byteLength = state[0];
this.buffer = state[1].slice().buffer;
};
(function()
{

View file

@ -53,7 +53,7 @@ function run_test(name, config, done)
{
console.log("Done: %s", name);
emulator.stop();
done();
done && done();
}, 1000);
}, 1000);
});
@ -62,6 +62,5 @@ function run_test(name, config, done)
run_test("async cdrom", config_async_cdrom, function()
{
// XXX: Fails currently
//run_test("sync cdrom", config_sync_cdrom, function() {});
run_test("sync cdrom", config_sync_cdrom);
});