Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions hbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,23 @@ function hbjs(Module) {
return trace;
}

function get_version() {
function version() {
var major = exports.malloc(4);
var minor = exports.malloc(4);
var micro = exports.malloc(4);
exports.hb_version(major, minor, micro);
var version = {
major: heapu32[major / 4],
minor: heapu32[minor / 4],
micro: heapu32[micro / 4],
};
exports.free(major);
exports.free(minor);
exports.free(micro);
return version;
}

function version_string() {
var versionPtr = exports.hb_version_string();
var version = utf8Decoder.decode(heapu8.subarray(versionPtr, heapu8.indexOf(0, versionPtr)));
return version;
Expand All @@ -546,7 +562,8 @@ function hbjs(Module) {
createBuffer: createBuffer,
shape: shape,
shapeWithTrace: shapeWithTrace,
version: get_version(),
version: version,
version_string: version_string,
};
}

Expand Down
11 changes: 9 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,15 @@ describe('shape', function () {
});

describe('misc', function () {
it('get version', function () {
const version = hb.version();
expect(version).to.have.property('major').that.is.a('number');
expect(version).to.have.property('minor').that.is.a('number');
expect(version).to.have.property('micro').that.is.a('number');
expect(version.major).to.be.at.least(10);
});
it('get version string', function () {
const version = hb.version
expect(version).to.match(/^\d+\.\d+\.\d+$/);
const version_string = hb.version_string();
expect(version_string).to.match(/^\d+\.\d+\.\d+$/);
});
});