Ai
1 Star 0 Fork 0

lol/node-ffi-napi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
function.js 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
Tim Perry 提交于 2020-04-22 23:16 +08:00 . Prebuild and publish binaries (#63)
'use strict';
const assert = require('assert');
const ref = require('ref-napi');
const ffi = require('../');
const bindings = require('node-gyp-build')(__dirname);
describe('Function "type"', function () {
afterEach(global.gc);
it('should be a function', function () {
assert.strictEqual('function', typeof ffi.Function);
});
var voidFn = ffi.Function('void', []);
it('should return a "type" object when invoked with a return type and array of arguments types', function () {
assert(voidFn);
assert.strictEqual('function', typeof voidFn.get);
assert.strictEqual('function', typeof voidFn.set);
});
it('should be accepted as a return "type" to a ForeignFunction', function () {
ffi.ForeignFunction(ref.NULL, voidFn, []);
});
it('should be accepted as an argument "type" to a ForeignFunction', function () {
ffi.ForeignFunction(ref.NULL, 'void', [ voidFn ])
});
it('should work as expected using the "callback_func" static bindings', function () {
const fn = ffi.Function('int', [ 'int' ]);
const callback_func = ffi.ForeignFunction(bindings.callback_func, fn, [ fn ]);
const abs = callback_func(Math.abs);
assert.strictEqual('function', typeof abs);
assert.strictEqual(Math.abs(-5), abs(-5));
assert.strictEqual(Math.abs(-9), abs(-9));
assert.strictEqual(Math.abs(-69), abs(-69));
assert.strictEqual(Math.abs(3), abs(3));
});
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wcp_code/node-ffi-napi.git
git@gitee.com:wcp_code/node-ffi-napi.git
wcp_code
node-ffi-napi
node-ffi-napi
master

搜索帮助