Skip to content

Commit

Permalink
Add async/await & promise support to Bun runner
Browse files Browse the repository at this point in the history
  • Loading branch information
reesericci authored Oct 5, 2023
1 parent dfb4e35 commit 85c6b87
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/execjs/support/bun_runner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(program, execJS) { (function() {execJS(program) }).call({}); })(function(self, global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
(function(program, execJS) { (function() {execJS(program) }).call({}); })(async function(self, global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
}, function(program) {
// Force BunJS to use sloppy mode see https://github.com/oven-sh/bun/issues/4527#issuecomment-1709520894
exports.abc = function(){}
Expand All @@ -11,17 +11,21 @@
try {
delete this.process;
delete this.console;
result = program();
process = __process__;
if (typeof result == 'undefined' && result !== null) {
printFinal('["ok"]');
} else {
try {
printFinal(JSON.stringify(['ok', result]));
} catch (err) {
printFinal(JSON.stringify(['err', '' + err, err.stack]));
(program()).then((result) => {
process = __process__;
if (typeof result == 'undefined' && result !== null) {
printFinal('["ok"]');
} else {
try {
printFinal(JSON.stringify(['ok', result]));
} catch (err) {
printFinal(JSON.stringify(['err', '' + err, err.stack]));
}
}
}
}).catch((err) => {
process = __process__;
printFinal(JSON.stringify(['err', '' + err, err.stack]));
})
} catch (err) {
process = __process__;
printFinal(JSON.stringify(['err', '' + err, err.stack]));
Expand Down

0 comments on commit 85c6b87

Please sign in to comment.