emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.69k stars 3.29k forks source link

BindingError when running unittests twice #12768

Open fibbo opened 3 years ago

fibbo commented 3 years ago

I have setup some unit tests using karma and jasmine.

The file that loads the Wasm looks like this:

declare var window: any
declare var Module: any
window.Module = {}
window.PdfToolsPromise = new Promise((resolve, reject) => {
    window.Module['onRuntimeInitialized'] = () =>{
        console.log('resolved')
        window.WebViewerLoaded = true
        resolve()
    }
})

let script = document.createElement('script');
script.src = 'PdfViewing_Main.js';
document.head.appendChild(script);

and my beforeAllTests callback looks like this:

export function beforeAllTests(): () => Promise<any> {
  return () => new Promise<void>( (resolve, reject) => {
    const checkApi = () => {
      console.log('binaries ready', window.WebViewerLoaded)
      if (window.WebViewerLoaded) {
        resolve()
        clearInterval(interval)
      }
    }
    const interval = setInterval(checkApi, 100)
    checkApi()
  })
}

When starting the unit tests it's fine but refreshing the browser or changing some test files causing a reload results in a BindingError:

message: "Cannot register public name '' twice"
name: "BindingError"
throwBindingError http://localhost:9876/PdfViewing_Main.js:1
    exposePublicSymbol http://localhost:9876/PdfViewing_Main.js:1
    __embind_register_function http://localhost:9876/PdfViewing_Main.js:1
    <anonym> http://localhost:9876/PdfViewing_Main.wasm:1181499
    <anonym> http://localhost:9876/PdfViewing_Main.wasm:44712
    ___wasm_call_ctors http://localhost:9876/PdfViewing_Main.js:1
    func http://localhost:9876/PdfViewing_Main.js:1
    callRuntimeCallbacks http://localhost:9876/PdfViewing_Main.js:1
    initRuntime http://localhost:9876/PdfViewing_Main.js:1
    doRun http://localhost:9876/PdfViewing_Main.js:1
    run http://localhost:9876/PdfViewing_Main.js:1
    runCaller http://localhost:9876/PdfViewing_Main.js:1
    removeRunDependency http://localhost:9876/PdfViewing_Main.js:1
    processPackageData http://localhost:9876/PdfViewing_Main.js:1
    onsuccess http://localhost:9876/PdfViewing_Main.js:1
    (Async: EventHandlerNonNull)
    fetchCachedPackage http://localhost:9876/PdfViewing_Main.js:1
    runWithFS http://localhost:9876/PdfViewing_Main.js:1
    onsuccess http://localhost:9876/PdfViewing_Main.js:1
    (Async: EventHandlerNonNull)
    checkCachedPackage http://localhost:9876/PdfViewing_Main.js:1
    runWithFS http://localhost:9876/PdfViewing_Main.js:1
    onsuccess http://localhost:9876/PdfViewing_Main.js:1
    (Async: EventHandlerNonNull)
    openDatabase http://localhost:9876/PdfViewing_Main.js:1
    runWithFS http://localhost:9876/PdfViewing_Main.js:1
    callRuntimeCallbacks http://localhost:9876/PdfViewing_Main.js:1
    preRun http://localhost:9876/PdfViewing_Main.js:1
    run http://localhost:9876/PdfViewing_Main.js:1
    runCaller http://localhost:9876/PdfViewing_Main.js:1
    removeRunDependency http://localhost:9876/PdfViewing_Main.js:1
    receiveInstance http://localhost:9876/PdfViewing_Main.js:1
    receiveInstantiatedSource http://localhost:9876/PdfViewing_Main.js:1
    (Async: promise callback)
    instantiateAsync http://localhost:9876/PdfViewing_Main.js:1
    (Async: promise callback)
    instantiateAsync http://localhost:9876/PdfViewing_Main.js:1
    createWasm http://localhost:9876/PdfViewing_Main.js:1
    <anonym> http://localhost:9876/PdfViewing_Main.js:1

Is there a way to avoid this?

fibbo commented 3 years ago

I thought I fixed it, but I didn't. Help is still appreciated.

fibbo commented 3 years ago

Wondering if anyone has insights on this topic

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.