Class: RustyRacer::Isolate

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 (0 = no limit): a script that exceeds it is terminated and raises V8OutOfMemoryError rather than aborting the process, and the isolate stays usable afterward. It is a soft limit — V8 enforces it at GC granularity, so usage may briefly overshoot, and it must comfortably exceed the isolate’s baseline (and any snapshot’s baked-in heap), since the limit is only armed once the isolate has booted. 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.



58
59
60
61
62
63
64
# File 'lib/rusty_racer.rb', line 58

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).



76
77
78
79
# File 'lib/rusty_racer.rb', line 76

def dynamic_import_resolver=(resolver)
  @dynamic_import_resolver = resolver
  _set_dynamic_import_resolver(resolver)
end