diff --git a/lib/execjs/support/bun_runner.js b/lib/execjs/support/bun_runner.js index 08605af..89e3fd3 100644 --- a/lib/execjs/support/bun_runner.js +++ b/lib/execjs/support/bun_runner.js @@ -1,5 +1,5 @@ -(function(program, execJS) { (function() {execJS(program) }).call({}); })(function(self, global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source} -}, function(program) { +(function(program, execJS) { (function() {execJS(program) }).call({}); })(async function(self, global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source} +}, async function(program) { // Force BunJS to use sloppy mode see https://github.com/oven-sh/bun/issues/4527#issuecomment-1709520894 exports.abc = function(){} var __process__ = process; @@ -11,7 +11,7 @@ try { delete this.process; delete this.console; - result = program(); + result = await program(); process = __process__; if (typeof result == 'undefined' && result !== null) { printFinal('["ok"]'); diff --git a/test/test_execjs.rb b/test/test_execjs.rb index 4b0976f..b0c4d07 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -450,6 +450,15 @@ def test_uglify context.call("uglify", "function foo(bar) {\n return bar;\n}") end + def test_async_bun + skip unless ENV["EXECJS_RUNTIME"] == "Bun" + source = <<-JS + async function testAsync() { return (await new Promise((resolve) => { resolve("it works!") } )) } + JS + context = ExecJS.compile(source) + assert_equal "it works!", context.call("testAsync") + end + private def assert_output(expected, actual)