Skip to content

v0.13.0

Choose a tag to compare

@hmsk hmsk released this 06 Apr 20:27
· 33 commits to main since this release
7cba274

VM#on_log

Instead of collecting logs after the fact via VM#logs, you can now register a block that fires for every console.log/info/debug/warn/error call as it happens.

vm = Quickjs::VM.new
vm.on_log { |log| puts "#{log.severity}: #{log.to_s}" }

vm.eval_code('console.warn("watch out")')
# => prints: warning: watch out

Each log object exposes .severity (:info / :verbose / :warning / :error), .to_s (space-joined args), and .raw (array of Ruby values).

⚠️ VM#logs is now deprecated in favor of this API (will be omitted in v0.14.0).

POLYFILL_ENCODING

New opt-in feature flag that polyfills WHATWG Encoding (TextEncoder and TextDecoderr)

vm = Quickjs::VM.new(features: [::Quickjs::POLYFILL_ENCODING])
vm.eval_code('new TextEncoder().encode("hello")')

More for POLYFILL_FILE

Ruby interop for Blob and File

vm = Quickjs::VM.new(features: [::Quickjs::POLYFILL_FILE])

Ruby ::File objects returned from define_function blocks are surfaced as File-compatible JS proxies, supporting .name, .size, .text(), .arrayBuffer(), and .slice(). Passing such a proxy back to Ruby from JS returns the original ::File object. JS Blob / File values returned to Ruby are converted to Quickjs::Blob / Quickjs::File structs.

vm.define_function(:get_file) { File.open('report.pdf') }

vm.eval_code("get_file().name")         #=> "report.pdf"
vm.eval_code("await get_file().text()") #=> file content as String

RBS type definitions

Type signatures for the public API are now shipped with the gem and validated in CI.