'use strict' const assert = require('assert') const fs = require('fs') const path = require('path') const vm = require('vm') const source = fs.readFileSync(path.join(path.resolve(__dirname, '..'), 'src', 'runtime-boundary.js'), 'utf8') const sandbox = {} vm.runInNewContext(source, sandbox) const boundary = sandbox.IWBRuntimeBoundary let reports = 0 const scoped = boundary.create({ report: () => { reports++ } }) assert.strictEqual(scoped.invoke(() => { throw new Error('x') }, 'fallback'), 'fallback') assert.strictEqual(scoped.invoke(() => 3, 0), 3) scoped.async(() => Promise.reject(new Error('async')), 'safe').then((value) => { assert.strictEqual(value, 'safe') assert.strictEqual(reports, 2) return boundary.safeAsync(() => 4, 0) }).then((value) => { assert.strictEqual(value, 4); console.log('runtime boundary checks passed') }).catch((error) => { console.error(error); process.exitCode = 1 })