ruby/ruby.wasm

Uncaught TypeError: FinalizationRegistry: cleanup must be callable

Closed this issue · 2 comments

Issue

I cannot make app work with locally build ruby.wasm. I built the wasm binary by issuing: bundle exec rbwasm build -o ruby.wasm

This is my project.

Gemfile:

# frozen_string_literal: true

source "https://rubygems.org"

# Gemfile
gem 'ruby_wasm'
gem 'victor', '~> 0.5.0'

Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    ruby_wasm (2.7.1)
    ruby_wasm (2.7.1-aarch64-linux)
    ruby_wasm (2.7.1-aarch64-linux-musl)
    ruby_wasm (2.7.1-arm64-darwin)
    ruby_wasm (2.7.1-x86_64-darwin)
    ruby_wasm (2.7.1-x86_64-linux)
    ruby_wasm (2.7.1-x86_64-linux-musl)
    victor (0.5.0)

PLATFORMS
  aarch64-linux
  aarch64-linux-musl
  arm64-darwin
  ruby
  x86_64-darwin
  x86_64-linux
  x86_64-linux-musl

DEPENDENCIES
  ruby_wasm
  victor (~> 0.5.0)

BUNDLED WITH
   2.6.2

index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Ruby WASM</title>
  </head>
  <body></body>
  <script type="module" src="index.js"></script>
</html>

index.js:

import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.1/dist/browser/+esm";
const response = await fetch("./ruby.wasm");
const module = await WebAssembly.compileStreaming(response);
const { vm } = await DefaultRubyVM(module);

vm.eval(`
  require "js"

  JS.global[:document].write "TEST"
`);

Result

What I get in the JS console is: Uncaught TypeError: FinalizationRegistry: cleanup must be callable.

When I try it with the cdn binary as documented in the cheat sheet every thing works without any issues.

What I want

What I want to achieve in the end is to execute a simple script:

# app.rb
require 'victor'

svg = Victor::SVG.new width: 100, height: 100

svg.build do
  rect x: 10, y: 10, width: 80, height: 80, fill: 'blue'
  circle cx: 50, cy: 50, r: 30, fill: 'green'
end

puts svg.render

Thank you for reporting. Could you try adding gem "js" to your Gemfile and rebuild the wasm again?

Thanks a lot this fixed it :) I'm closing the issue :)