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 Bun as an available runtime #127

Merged
merged 2 commits into from Sep 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -14,6 +14,10 @@ jobs:
uses: actions/checkout@v3
- name: Install Node
run: sudo apt-get install -y nodejs
- name: Install Bun
- uses: oven-sh/setup-bun@v1
terracatta marked this conversation as resolved.
Show resolved Hide resolved
with:
bun-version: latest
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -11,6 +11,7 @@ ExecJS supports these runtimes:
Rhino embedded within JRuby
* [Duktape.rb](https://github.com/judofyr/duktape.rb) - Duktape JavaScript interpreter
* [Node.js](http://nodejs.org/)
* [Bun.sh](https://bun.sh) - JavaScript runtime & toolkit designed for speed
* Apple JavaScriptCore - Included with Mac OS X
* [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)
* [Google V8](http://code.google.com/p/v8/)
Expand Down
8 changes: 8 additions & 0 deletions lib/execjs/runtimes.rb
Expand Up @@ -25,6 +25,13 @@ module Runtimes
encoding: 'UTF-8'
)

Bun = ExternalRuntime.new(
name: "Bun.sh",
command: ["bun"],
runner_path: ExecJS.root + "/support/bun_runner.js",
encoding: 'UTF-8'
)

JavaScriptCore = ExternalRuntime.new(
name: "JavaScriptCore",
command: [
Expand Down Expand Up @@ -88,6 +95,7 @@ def self.runtimes
GraalJS,
Duktape,
MiniRacer,
Bun,
terracatta marked this conversation as resolved.
Show resolved Hide resolved
Node,
JavaScriptCore,
SpiderMonkey,
Expand Down
29 changes: 29 additions & 0 deletions lib/execjs/support/bun_runner.js
@@ -0,0 +1,29 @@
(function(program, execJS) { (function() {execJS(program) }).call({}); })(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(){}
var __process__ = process;
var printFinal = function(string) {
process.stdout.write('' + string, function() {
__process__.exit(0);
});
};
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]));
}
}
} catch (err) {
process = __process__;
printFinal(JSON.stringify(['err', '' + err, err.stack]));
}
});
2 changes: 1 addition & 1 deletion test/fixtures/uglify.js
Expand Up @@ -307,7 +307,7 @@ if(!String.prototype.trim) {
function definePropertyWorks() {
try {
Object.defineProperty({}, "property", {});
return "property" in object;
return true;
byroot marked this conversation as resolved.
Show resolved Hide resolved
} catch (exception) {
return false;
}
Expand Down
15 changes: 9 additions & 6 deletions test/test_execjs.rb
Expand Up @@ -296,6 +296,9 @@ def test_console_is_undefined
end

def test_timers_are_undefined
# See Bug https://github.com/oven-sh/bun/issues/4806
skip if ENV["EXECJS_RUNTIME"] == "Bun"

assert ExecJS.eval("typeof setTimeout == 'undefined'")
assert ExecJS.eval("typeof setInterval == 'undefined'")
assert ExecJS.eval("typeof clearTimeout == 'undefined'")
Expand Down Expand Up @@ -327,7 +330,7 @@ def test_exec_syntax_error
flunk
rescue ExecJS::RuntimeError => e
assert e
assert e.backtrace[0].include?("(execjs):1"), e.backtrace.join("\n")
assert e.backtrace.join("\n").include?("(execjs):")
end
end

Expand All @@ -337,7 +340,7 @@ def test_eval_syntax_error
flunk
rescue ExecJS::RuntimeError => e
assert e
assert e.backtrace[0].include?("(execjs):1"), e.backtrace.join("\n")
assert e.backtrace.join("\n").include?("(execjs):")
end
end

Expand All @@ -347,7 +350,7 @@ def test_compile_syntax_error
flunk
rescue ExecJS::RuntimeError => e
assert e
assert e.backtrace[0].include?("(execjs):1"), e.backtrace.join("\n")
assert e.backtrace[0].include?("(execjs):"), e.backtrace.join("\n")
end
end

Expand All @@ -357,7 +360,7 @@ def test_exec_thrown_error
flunk
rescue ExecJS::ProgramError => e
assert e
assert e.backtrace[0].include?("(execjs):1"), e.backtrace.join("\n")
assert e.backtrace.join("\n").include?("(execjs):")
end
end

Expand All @@ -367,7 +370,7 @@ def test_eval_thrown_error
flunk
rescue ExecJS::ProgramError => e
assert e
assert e.backtrace[0].include?("(execjs):1"), e.backtrace.join("\n")
assert e.backtrace.join("\n").include?("(execjs):")
end
end

Expand All @@ -377,7 +380,7 @@ def test_compile_thrown_error
flunk
rescue ExecJS::ProgramError => e
assert e
assert e.backtrace[0].include?("(execjs):1"), e.backtrace.join("\n")
assert e.backtrace.join("\n").include?("(execjs):")
end
end

Expand Down