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

Comments

@abergmeier
Copy link

@abergmeier abergmeier commented Sep 18, 2020

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

@abergmeier abergmeier commented Sep 19, 2020

Working on that in abergmeier#1

@agnivade
Copy link
Contributor

@agnivade agnivade commented Sep 19, 2020

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

/cc @neelance

@neelance
Copy link
Member

@neelance neelance commented Sep 19, 2020

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

@abergmeier abergmeier commented Sep 19, 2020

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

@abergmeier abergmeier commented Sep 19, 2020

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

@abergmeier abergmeier closed this Sep 19, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 11, 2020

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.