Merge branch 'next-release'
This commit is contained in:
commit
baac8d4ea8
221 changed files with 6475 additions and 2731 deletions
|
|
@ -283,6 +283,129 @@ web.getResource = function(sURL, dataPost, fAsync, done)
|
|||
return response;
|
||||
};
|
||||
|
||||
/**
|
||||
* parseMemoryResource(sURL, sData)
|
||||
*
|
||||
* @param {string} sData
|
||||
* @return {Object|null} (resource)
|
||||
*/
|
||||
web.parseMemoryResource = function(sURL, sData)
|
||||
{
|
||||
var i;
|
||||
var resource = {
|
||||
aBytes: null,
|
||||
aSymbols: null,
|
||||
addrLoad: null,
|
||||
addrExec: null
|
||||
};
|
||||
|
||||
if (sData.charAt(0) == "[" || sData.charAt(0) == "{") {
|
||||
try {
|
||||
var a, ib, data;
|
||||
|
||||
if (sData.substr(0, 1) == "<") { // if the "data" begins with a "<"...
|
||||
/*
|
||||
* Early server configs reported an error (via the nErrorCode parameter) if a tape URL was invalid,
|
||||
* but more recent server configs now display a somewhat friendlier HTML error page. The downside,
|
||||
* however, is that the original error has been buried, and we've received "data" that isn't actually
|
||||
* tape data. So if the data we've received appears to be "HTML-like", we treat it as an error message.
|
||||
*/
|
||||
throw new Error(sData);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: IE9 is rather unfriendly and restrictive with regard to how much data it's willing to
|
||||
* eval(). In particular, the 10Mb disk image we use for the Windows 1.01 demo config fails in
|
||||
* IE9 with an "Out of memory" exception. One work-around would be to chop the data into chunks
|
||||
* (perhaps one track per chunk, using regular expressions) and then manually re-assemble it.
|
||||
*
|
||||
* However, it turns out that using JSON.parse(sDiskData) instead of eval("(" + sDiskData + ")")
|
||||
* is a much easier fix. The only drawback is that we must first quote any unquoted property names
|
||||
* and remove any comments, because while eval() was cool with them, JSON.parse() is more particular;
|
||||
* the following RegExp replacements take care of those requirements.
|
||||
*
|
||||
* The use of hex values is something else that eval() was OK with, but JSON.parse() is not, and
|
||||
* while I've stopped using hex values in DumpAPI responses (at least when "format=json" is specified),
|
||||
* I can't guarantee they won't show up in "legacy" images, and there's no simple RegExp replacement
|
||||
* for transforming hex values into decimal values, so I cop out and fall back to eval() if I detect
|
||||
* any hex prefixes ("0x") in the sequence. Ditto for error messages, which appear like so:
|
||||
*
|
||||
* ["unrecognized disk path: test.img"]
|
||||
*/
|
||||
if (sData.indexOf("0x") < 0 && sData.substr(0, 2) != "[\"") {
|
||||
data = JSON.parse(sData.replace(/([a-z]+):/gm, "\"$1\":").replace(/\/\/[^\n]*/gm, ""));
|
||||
} else {
|
||||
data = eval("(" + sData + ")");
|
||||
}
|
||||
|
||||
resource.addrLoad = data['load'];
|
||||
resource.addrExec = data['exec'];
|
||||
|
||||
if (a = data['bytes']) {
|
||||
resource.aBytes = a;
|
||||
}
|
||||
else if (a = data['words']) {
|
||||
/*
|
||||
* Convert all words into bytes
|
||||
*/
|
||||
resource.aBytes = new Array(a.length * 2);
|
||||
for (i = 0, ib = 0; i < a.length; i++) {
|
||||
resource.aBytes[ib++] = a[i] & 0xff;
|
||||
resource.aBytes[ib++] = (a[i] >> 8) & 0xff;
|
||||
Component.assert(!(a[i] & ~0xffff));
|
||||
}
|
||||
}
|
||||
else if (a = data['data']) {
|
||||
/*
|
||||
* Convert all dwords (longs) into bytes
|
||||
*/
|
||||
resource.aBytes = new Array(a.length * 4);
|
||||
for (i = 0, ib = 0; i < a.length; i++) {
|
||||
resource.aBytes[ib++] = a[i] & 0xff;
|
||||
resource.aBytes[ib++] = (a[i] >> 8) & 0xff;
|
||||
resource.aBytes[ib++] = (a[i] >> 16) & 0xff;
|
||||
resource.aBytes[ib++] = (a[i] >> 24) & 0xff;
|
||||
}
|
||||
}
|
||||
else {
|
||||
resource.aBytes = data;
|
||||
}
|
||||
|
||||
resource.aSymbols = data['symbols'];
|
||||
|
||||
if (!resource.aBytes.length) {
|
||||
Component.error("Empty resource: " + sURL);
|
||||
resource = null;
|
||||
}
|
||||
else if (resource.aBytes.length == 1) {
|
||||
Component.error(resource.aBytes[0]);
|
||||
resource = null;
|
||||
}
|
||||
} catch (e) {
|
||||
Component.error("Resource data error (" + sURL + "): " + e.message);
|
||||
resource = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Parse the data manually; we assume it's a series of hex byte-values separated by whitespace.
|
||||
*/
|
||||
var ab = [];
|
||||
var sHexData = sData.replace(/\n/gm, " ").replace(/ +$/, "");
|
||||
var asHexData = sHexData.split(" ");
|
||||
for (i = 0; i < asHexData.length; i++) {
|
||||
var n = parseInt(asHexData[i], 16);
|
||||
if (isNaN(n)) {
|
||||
Component.error("Resource data error (" + sURL + "): invalid hex byte (" + asHexData[i] + ")");
|
||||
break;
|
||||
}
|
||||
ab.push(n & 0xff);
|
||||
}
|
||||
if (i == asHexData.length) resource.aBytes = ab;
|
||||
}
|
||||
return resource;
|
||||
};
|
||||
|
||||
/**
|
||||
* sendReport(sApp, sVer, sURL, sUser, sType, sReport, sHostName)
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue