Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support simple asynchronous operations #3

Merged
merged 14 commits into from
Jun 17, 2022
Prev Previous commit
Next Next commit
test -sNODEJS_CATCH_EXIT=0
  • Loading branch information
toyobayashi committed Jun 17, 2022
commit 32d3db269e10ffe1a35e11954a85834091fd12f1
28 changes: 26 additions & 2 deletions packages/test/async/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ const assert = require('assert')
const child_process = require('child_process')

async function main () {
const test_async = await load('async')
const loadPromise = load('async')
const test_async = await loadPromise

const testException = 'test_async_cb_exception'

// Exception thrown from async completion callback.
// (Tested in a spawned process because the exception is fatal.)
if (process.argv[2] === 'child') {
process.on('uncaughtException', function (ex) {
// suppress ExitStatus exceptions from showing an error
if (!(ex instanceof loadPromise.Module.ExitStatus)) {
throw ex
}
})
test_async.Test(1, {}, common.mustCall(function () {
throw new Error(testException)
}))
Expand Down Expand Up @@ -56,7 +63,24 @@ async function main () {
test_async.DoRepeatedWork(workDone)

await new Promise((resolve) => {
setTimeout(resolve, 4000)
process.once('uncaughtException', common.mustCall(function (err) {
try {
throw new Error('should not fail')
} catch (err) {
assert.strictEqual(err.message, 'should not fail')
}
assert.strictEqual(err.message, 'uncaught')
resolve()
}))

// Successful async execution and completion callback.
test_async.Test(5, {}, common.mustCall(function () {
throw new Error('uncaught')
}))
})

await new Promise((resolve) => {
setTimeout(resolve, 3000)
})
}

Expand Down
1 change: 1 addition & 0 deletions packages/test/cgen.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function (_options, { isDebug, isEmscripten }) {
const linkerFlags = isEmscripten
? [
// "-sEXPORTED_FUNCTIONS=['_malloc','_free']",
'-sNODEJS_CATCH_EXIT=0',
'-sWASM_BIGINT=1',
'-sALLOW_MEMORY_GROWTH=1',
'-sMIN_CHROME_VERSION=67',
Expand Down
1 change: 1 addition & 0 deletions packages/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.load = function (targetName) {
}
}
}).then(({ Module, emnapi }) => {
p.Module = Module
p.emnapi = emnapi
resolve(Module.emnapiExports)
})
Expand Down