mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-03 09:44:24 +03:00
JS Generics: Add a NodeMap proxy builder
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
parent
2325062ff1
commit
b23063bb52
@ -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() {
|
||||
|
||||
if (arguments.length == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user