Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Look into enabling TC39 weak references support in wasm-bindgen
https://rustwasm.github.io/wasm-bindgen/reference/weak-references.html

To avoid manual `.free()` calls to free memory.


Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index cc81f1dd9..00375e891 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ target/
 Cargo.lock
 bin/
 pkg/
+pkg-browser/
 wasm-pack.log
 .metals
 .vscode/
diff --git a/bindings/ergo-lib-wasm/Cargo.toml b/bindings/ergo-lib-wasm/Cargo.toml
index df10a8756..76123a375 100644
--- a/bindings/ergo-lib-wasm/Cargo.toml
+++ b/bindings/ergo-lib-wasm/Cargo.toml
@@ -42,8 +42,8 @@ derive_more = { workspace = true }
 num-traits = { workspace = true }
 serde_with = { workspace = true }
 bounded-vec = { workspace = true, features=["serde"] }
-wasm-bindgen = { version = "0.2.83", features = [] }
-wasm-bindgen-futures = { version = "0.4.33" }
+wasm-bindgen = { version = "0.2.84", features = [] }
+wasm-bindgen-futures = { version = "0.4.34" }
 
 [dev-dependencies]
 wasm-bindgen-test = { workspace = true }
diff --git a/bindings/ergo-lib-wasm/package.json b/bindings/ergo-lib-wasm/package.json
index 2aa8daccd..a3053bfea 100644
--- a/bindings/ergo-lib-wasm/package.json
+++ b/bindings/ergo-lib-wasm/package.json
@@ -4,14 +4,14 @@
     "browser": "./index.browser.js",
     "scripts": {
         "build": "webpack",
-        "serve": "wasm-pack build --target browser && webpack-dev-server",
-        "test": "wasm-pack build --target nodejs && mocha --require @babel/register --require @babel/polyfill 'tests/test*.js'",
+        "serve": "cross-env WASM_BINDGEN_WEAKREF=1 wasm-pack build --target browser && webpack-dev-server",
+        "test": "cross-env WASM_BINDGEN_WEAKREF=1 wasm-pack build --target nodejs && mocha --require @babel/register --require @babel/polyfill 'tests/test*.js'",
         "test-browser": "rm -rf ./pkg && npm run build-browser && mv ./pkg-browser ./pkg && ./node_modules/.bin/karma start",
         "doc": "jsdoc -c jsdoc.json pkg/ergo_wallet_wasm.js README.md -d docs",
-        "build-nodejs": "rm -rf ./pkg-nodejs && wasm-pack build --target nodejs --out-dir pkg-nodejs && cd pkg-nodejs && node ../scripts/publish_helper -nodejs",
-        "build-nodejs-alpha": "rm -rf ./pkg-nodejs && wasm-pack build --target nodejs --out-dir pkg-nodejs && cd pkg-nodejs && node ../scripts/publish_helper -nodejs && npm version minor && node ../scripts/set_alpha_version -nodejs $(git rev-parse --short HEAD)",
-        "build-browser": "rm -rf ./pkg-browser && wasm-pack build --target browser --out-dir pkg-browser --features rest && cd pkg-browser && node ../scripts/publish_helper -browser && node ../scripts/set_exports",
-        "build-browser-alpha": "rm -rf ./pkg-browser && wasm-pack build --target browser --out-dir pkg-browser --features rest && cd pkg-browser && node ../scripts/publish_helper -browser && node ../scripts/set_exports && npm version minor && node ../scripts/set_alpha_version -browser $(git rev-parse --short HEAD)",
+        "build-nodejs": "rm -rf ./pkg-nodejs && cross-env WASM_BINDGEN_WEAKREF=1 wasm-pack build --target nodejs --out-dir pkg-nodejs && cd pkg-nodejs && node ../scripts/publish_helper -nodejs",
+        "build-nodejs-alpha": "rm -rf ./pkg-nodejs && cross-env WASM_BINDGEN_WEAKREF=1 wasm-pack build --target nodejs --out-dir pkg-nodejs && cd pkg-nodejs && node ../scripts/publish_helper -nodejs && npm version minor && node ../scripts/set_alpha_version -nodejs $(git rev-parse --short HEAD)",
+        "build-browser": "rm -rf ./pkg-browser && cross-env WASM_BINDGEN_WEAKREF=1 wasm-pack build --target browser --out-dir pkg-browser --features rest && cd pkg-browser && node ../scripts/publish_helper -browser && node ../scripts/set_exports",
+        "build-browser-alpha": "rm -rf ./pkg-browser && cross-env WASM_BINDGEN_WEAKREF=1 wasm-pack build --target browser --out-dir pkg-browser --features rest && cd pkg-browser && node ../scripts/publish_helper -browser && node ../scripts/set_exports && npm version minor && node ../scripts/set_alpha_version -browser $(git rev-parse --short HEAD)",
         "publish-nodejs": "npm run build-nodejs &&  cd pkg-nodejs && npm publish",
         "publish-browser": "npm run build-browser && cd pkg-browser && npm publish"
     },
@@ -24,6 +24,7 @@
         "babel-cli": "^6.26.0",
         "babel-loader": "^8.2.3",
         "chai": "^4.2.0",
+        "cross-env": "^7.0.3",
         "jsdoc": "~3.6.3",
         "karma": "^6.3.13",
         "karma-chai": "^0.1.0",


Test patch: