I want to parse some nasty Mork data from Thunderbird. I found Javascript class and want to use the code in JavaScriptEngineMBS. However, my JavaScript is a bit basic and I can’t make sense of the error I get.
The line “for (let pair of pairs)” make an error “unexpected token pair”. As far as I understand the code “var pairs” makes an array with split. The “for (let pair of pairs)” should be something like an “for each pair in pairs” in Xojo.
function mork_parse_value_table(section, val_part) {
if (!val_part) {
return { };
}
//Extract pairs (key=value)
var pairs = val_part.split(/\(([^\)]+)\)/g);
for (let pair of pairs) {
//Skip empty line
if (pair.trim().length == 0) {
continue;
}
var m = /([\dA-F]*)[\t\n ]*=[\t\n ]*([\S\s]*)/gi.exec(pair);
if (!m) {
continue;
}
key = m[1];
val = m[2];
if (!val || val.trim().length == 0) {
//console.error(section + ": unparsable value: " + pair);
//continue;
}
//Approximate wchar_t -> ASCII and remove NULs
//val = mork_fix_encoding(val);
self.val_table[key] = val;
}
return self.val_table;
}
Some old javascript engines don’t handle “let”. You can try replacing it with “var”. However, old javascript engines may also not support the “for…of” construct.
You could rewrite it like this:
//Extract pairs (key=value)
var pairs = val_part.split(/\(([^\)]+)\)/g);
for (let pair of pairs) {
...
→
//Extract pairs (key=value)
var pairs = val_part.split(/\(([^\)]+)\)/g);
for (var i = 0; i < pairs.length ; i++) {
var pair = pairs[i];
...
JavaScriptEngineMBS uses DukTape, which is barely passable as a JavaScript engine. It has only “partial” support for ES6, which means most modern JavaScript won’t run in it.
Interesting - one of my products uses the HTMLViewer under Windows, which (if you set it up properly) supports IE11. As long as you are careful to avoid “newfangled” ES6 ideas, the IE11 engine is solid.
Sound like this DukTape thing is even worse though
Well, if JavaScriptEngineMBS class doesn’t do enough for you, maybe check JSContextMBS class instead. That is the engine from WebKit, which can run cross platform, even on Windows.