Skip to content

Commit

Permalink
Add hb.version() and rename hb.version to hb.version_string()
Browse files Browse the repository at this point in the history
hb.version() returns an array of [major, minor, patch] as numbers.
  • Loading branch information
khaledhosny committed Sep 24, 2024
1 parent 5df5473 commit 21c598b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
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 patch = exports.malloc(4);
exports.hb_version(major, minor, patch);
var version = [
heapu32[major / 4],
heapu32[minor / 4],
heapu32[patch / 4]
];
exports.free(major);
exports.free(minor);
exports.free(patch);
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
12 changes: 10 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,16 @@ describe('shape', function () {
});

describe('misc', function () {
it('get version', function () {
const version = hb.version();
expect(version).to.be.an('array');
expect(version).to.have.lengthOf(3);
expect(version[0]).is.a('number');
expect(version[1]).is.a('number');
expect(version[2]).is.a('number');
});
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+$/);
});
});

0 comments on commit 21c598b

Please sign in to comment.