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, 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, 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. 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.
48 49 50 51 52 53 54 |
# File 'lib/rusty_racer.rb', line 48 def self.new(host_namespace: nil, snapshot: nil, timeout_ms: 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, 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).
66 67 68 69 |
# File 'lib/rusty_racer.rb', line 66 def dynamic_import_resolver=(resolver) @dynamic_import_resolver = resolver _set_dynamic_import_resolver(resolver) end |