gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-wallet-webex] branch master updated: fix emscripten


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated: fix emscripten module loading in node
Date: Sat, 27 May 2017 19:04:15 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-webex.

The following commit(s) were added to refs/heads/master by this push:
     new 592fd624 fix emscripten module loading in node
592fd624 is described below

commit 592fd62402b7f0fdb8dbe08605381d3a74d929f2
Author: Florian Dold <address@hidden>
AuthorDate: Sat May 27 19:04:07 2017 +0200

    fix emscripten module loading in node
---
 src/crypto/emscLoader.js | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/crypto/emscLoader.js b/src/crypto/emscLoader.js
index 723b8ae3..eebe20c0 100644
--- a/src/crypto/emscLoader.js
+++ b/src/crypto/emscLoader.js
@@ -17,22 +17,41 @@
 
 // @ts-nocheck
 
+
+/**
+ * This module loads the emscripten library, and is written in unchecked
+ * JavaScript since it needs to do environment detection and dynamically select
+ * the right way to load the library.
+ */
+
 /**
  * Load the taler emscripten lib.
  *
- * If in a WebWorker, importScripts is used.  Inside a browser,
- * the module must be globally available.
+ * If in a WebWorker, importScripts is used.  Inside a browser, the module must
+ * be globally available.  Inside node, require is used.
  */
-export default function getLib() {
-  if (window.TalerEmscriptenLib) {
-    return TalerEmscriptenLib;
-  }
-  if (importScripts) {
+export function getLib() {
+  if (typeof importScripts !== "undefined") {
     importScripts('/src/emscripten/taler-emscripten-lib.js')
     if (TalerEmscriptenLib) {
       throw Error("can't import TalerEmscriptenLib");
     }
     return TalerEmscriptenLib
   }
-  throw Error("Can't find TalerEmscriptenLib.");
+
+  if (typeof require !== "undefined") {
+    // Make sure that TypeScript doesn't try
+    // to check the taler-emscripten-lib.
+    const fn = require;
+    // Assume that the code is run from the build/ directory.
+    return fn("../../../emscripten/taler-emscripten-lib.js");
+  }
+
+  if (typeof window !== "undefined") {
+    if (window.TalerEmscriptenLib) {
+      return TalerEmscriptenLib;
+    }
+    throw Error("Looks like running in browser, but TalerEmscriptenLib is not 
defined");
+  }
+  throw Error("Running in unsupported environment");
 }

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]