From 2e3baa2ae516aebcaf51378d7c40cd96bb925bc0 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Fri, 5 Nov 2021 11:31:12 +0100 Subject: [PATCH] Move allocations around so there's nothing to clean up when hb_subset_input_create_or_fail returns 0 https://github.com/papandreou/subset-font/pull/13#discussion_r743354527 --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index dfccf82..ba08ff2 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,13 @@ async function subsetFont( originalFont = await fontverter.convert(originalFont, 'truetype'); + const input = exports.hb_subset_input_create_or_fail(); + if (input === 0) { + throw new Error( + 'hb_subset_input_create_or_fail (harfbuzz) returned zero, indicating failure' + ); + } + const fontBuffer = exports.malloc(originalFont.byteLength); heapu8.set(new Uint8Array(originalFont), fontBuffer); @@ -42,13 +49,6 @@ async function subsetFont( const face = exports.hb_face_create(blob, 0); exports.hb_blob_destroy(blob); - const input = exports.hb_subset_input_create_or_fail(); - if (input === 0) { - throw new Error( - 'hb_subset_input_create_or_fail (harfbuzz) returned zero, indicating failure' - ); - } - if (preserveNameIds) { const inputNameIds = exports.hb_subset_input_set( input,