From a8cdcde89a77f314647743a4c3551fa2c9571cbf Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 18 Sep 2018 19:01:52 +0200 Subject: [PATCH] Fix: If opensslLoaded function is undefined don't call it Signed-off-by: Knut Ahlers --- README.md | 2 +- main.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 576e3b4..25337ea 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Afterwards in your HTML you can include the `wasm_exec.js` and load the binary: ``` -Be sure to have a top-level function `opensslLoaded()` defined as this will be called in the initialization of the `openssl.wasm`. This serves as a notification you do have now access to the top-level functions `encrypt` and `decrypt`: +If you have a top-level function `opensslLoaded()` defined, this will be called in the initialization of the `openssl.wasm`. This serves as a notification you do have now access to the top-level functions `encrypt` and `decrypt`: ```javascript function decrypt(ciphertext, passphrase, callback) {} diff --git a/main.go b/main.go index 67a9a92..95ec9ba 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,10 @@ func main() { js.Global().Set("encrypt", js.NewCallback(encrypt)) // Trigger custom "event" - js.Global().Call("opensslLoaded") + if js.Global().Get("opensslLoaded").Type() == js.TypeFunction { + js.Global().Call("opensslLoaded") + } + <-make(chan struct{}, 0) }