6

I am attempting to run WebAssembly on the new V8 Google Apps Script runtime, and it appears to be supported, however it seems that async functions are terminated after they return a Promise.

let wasm= new Uint8Array([/* snip */]).buffer
function add(a,b) {
  return((async()=>{
  console.log("running function...")
  results=await WebAssembly.instantiate(wasm)
  return results.instance.exports.add(a,b)
})());
}
function test(){
  add(2,3).then(console.log).catch(console.error)
}

when I run test "running function..." is logged, then nothing. No errors, no results. I have confirmed that WebAssembly.instantiate returns a Promise. Does anyone know what is going on, or is this something to ask Google about?

Update:

Created a issue at https://issuetracker.google.com/issues/153828715

5
  • Make sure your snip is a valid module. If so, Create a issue in issuetracker. See tag info page for more details. Commented Apr 13, 2020 at 16:17
  • The exact code works in browsers too, so it is valid. Commented Apr 13, 2020 at 18:14
  • if you create a issue, link it here for wider reach Commented Apr 14, 2020 at 3:52
  • 2
    Issue is at issuetracker.google.com/issues/153828715 Commented Apr 14, 2020 at 13:25
  • Issue marked as Fixed Commented Jul 21, 2022 at 9:30

3 Answers 3

5

Refactored the sample script you provided on issue tracker and got it to work from the GAS editor (maybe Google changed something since you've posted this issue). GAS is synchronous but you can still use async/await as follows:


async function testWasm() {
    let bytes = new Uint8Array([0,97,115,109,1,0,0,0,1,7,1,96,2,127,127,1,127,3,2,1,0,7,7,1,3,97,100,100,0,0,10,9,1,7,0,32,0,32,1,106,11,0,28,4,110,97,109,101,1,6,1,0,3,97,100,100,2,13,1,0,2,0,3,108,104,115,1,3,114,104,115]);
    
    let { 
        instance: { 
            exports: { 
                add 
            }
        }
    } = await WebAssembly.instantiate(bytes);

    console.log(add(2,3));
}
Sign up to request clarification or add additional context in comments.

Comments

3

Asynchronous functionalities don't seem to be fully supported in V8 yet. There is actually an open Issue Tracker regarding this. You can click the star on the top left of the page to keep track of this issue.

In any case, please be aware that there is no explicit statement in the official documentation referring to the availability of these functionalities in V8. It just states that you can use keywords like async in your code, but it doesn't mention what functionality you will get if you use that.

Reference:

Comments

1

This is a bit late, but make sure your functions are async all the way up to the top level.

Note the change before function add below:

let wasm= new Uint8Array([/* snip */]).buffer
async function add(a,b) {
  console.log("running function...")
  results=await WebAssembly.instantiate(wasm)
  return results.instance.exports.add(a,b)
}
function test(){
  add(2,3).then(console.log).catch(console.error)
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.