Permalink
Browse files

type: recurse up the prototype chain to type to find the `ffi_type` t…

…o use

Makes the "long" and "ulong" types work.
  • Loading branch information...
1 parent ff70171 commit e538361b9a351a2840f2e4b8e341ef983af41ce2 @TooTallNate TooTallNate committed Apr 6, 2013
Showing with 14 additions and 1 deletion.
  1. +5 −1 lib/type.js
  2. +9 −0 test/types.js
View
6 lib/type.js
@@ -114,7 +114,11 @@ function Type (type) {
if ('CString' == type.name) {
rtn = type.ffi_type = bindings.FFI_TYPES.pointer
} else {
- rtn = type.ffi_type = bindings.FFI_TYPES[type.name]
+ var cur = type
+ while (!rtn && cur) {
+ rtn = cur.ffi_type = bindings.FFI_TYPES[cur.name]
+ cur = Object.getPrototypeOf(cur)
+ }
}
}
View
9 test/types.js
@@ -33,6 +33,15 @@ describe('types', function () {
assert(Buffer.isBuffer(ffi_type))
})
+ it('should match a valid `ffi_type` for `ulong` without a cached value', function () {
+ // simulate a ref type without a "ffi_type" property set
+ var type = Object.create(ref.types.ulong)
+ type.ffi_type = undefined
+
+ var ffi_type = ffi.ffiType(type)
+ assert(Buffer.isBuffer(ffi_type))
+ })
+
})
})

0 comments on commit e538361

Please sign in to comment.