JOB_Web demos fail with "import object field 'create_object' is not a Function"
- Truncate descriptions
I'm trying to run the JOB_Web demos from the Pas2js repository:
- demo/wasienv/button/
- demo/wasienv/dom/
I'm using
-
The very latest Pas2js from GIT ( https://wiki.freepascal.org/pas2js#GIT ), from today, GIT commit 3055de55 .
(I also tested Pas2js 3.0.1, https://getpas2js.freepascal.org/ with similar results though examples needed to be modified more to work).
-
The latest FPC main branch ( https://gitlab.com/freepascal.org/fpc/source.git/ ), also from today, GIT commit source@c45d0385 .
I'm testing on Linux/x86_64. I built FPC using fpcupdeluxe (with cross-compiler to Wasm32/Wasi).
This FPC version already includes the Job.JS unit which I see is used by WASM example code (in packages/wasm-job/src/ ). I see there's a TODO "move job_web+job_js units to fpc" on https://wiki.freepascal.org/WebAssembly/DOM , I guess it is (at least partially) done now.
I had to make these 2 modifications to the examples:
-
To build
demo/wasienv/dom/
WASM part I had to fix uses clauses inpas2js/demo/wasienv/dom/WasiDomTest1.lpr
, theNoThreads
unit was used there twice. -
I had to also fix both
- pas2js/demo/wasienv/dom/WasiDomTest1.lpr
- pas2js/demo/wasienv/button/WasiButton1.lpr
In both cases I commented out "
exports JOBCallback
" inside the lpr, otherwise trying to load them in browsers resulted in errrors "duplicate import". There is a comment "workaround: fpc wasm does not yet support exporting functions from units" in both above files, possibly this is outdated comment now and FPC exports JOBCallback from Job.JS unit OK now? Because there isexports JOBCallback;
inside https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/wasm-job/src/job.js.pas?ref_type=heads#L4986 .
Still, after doing AD 1 and AD 2, running the examples in the browsers shows errors about create_object
. Here's how I try to run them:
cd ~/sources/pas2js/demo/wasienv/dom
pas2js -Jc -Jirtl.js -Tbrowser BrowserDomTest1.lpr
fpc -Twasi -Pwasm32 WasiDomTest1.lpr
mv -f WasiDomTest1 WasiDomTest1.wasm
compileserver --port=3000
This fails:
-
In Firefox: "Instantiating of WebAssembly from WasiDomTest1.wasm failed import object field 'create_object' is not a Function"
-
In Vivaldi (based on Chromium): "Instantiating of WebAssembly from WasiDomTest1.wasm failed WebAssembly.instantiate(): Import #39 "job" "create_object": function import requires a callable"
Doing it with demo/wasienv/button
is similar, here's what I do:
cd ~/sources/pas2js/demo/wasienv/button
pas2js -Jc -Jirtl.js -Tbrowser BrowserButton1.lpr
fpc -Twasi -Pwasm32 WasiButton1.lpr -Fu../dom/
mv -f WasiButton1 WasiButton1.wasm
compileserver --port=3000
... with the exact same errors from Firefox and Vivaldi.
I'm attaching the screenshots with errors.
- Show labels
- Show closed items