Closed
Description
Please include the following in your bug report:
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.74 (1092ec3)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 322eb1a92e6d4266184060346616fa0dbe39e731)
Target: wasm32-unknown-emscripten
Thread model: posix
Failing command line in full:
NA
Full link command and output with -v
appended:
emcc example.cpp exampleexport.cpp -o a.js -g -s JSPI -s JSPI_IMPORTS=['do_fetch'] --bind
I tried to use JSPI instead of ASYNCIFY, and wrote a demo, but I got this error:
example.cpp:31 Uncaught (in promise) RuntimeError: attempting to suspend without a WebAssembly.promising export
at a.wasm.example::DoFetchSample() (http://127.0.0.1:5501/a.wasm:wasm-function[27]:0x1201)
//example.h
#pragma once
#include <emscripten.h>
#include <emscripten/val.h>
class example
{
private:
public:
example();
~example();
void DoFetchSample();
};
//example.cpp
#include "example.h"
#include <emscripten/html5.h>
#include <emscripten/bind.h>
#include <stdio.h>
#include <iostream>
#include <string>
example::example()
{
}
example::~example()
{
}
EM_JS(int, do_fetch, (), {
return Asyncify.handleAsync(function () {
out("waiting for a fetch");
return fetch("a.html").then(function (response) {
out("got the fetch response");
// (normally you would do something with the fetch here)
return 42;
});
});
});
void example::DoFetchSample()
{
std::cout << "do_fetch begin: " << std::endl;
int nResult = do_fetch();
std::cout << "do_fetch end: " << nResult << std::endl;
}
//exampleexport.cpp
#include "example.h"
#include <emscripten/emscripten.h>
#include <emscripten/bind.h>
EMSCRIPTEN_BINDINGS(exampleWrapper)
{
emscripten::class_<example>("example")
.constructor<>()
.function("DoFetchSample", &example::DoFetchSample);
}
///TestDemo.html
<!DOCTYPE html>
<html lang="utf-8">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test Demo</title>
</head>
<body>
</body>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script>
var webReportCtrl = undefined;
Module = {};
Module.onRuntimeInitialized = async function () {
webReportCtrl = new Module.example();
webReportCtrl.DoModal();
};
</script>
<script src="./a.js"></script>
</html>
If i use following command, the result is ok.
emcc example.cpp exampleexport.cpp -o a.js -g -s ASYNCIFY -s ASYNCIFY_IMPORTS=['do_fetch'] --bind
Am I using JSPI wrong?
Metadata
Metadata
Assignees
Labels
No labels