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

Add async/await & promise support to Bun runner #135

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://github.com/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