Questions tagged [webassembly]

0

votes
0

answer
3

Views

How can I import Emscripten generated .wasm/js files in files created with create-react-app

I have a library I can successfully build & run with the Emscripten generated .html files. I'd like to use it with React now, however, I get a MIME type error` which I can't fix. Here are the steps I take to generate the React app and .wasm files npx create-react-app stackoverflow DEST=stackoverfl...
Marvin Irwin
1

votes
1

answer
44

Views

How to get a file's content of UNO shared project as string

In regular C#/UWP it is possible without any (bigger) problems to read a file's (or resource's) content to a string variable. How is this done with the UNO platform's WebAssembly build target? What I already tried: According to the browser's debugging console, my code execution stops (without any ex...
Syntaxrabbit
0

votes
0

answer
7

Views

Golang's syscall/js js.NewCallback is undefined

I am new to both go and wasm and it looks like these projects are pretty fast moving. I was reading an introduction to using wasm in go and it seems although it was written in January, its already out of date. I am attempting to call a single go function when a JavaScript function is invoked. The ex...
w33t
1

votes
0

answer
7

Views

Problem connecting websocket from c++ compiled with emscripten

Trying to connect to websocket (poco-1.9.0 samples\WebSocketServer) using c++ code compiled with emscripten. Using compiled boost 1.69 and one of common examples to connect to socket. boost::asio::ssl::context ctxt(context::sslv23_client); ctxt.set_verify_mode(boost::asio::ssl::verify_none); boost:...
Laza
0

votes
1

answer
289

Views

Functions available to WebAssembly [closed]

Does anyone know of a list of functions which are available to call from WebAssembly when running in a modern web browser? Or perhaps the answer is that there are no such functions except the ones explicitly made available from JavaScript? Specifically, I would like to know if it is possible to read...
user1772004
1

votes
3

answer
132

Views

How to distribute web assembly package

I am using WebAssembly in a project. I would like to package the wasm part of the project into its own module and hopefully distribute the standalone binary. I've not found anything like a 'wasm repository' so far. It would be great for web developers to be able to include a 3rd party wasm binary in...
eric sherouse
1

votes
0

answer
43

Views

Error throwing when calling “call_indirect” in a function in WebAssembly module

