Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm_exec.js not working in Gnome3+ Extensions #41482

Closed
abergmeier opened this issue Sep 18, 2020 · 6 comments
Closed

wasm_exec.js not working in Gnome3+ Extensions #41482

abergmeier opened this issue Sep 18, 2020 · 6 comments
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@abergmeier
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.15 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

"use strict";

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const St = imports.gi.St;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;

// This imports wasm_exec.js
const WasmExec = Me.imports.wasm_exec; 

const go = new WasmExec.Go();
WebAssembly.instantiateStreaming(fetch("foo.wasm"), go.importObject).then((result) => {
    go.run(result.instance);
});

What did you expect to see?

Should load just fine.

What did you see instead?

Errors with:

Sep 18 20:19:02 9300 gnome-shell[5474]: JS ERROR: Extension stackdriver@abergmeier.github.com: ReferenceError: require is not defined
                                        @/home/andreas/.local/share/gnome-shell/extensions/stackdriver@abergmeier.github.com/wasm_exec.js:105:22
                                        @/home/andreas/.local/share/gnome-shell/extensions/stackdriver@abergmeier.github.com/wasm_exec.js:588:3
                                        @/home/andreas/.local/share/gnome-shell/extensions/stackdriver@abergmeier.github.com/extension.js:13:18

Seems like the problem is with using

const nodeCrypto = require("crypto");

So probably there is the need to define a require.

@abergmeier
Copy link
Author

Working on that in abergmeier#1

@agnivade agnivade added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. arch-wasm WebAssembly issues labels Sep 19, 2020
@agnivade
Copy link
Contributor

Thanks for the report. Yet another environment to support :)

/cc @neelance

@neelance
Copy link
Member

We can check for the existence of require, but that won't help you much. Your environment needs to provide crypto.getRandomValues as well as TextEncoder and TextDecoder. You should polyfill them.

@abergmeier
Copy link
Author

We can check for the existence of require, but that won't help you much. Your environment needs to provide crypto.getRandomValues as well as TextEncoder and TextDecoder. You should polyfill them.

I have require hooked up. There are polyfills for TextEncoder and TextDecoder in place.
Currently I have problems hooking up hrettimer.

Now even though I might be able to fix all this (an then have to get through the horrible Gerrit process), how would we test, that this does not break with future GJS/Golang releases?

@abergmeier
Copy link
Author

Will take the more portable browser implementation now. And thus the current js implementation should be sufficient.

@gopherbot
Copy link

Change https://golang.org/cl/261357 mentions this issue: misc/wasm: improve error message if javascript polyfills are required

gopherbot pushed a commit that referenced this issue Oct 21, 2020
wasm_exec.js expects that either "require" is available or that the
globals "crypto", "TextEncoder" and "TextDecoder" are already defined.
Report a better error message if this is not the case, suggesting the
use of a polyfill.

Updates #41482

Change-Id: I5473cae15c98ae42e39f5928245b7762e7a5a8bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/261357
Trust: Richard Musiol <neelance@gmail.com>
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
@golang golang locked and limited conversation to collaborators Oct 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants