Skip to content

Commit

Permalink
Merge pull request #112 from MattMatic/Fix-JavaScript-browser-issues
Browse files Browse the repository at this point in the history
Fix browser issues with 0.4.x
  • Loading branch information
khaledhosny authored Dec 19, 2024
2 parents eee3c3e + 70969a5 commit ebb06e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ em++ \
-DHB_EXPERIMENTAL_API \
--no-entry \
-s MODULARIZE \
-s EXPORT_NAME=createHarfBuzz \
-s [email protected] \
-s EXPORTED_RUNTIME_METHODS='["addFunction", "wasmMemory", "wasmExports"]' \
-s INITIAL_MEMORY=65MB \
Expand Down
9 changes: 6 additions & 3 deletions examples/hbjs.example.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<script src="../hb.js"></script>
<script src="../hbjs.js"></script>
<script src="hbjs.example.js"></script>
<script>
// instantiateStreaming isn't supported in Safari yet, see nohbjs.html
WebAssembly.instantiateStreaming(fetch("../hb.wasm")).then(function (result) {

let harfBuzzModule; // not really needed with the hbjs wrapper
createHarfBuzz().then(hbmodule=>{
harfBuzzModule = hbmodule;
fetch('../test/fonts/noto/NotoSans-Regular.ttf').then(function (x) {
return x.arrayBuffer();
}).then(function (blob) {
document.body.innerText = JSON.stringify(example(hbjs(result.instance), new Uint8Array(blob)), undefined, 2);
document.body.innerText = JSON.stringify(example(hbjs(hbmodule), new Uint8Array(blob)), undefined, 2);
document.body.style.whiteSpace = 'pre';
});
});
Expand Down
13 changes: 5 additions & 8 deletions examples/nohbjs.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<!DOCTYPE html>
<script src="../hb.js"></script>
<script>
var utf8Encoder = new TextEncoder("utf8");

// We could use instantiateStreaming but it's not supported in Safari yet
// https://bugs.webkit.org/show_bug.cgi?id=173105
fetch("../hb.wasm").then(function (x) {
return x.arrayBuffer();
}).then(function (wasm) {
return WebAssembly.instantiate(wasm);
}).then(function (result) {
var exports = result.instance.exports;
let harfBuzzModule;
createHarfBuzz().then(hbmodule=>{
harfBuzzModule = hbmodule;
var exports = hbmodule.wasmExports;

fetch('../test/fonts/noto/NotoSans-Regular.ttf').then(function (x) {
return x.arrayBuffer();
Expand Down

0 comments on commit ebb06e0

Please sign in to comment.