Skip to content

Commit 2987473

Browse files
committed
Add hb.version() and rename hb.version to hb.version_string()
hb.version() returns an object with major, minor, and micro properties as numbers, while hb.version_string() returns a string.
1 parent 5df5473 commit 2987473

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

hbjs.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,23 @@ function hbjs(Module) {
533533
return trace;
534534
}
535535

536-
function get_version() {
536+
function version() {
537+
var major = exports.malloc(4);
538+
var minor = exports.malloc(4);
539+
var micro = exports.malloc(4);
540+
exports.hb_version(major, minor, micro);
541+
var version = {
542+
major: heapu32[major / 4],
543+
minor: heapu32[minor / 4],
544+
micro: heapu32[micro / 4],
545+
};
546+
exports.free(major);
547+
exports.free(minor);
548+
exports.free(micro);
549+
return version;
550+
}
551+
552+
function version_string() {
537553
var versionPtr = exports.hb_version_string();
538554
var version = utf8Decoder.decode(heapu8.subarray(versionPtr, heapu8.indexOf(0, versionPtr)));
539555
return version;
@@ -546,7 +562,8 @@ function hbjs(Module) {
546562
createBuffer: createBuffer,
547563
shape: shape,
548564
shapeWithTrace: shapeWithTrace,
549-
version: get_version(),
565+
version: version,
566+
version_string: version_string,
550567
};
551568
}
552569

test/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,15 @@ describe('shape', function () {
249249
});
250250

251251
describe('misc', function () {
252+
it('get version', function () {
253+
const version = hb.version();
254+
expect(version).to.have.property('major').that.is.a('number');
255+
expect(version).to.have.property('minor').that.is.a('number');
256+
expect(version).to.have.property('micro').that.is.a('number');
257+
expect(version.major).to.be.at.least(10);
258+
});
252259
it('get version string', function () {
253-
const version = hb.version
254-
expect(version).to.match(/^\d+\.\d+\.\d+$/);
260+
const version_string = hb.version_string();
261+
expect(version_string).to.match(/^\d+\.\d+\.\d+$/);
255262
});
256263
});

0 commit comments

Comments
 (0)