Skip to content

Commit

Permalink
type: recurse up the prototype chain to type to find the ffi_type t…
Browse files Browse the repository at this point in the history
…o use

Makes the "long" and "ulong" types work.
  • Loading branch information
TooTallNate committed Apr 6, 2013
1 parent ff70171 commit e538361
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.