I got an error 'RuntimeError: function signature mismatch' when calling the exported method 'func0'. So, what cause the problem? (module (table $t 10 anyfunc) (elem $t (offset (i32.const 0)) $func1 $func1) (memory $0 1) (export 'memory' (memory $0)) (export 'main' (func $main)) (export 'func1' (fun...
YHSPY
1

votes
0

answer
263

Views

How to produce .wasm file using emmake

I have this project skeleton on github The project allows to move a cursor using SDL lib. Which I want to port afterward into browser. The files were generated based on this turorial MouseMove/src/main.cpp: #include #include #include int main(int, char**){ if (SDL_Init(SDL_INIT_VIDEO) != 0){ std:...
deathangel908
1

votes
0

answer
67

Views

Where can I try the the new SIMD feature of WebAssembly?

Where can I try the the new SIMD feature of WebAssembly? Any other online instant WebAssembly compiling platform like Emscripten?
YHSPY
1

votes
1

answer
74

Views

Load .wasm object from memory [closed]

I have a tool chain, which sends sources from client side to the server and on the server generates .wasm and .js files and send it back with the response. I receive all this data in variables and then inject .js file into page but it tries to find the .wasm file on the root folder, but I only have...
jks1781
10

votes
3

answer
3.6k

Views

How to return a string (or similar) from Rust in WebAssembly?

I created a small WASM file from this Rust code: #[no_mangle] pub fn hello() -> &'static str { 'hello from rust' } It builds and the hello function can be called from JS: fetch('main.wasm') .then(response => response.arrayBuffer()) .then(bytes => WebAssembly.instantiate(bytes, {})) .then(results =>...
rap-2-h
1

votes
0

answer
70

Views

WebAssembly example forces browser to quit

I'm running a WebAssembly example with Emscripten that prints a message. The browser opens for a second, prints the message, and then closes. Here's my code: #include int main() { printf('Hello, World!'); return 0; } I'm compiling the code with emcc -s WASM=1 --emrun -o hello.html hello.c. When I l...
MatthewScarpino
1

votes
0

answer
174

Views

Web assembly : sending data from js to argv argument of C++ main function

I want to send an array of string to my 'main' C++ function. I have tried this: this.module = buildModule(args).then((res) => { const main = res.cwrap('main', 'number', ['number', 'array']) // create a pointer using the 'Glue' method and the String value const ptr1 = res.allocate(wasmBuild.intArrayF...
godot
1

votes
2

answer
629

Views

Electron WebAssembly: TypeError: Incorrect response MIME type. Expected 'application/wasm'

WebAssembly.instantiateStreaming fails when using a local relative path. Is there any way to disable this check or does anyone have any advice on another approach of getting around the problem? I'm trying to remove having the dependency of a web backend of my electron project. WebAssembly.instantiat...
James
1

votes
0

answer
270

Views

How to import wasm in web workers with webpack?

is it possible with webpack to import wasm in workers? In my normal js code i can import wasm like this: import('../wasm/hello_world.wasm').then(module => { console.log(module.add_one(9)) }) the same code does not work inside a worker. It returns the following error message: Uncaught TypeError: Cann...
Carsten
1

votes
1

answer
164

Views

How to Write a String to Memory in WebAssembly

I started off working like this: // example.wast (module (memory (export 'mem') 1)) // example.js WebAssembly.instantiateStreaming(fetch('example.wasm'), {}).then(mod => { var exports = mod.instance.exports var i8 = new Uint8Array(exports.mem) var ra = 100 var rb = 500 var rc = 1000 var rd = 1200 va...
Lance Pollard
1

votes
0

answer
84

Views

Standalone modules with emscripten

I'm trying to use emscripten to build a side module for my JS app, so I don't need all the glue code it generates by default, and can provide the rest myself. According to https://github.com/kripken/emscripten/wiki/WebAssembly-Standalone, most unnecessary dependencies will be removed automatically,...
riv
1

votes
0

answer
30

Views

Cleanup in WebWorker when page is closed

I have a WebAssembly module running in a WebWorker. This module contains a session key for encryption and other sensitive data I want to memzero before the page is closed. Is there any way to reliably do this for different Browsers? If not are there any good alternatives? I could intercept onbeforeu...
kamulos
1

votes
1

answer
61

Views

What is the smallest amount of code needed to use a wasm array

I have a c++ file that contains a function which does nothing but math. This function takes in an array as an argument and saves all it's results back into the same array. I can compile this with emscripten, and that would give me a working js and wasm file but the javascript it generates is fille...
YAHsaves
1

votes
1

answer
109

Views

How to generate import section in wasm?

When we comiple an c source file into wasm, there will be lots of import 'env' xxxx sections. For example, this is my c source file, char message[] = 'hello wasm!'; char* getMessageRef() { return message; } int getMessageLength() { return sizeof(message); } const int SIZE = 10; int data[SIZE]; void...
Duan Bing
1

votes
0

answer
330

Views

How do I create a WebAssembly.Memory in JS and then access it in C?

I have a demo fiddle online at https://webassembly.studio/?f=0r9gxzb9rdq where I'm using an array buffer that gets shared between JS and WebAssembly. As suggested in this answer How to access WebAssembly linear memory from C/C++, I'm declaring it as a global array that I'm reading and writing to, al...
jtiscione
1

votes
0

answer
102

Views

How to generate standalone webassembly with emscripten

The documentation offers two options: let optimizer strip unnecessary code and then replace the .js glue with your own, or use SIDE_MODULE flag. Both options result in a memory import (instead of export), and in the case of SIDE_MODULE a ton of extra imports/exports are also defined. Compare it to a...
riv
1

votes
0

answer
62

Views

WebAssemby char* to Javascript Blob

I have a project were I want to signal processing in WebAssembly. I can load a wav file using javascript and get the data in / parsed and processed in c++ WebAssembly. I then have a pointer that I can pass back to javascript to access via the heap buffer. But for some strange reason the offset is al...
Ian Knowles
1

votes
0

answer
52

Views

WebAssembly.instantiate() function

Was exploring web assembly a bit since it is now natively in all major browsers. Having some questions regarding the WebAssembly.instantiate() exactly work. Mozilla web docs state the following: The WebAssembly.instantiate() function allows you to compile and instantiate WebAssembly code. The func...
Willem van der Veen
1

votes
0

answer
267

Views

Creating a GUI with Glade and Webassembly

The Glade software is a visual editor for GUI development. The output is a XML file which can be used in a C++ application for user interaction. A normal C++ program is compiled to run on a desktop, for example in Fedora Linux. In contrast, the Webassembly standard has the aim to execute programs in...
Manuel Rodriguez
1

votes
0

answer
110

Views

Wasm: Uncaught (in promise) TypeError: Import #0 module=“env” error: module is not an object or function Promise.then (async) (anonymous) @ (index):9

I'm new to emscripten and find it very hard... I have obligation to work on windows because i have to test .exe versions of my apps. I'm on windows 7. I can compile wasm but javascript cannot read it. Here's my code. C code: char * HelloWorld () { return 'Hello World !'; } Emscripten command-line: e...
NonBinary
1

votes
0

answer
96

Views

How can I include a WebAssembly module from a C++ file?

WebAssembly is a binary language that intends to, among other goals, break the barriers between programming languages. Currently, it's easy enough to compile C++ code to WebAsm and include it into JavaScript code. There's even a proposal and a Webpack polyfill to make it as easy as import { foo } fr...
Narrateur du chaos
1

votes
0

answer
179

Views

How to use web RTC (p2p) in Wasm

How to send p2p data in Emscripten C++ -> native wasm? I can't find any Documentation for Sockets in wasm in general. What I found was this: https://github.com/kripken/emscripten/blob/master/tests/sockets/webrtc_peer.c and https://github.com/kripken/emscripten/blob/master/tests/sockets/webrtc_host.c...
K0IN
1

votes
0

answer
99

Views

Kotlin WebAssembly access DOM

I've got the following code in Kotlin import kotlinx.interop.wasm.dom.* import kotlinx.wasm.jsinterop.* fun main(args: Array) { val veryImportantCalculation = 42 //access the #wasm in html and append it to the element } which is compiled to wasmFunctions.wasm, and an extremely easy HTML: I need to p...
Dmitry Alexandrov
1

votes
0

answer
47

Views

Can you exploit emscripten-compiled Wasm to run arbitrary JavaScript?

I'm trying to understand the threat level of the following scenario in a web application: Web app contains a C++ component compiled to Wasm by Emscripten Runs 3rd party Wasm blobs (assume fully untrusted) Assume neither blob can call back to JS via import/export All Wasm blobs share memory So, obvio...
Vesa Norilo
1

votes
0

answer
31

Views

api key security for WebAssembly application

I know it's always a bad idea to put api key in frontend. We are designing a WebAssembly application which authenticates through Javascript api call. Other users can get the WebAssembly binary which we provide and build their own website if they have the api key. To alleviate the misuse, each key...
Yen
1

votes
2

answer
31

Views

How to get a filename renamed by Webpack?

I'm using a webassembly file compiled by Emscripten in my project. And since my project uses Webpack, it renames all files, then the Emscripten module can't find more the webassembly file. Then I need to get the new filename of the webassembly file to can load it. I found this workaround, but I want...
Macabeus
1

votes
1

answer
18

Views

Load WebAssembly module only once / Singleton

I want to use WebAssembly modules in my React app. The modules are loaded when the app starts. Now I want to reuse this wasm module in another Javascript module. How can I reuse these wasm modules in other JS modules? Do I really have to load the modules again? Loading wasm in the main module: Promi...
Michael
1

votes
1

answer
32

Views

Cannot return an array in go function that is invoked by js function. panic: ValueOf: invalid value

There is a gocode, which is compiled into a wasm file. I want one of the functions to return an array, but when I do so I see a panic: ValueOf: invalid value error. js.ValueOf function seems to be able to handle an array: ... case []interface{}: a := arrayConstructor.New(len(x)) for i, s := range x...
Don Baton
1

votes
0

answer
48

Views

Why is a string passed from JavaScript to Wasm always empty in section 4.2 of the Rust/Wasm beginner book?

I'm trying to follow the Rust WebAssembly book and I'm stuck at the exercise in section 4.2. I changed everything as described in the answer, but the given &str (name) in the greet function is always empty. Here is my version of the greet function with debugging #[wasm_bindgen] pub fn greet(name: &s...
createproblem
1

votes
0

answer
82

Views

Unity WebGL throwing Cannot read property 'length' of undefined

I'm currently experiencing this error trying to run a Unity WebGL (2018.2.11) module in a java web application running on Spring Boot (1.5.4). I tried all possible settings on Unity and on the web server as well, always getting the same result while it's loading: Uncaught TypeError: Cannot read prop...
Pedro Madrid
1

votes
1

answer
607

Views

Webassembly games and low latency keyboard mouse

How to implement low latency keyboard/mouse input for Wasm application? How did the angery bots implemented it? http://webassembly.org/demo/ is there a way to send interupts inside a wasm app? thanks!
James Brown
1

votes
1

answer
209

Views

Is it's possible to generate WASM file instead of bundle.js?

As far as I understand WASM is very closely by desing to MSIL, but designed to work in browsers. So it's low-level representation of code. Can I generate WASM code and connect it to page instead of generating minificated version of js-bundle like bundle.js?
Dmitry Bubnenkov
1

votes
1

answer
107

Views

Confusing on webassembly's binary code structure

I am trying to recognize each part of a wasm binary module according to webassembly's module structure doc. And I have done a part of those recognizations like shows below: screenshot the code in red color was labelled as 'magic code'; the code in dark orange was labelled as 'version number'; the co...
YHSPY
1

votes
1

answer
98

Views

Disable/rename imports from host environment “env”

When compiling C or C++ to web assembly (clang/llvm/binaryen) undefined functions are imported from 'env'. For example extern 'C' int afunc(); int main() { return afunc(); } compiles to (module (type $FUNCSIG$i (func (result i32))) (import 'env' 'afunc' (func $afunc (result i32))) (table 0 anyfunc)...
kazemakase

View additional questions