JS Generics: Add a NodeMap proxy builder

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2020-02-21 18:40:16 +00:00
parent 2325062ff1
commit b23063bb52
No known key found for this signature in database
GPG Key ID: C30DF439F2987D74

View File

@ -27,6 +27,29 @@ var NetSurf = {
}, },
}); });
}, },
/* The make-proxy call for nodemap-type objects */
makeNodeMapProxy: function(inner) {
return new Proxy(inner, {
has: function(target, key) {
if (typeof key == 'number') {
return (key >= 0) && (key < target.length);
} else {
return target.getNamedItem(key) || (key in target);
}
},
get: function(target, key) {
if (typeof key == 'number') {
return target.item(key);
} else {
var attr = target.getNamedItem(key);
if (attr) {
return attr;
}
return target[key];
}
},
});
},
consoleFormatter: function Formatter() { consoleFormatter: function Formatter() {
if (arguments.length == 0) { if (arguments.length == 0) {