Class: RustyRacer::Isolate
- Inherits:
-
Object
- Object
- RustyRacer::Isolate
- Defined in:
- lib/rusty_racer.rb
Overview
A V8 isolate. Owns the VM and its lifecycle; hands out Contexts to run JS in.
Class Method Summary collapse
-
.new(host_namespace: nil, snapshot: nil, timeout_ms: 0, memory_limit: 0, microtasks: :auto) ⇒ Object
Keyword-arg constructor over the positional Rust primitive.
Instance Method Summary collapse
-
#dynamic_import_resolver=(resolver) ⇒ Object
->(specifier, referrer_url, context) { Module } for JS import().
Class Method Details
.new(host_namespace: nil, snapshot: nil, timeout_ms: 0, memory_limit: 0, microtasks: :auto) ⇒ Object
Keyword-arg constructor over the positional Rust primitive. A snapshot (RustyRacer::Snapshot) boots the isolate with its baked-in state; timeout_ms caps each eval/call (0 = no limit) against in-V8 infinite loops. memory_limit caps the V8 heap in bytes: a script that exceeds the ceiling is terminated and raises V8OutOfMemoryError rather than aborting the process, and the isolate stays usable afterward. 0 (the default) does NOT disable this — it leaves V8’s own platform-derived default ceiling (typically ~2 GB on 64-bit) in place, so a runaway is still catchable instead of a fatal abort; pass a smaller value for a tighter bound. It is a soft limit — V8 enforces it at GC granularity, so usage may briefly overshoot, and an explicit limit must comfortably exceed the isolate’s baseline (and any snapshot’s baked-in heap), since it is only armed once the isolate has booted. Caveat: if the process’s available memory (e.g. a container cgroup limit) is below the active ceiling, the OS may kill the process before V8’s callback fires — set an explicit memory_limit under that bound to keep the error catchable. microtasks mirrors V8’s kAuto/kExplicit: :auto (default) drains the microtask queue when the outermost eval/call/run/evaluate completes (the standard embedder contract); :explicit drains only on #perform_microtask_checkpoint.
66 67 68 69 70 71 72 |
# File 'lib/rusty_racer.rb', line 66 def self.new(host_namespace: nil, snapshot: nil, timeout_ms: 0, memory_limit: 0, microtasks: :auto) unless %i[auto explicit].include?(microtasks) raise ArgumentError, "microtasks must be :auto or :explicit, got #{microtasks.inspect}" end _new(host_namespace, snapshot, timeout_ms, memory_limit, microtasks == :explicit) end |
Instance Method Details
#dynamic_import_resolver=(resolver) ⇒ Object
->(specifier, referrer_url, context) { Module } for JS import(). |context| is the realm import() actually fired in (the Context, not just its id), so an import() from an extra realm resolves/compiles in THAT realm rather than the main one — return e.g. context.compile_module(src, filename: specifier). The block may return a merely compiled Module: linking and evaluation are the binding’s job (V8’s host contract), and static imports met while linking resolve through this same block (also with the realm as the 3rd arg). (Module#instantiate’s own resolve block keeps its 2-arg form.) Held in an ivar so the proc stays alive for the isolate’s lifetime (the native side only keeps a weak handle).
84 85 86 87 |
# File 'lib/rusty_racer.rb', line 84 def dynamic_import_resolver=(resolver) @dynamic_import_resolver = resolver _set_dynamic_import_resolver(resolver) end |