Skip to content

Commit

Permalink
Merge pull request #135 from reesericci/patch-1
Browse files Browse the repository at this point in the history
Add async/await & promise support to Bun runner
  • Loading branch information
byroot authored Mar 1, 2024
2 parents 45043f1 + 3ab72a6 commit ea4731d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/execjs/support/bun_runner.js
Original file line number Diff line number Diff line change
@@ -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:/oven-sh/bun/issues/4527#issuecomment-1709520894
exports.abc = function(){}
var __process__ = process;
Expand All @@ -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"]');
Expand Down
9 changes: 9 additions & 0 deletions test/test_execjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ea4731d

Please sign in to comment.