[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-wallet-webex] 02/05: oops, actually pass arguments t
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-wallet-webex] 02/05: oops, actually pass arguments to emscripten |
Date: |
Fri, 16 Aug 2019 15:04:03 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-webex.
commit cc4eeec0318def17ac966be2d0ad8547ce782bc7
Author: Florian Dold <address@hidden>
AuthorDate: Fri Aug 16 00:15:19 2019 +0200
oops, actually pass arguments to emscripten
---
package.json | 2 +-
src/crypto/synchronousWorker.ts | 91 +++++++++++++++++++++++------------------
2 files changed, 52 insertions(+), 41 deletions(-)
diff --git a/package.json b/package.json
index 4068c5ef..a7dce61e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "taler-wallet",
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "",
"main": "dist/node/index.js",
"repository": {
diff --git a/src/crypto/synchronousWorker.ts b/src/crypto/synchronousWorker.ts
index 4d1ff964..c8ee3be1 100644
--- a/src/crypto/synchronousWorker.ts
+++ b/src/crypto/synchronousWorker.ts
@@ -24,7 +24,9 @@ import fs = require("fs");
*/
export class SynchronousCryptoWorker {
private cachedEmscEnvironment: EmscEnvironment | undefined = undefined;
- private cachedEmscEnvironmentPromise: Promise<EmscEnvironment> | undefined =
undefined;
+ private cachedEmscEnvironmentPromise:
+ | Promise<EmscEnvironment>
+ | undefined = undefined;
/**
* Function to be called when we receive a message from the worker thread.
@@ -64,52 +66,61 @@ export class SynchronousCryptoWorker {
return this.cachedEmscEnvironmentPromise;
}
- // Make sure that TypeScript doesn't try
- // to check the taler-emscripten-lib.
- const indirectRequire = require;
+ const binaryPath =
+ __dirname + "/../../../emscripten/taler-emscripten-lib.wasm";
+ console.log("reading from", binaryPath);
+ const wasmBinary = new Uint8Array(fs.readFileSync(binaryPath));
- const g = global;
+ let lib: any;
+
+ return new Promise((resolve, reject) => {
+ // Arguments passed to the emscripten prelude
+ const libArgs = {
+ wasmBinary,
+ onRuntimeInitialized: () => {
+ if (!lib) {
+ console.error("fatal emscripten initialization error");
+ return;
+ }
+ this.cachedEmscEnvironmentPromise = undefined;
+ this.cachedEmscEnvironment = new EmscEnvironment(lib);
+ resolve(this.cachedEmscEnvironment);
+ },
+ };
- // unavoidable hack, so that emscripten detects
- // the environment as node even though importScripts
- // is present.
+ // Make sure that TypeScript doesn't try
+ // to check the taler-emscripten-lib.
+ const indirectRequire = require;
- // @ts-ignore
- const savedImportScripts = g.importScripts;
- // @ts-ignore
- delete g.importScripts;
+ const g = global;
- // Assume that the code is run from the build/ directory.
- const libFn = indirectRequire(
- "../../../emscripten/taler-emscripten-lib.js",
- );
- const lib = libFn();
- // @ts-ignore
- g.importScripts = savedImportScripts;
+ // unavoidable hack, so that emscripten detects
+ // the environment as node even though importScripts
+ // is present.
- if (!lib) {
- throw Error("could not load taler-emscripten-lib.js");
- }
+ // @ts-ignore
+ const savedImportScripts = g.importScripts;
+ // @ts-ignore
+ delete g.importScripts;
- if (!lib.ccall) {
- throw Error(
- "sanity check failed: taler-emscripten lib does not have 'ccall'",
+ // Assume that the code is run from the build/ directory.
+ const libFn = indirectRequire(
+ "../../../emscripten/taler-emscripten-lib.js",
);
- }
-
- const binaryPath = __dirname +
"/../../../emscripten/taler-emscripten-lib.wasm";
- console.log("reading from", binaryPath);
- const wasmBinary = new Uint8Array(fs.readFileSync(binaryPath));
-
- this.cachedEmscEnvironmentPromise = new Promise((resolve, reject) => {
- lib.wasmBinary = wasmBinary;
- lib.onRuntimeInitialized = () => {
- this.cachedEmscEnvironmentPromise = undefined;
- this.cachedEmscEnvironment = new EmscEnvironment(lib);
- resolve(this.cachedEmscEnvironment);
- };
+ const lib = libFn(libArgs);
+ // @ts-ignore
+ g.importScripts = savedImportScripts;
+
+ if (!lib) {
+ throw Error("could not load taler-emscripten-lib.js");
+ }
+
+ if (!lib.ccall) {
+ throw Error(
+ "sanity check failed: taler-emscripten lib does not have 'ccall'",
+ );
+ }
});
- return this.cachedEmscEnvironmentPromise;
}
private dispatchMessage(msg: any) {
@@ -157,7 +168,7 @@ export class SynchronousCryptoWorker {
return;
}
- this.handleRequest(operation, id, args).catch((e) => {
+ this.handleRequest(operation, id, args).catch(e => {
console.error("Error while handling crypto request:", e);
});
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [taler-wallet-webex] branch master updated (ea2fb677 -> a1e0fc3b), gnunet, 2019/08/16
- [GNUnet-SVN] [taler-wallet-webex] 01/05: load wasm manually from correct location, gnunet, 2019/08/16
- [GNUnet-SVN] [taler-wallet-webex] 04/05: load wasm binary for akono, gnunet, 2019/08/16
- [GNUnet-SVN] [taler-wallet-webex] 03/05: emscripten env consistency, gnunet, 2019/08/16
- [GNUnet-SVN] [taler-wallet-webex] 02/05: oops, actually pass arguments to emscripten,
gnunet <=
- [GNUnet-SVN] [taler-wallet-webex] 05/05: crypto worker refactoring, gnunet, 2019/08/16