lib/browser/delegate_native.rb in isomorfeus-preact-10.6.23 vs lib/browser/delegate_native.rb in isomorfeus-preact-10.6.24
- old
+ new
@@ -24,15 +24,25 @@
property_name = property_for_message(message)
%x{
let value = #@native[#{property_name}];
let type = typeof(value);
- if (type === 'function') {
- return value.apply(#@native, args);
- } else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
- return nil;
- }
- return value;
+ try {
+ if (type === 'function') {
+ return value.apply(#@native, args);
+ } else if (type === 'object' && (value instanceof HTMLCollection)) {
+ let a = [];
+ for(let i=0; i<value.length; i++) {
+ a[i] = #{Browser::Element.new(`value.item(i)`)};
+ }
+ value = a;
+ } else if (type === 'object' && (value instanceof HTMLElement)) {
+ value = #{Browser::Element.new(value)};
+ } else if (value === null || type === 'undefined' || (type === 'number' && isNaN(value))) {
+ return nil;
+ }
+ return value;
+ } catch { return value; }
}
end
end
def respond_to_missing? message, include_all