netsurf/content/handlers/javascript/duktape/generics.js
Daniel Silverstone 6dfc0f1486 Support nodelist indexing
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
2019-05-04 23:06:20 +01:00

31 lines
705 B
JavaScript

/*
* Generics for Duktape binding in NetSurf
*
* The result of this *MUST* be setting a NetSurf object only.
*
* That object will then be absorbed into the global object as a hidden
* object which is used by the rest of the bindings.
*/
var NetSurf = {
/* The make-proxy call for list-type objects */
makeListProxy: function(inner) {
return new Proxy(inner, {
has: function(target, key) {
if (typeof key == 'number') {
return (key >= 0) && (key < target.length);
} else {
return key in target;
}
},
get: function(target, key) {
if (typeof key == 'number') {
return target.item(key);
} else {
return target[key];
}
},
});
},
};