From 63d9fac85cee4e28d0fbd62536113e1fc1d70085 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Thu, 29 Aug 2024 12:44:29 +0100 Subject: [PATCH 1/2] Add hb_version symbol and .version member --- hb.symbols | 1 + hbjs.js | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hb.symbols b/hb.symbols index b78e99b..2a8468a 100644 --- a/hb.symbols +++ b/hb.symbols @@ -45,5 +45,6 @@ _hb_set_destroy _hb_set_get_population _hb_set_next_many _hb_shape +_hb_version _malloc _free diff --git a/hbjs.js b/hbjs.js index c34eb21..ee05a79 100644 --- a/hbjs.js +++ b/hbjs.js @@ -533,15 +533,34 @@ function hbjs(Module) { return trace; } + function get_version() { + var major = exports.malloc(4); + var minor = exports.malloc(4); + var patch = exports.malloc(4); + heapu32[major / 4] = 0; + heapu32[minor / 4] = 0; + heapu32[patch / 4] = 0; + exports.hb_version(major, minor, patch); + let hbversion = + heapu32[major / 4] + "." + heapu32[minor / 4] + "." + heapu32[patch / 4]; + exports.free(major); + exports.free(minor); + exports.free(patch); + return hbversion; + } + return { createBlob: createBlob, createFace: createFace, createFont: createFont, createBuffer: createBuffer, shape: shape, - shapeWithTrace: shapeWithTrace + shapeWithTrace: shapeWithTrace, + version: get_version(), }; -}; +} // Should be replaced with something more reliable -try { module.exports = hbjs; } catch(e) {} +try { + module.exports = hbjs; +} catch (e) {} From 9a45b17e5570d983685996aea7f23511c2675380 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 29 Aug 2024 15:13:32 +0300 Subject: [PATCH 2/2] Use hb_version_string() and add a test --- hb.symbols | 1 + hbjs.js | 16 +++------------- test/index.js | 7 +++++++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/hb.symbols b/hb.symbols index 2a8468a..7d8fc76 100644 --- a/hb.symbols +++ b/hb.symbols @@ -46,5 +46,6 @@ _hb_set_get_population _hb_set_next_many _hb_shape _hb_version +_hb_version_string _malloc _free diff --git a/hbjs.js b/hbjs.js index ee05a79..5d07a38 100644 --- a/hbjs.js +++ b/hbjs.js @@ -534,19 +534,9 @@ function hbjs(Module) { } function get_version() { - var major = exports.malloc(4); - var minor = exports.malloc(4); - var patch = exports.malloc(4); - heapu32[major / 4] = 0; - heapu32[minor / 4] = 0; - heapu32[patch / 4] = 0; - exports.hb_version(major, minor, patch); - let hbversion = - heapu32[major / 4] + "." + heapu32[minor / 4] + "." + heapu32[patch / 4]; - exports.free(major); - exports.free(minor); - exports.free(patch); - return hbversion; + var versionPtr = exports.hb_version_string(); + var version = utf8Decoder.decode(heapu8.subarray(versionPtr, heapu8.indexOf(0, versionPtr))); + return version; } return { diff --git a/test/index.js b/test/index.js index 14f45ca..7a52dd6 100644 --- a/test/index.js +++ b/test/index.js @@ -247,3 +247,10 @@ describe('shape', function () { }); }); }); + +describe('misc', function () { + it('get version string', function () { + const version = hb.version + expect(version).to.match(/^\d+\.\d+\.\d+$/); + }); +});