Class: MiniRacer::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_racer/shared.rb,
lib/mini_racer/truffleruby.rb,
ext/mini_racer_extension/mini_racer_extension.c

Overview

‘size` and `warmup!` public methods are defined in the C class

Instance Method Summary collapse

Constructor Details

#initialize(str = '') ⇒ Snapshot

Returns a new instance of Snapshot.



350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/mini_racer/shared.rb', line 350

def initialize(str = '')
  # ensure it first can load
  begin
    ctx = MiniRacer::Context.new
    ctx.eval(str)
  rescue MiniRacer::RuntimeError => e
    raise MiniRacer::SnapshotError, e.message, e.backtrace
  end

  @source = str

  # defined in the C class
  load(str)
end

Instance Method Details

#load(str) ⇒ Object

Raises:

  • (TypeError)


368
369
370
371
# File 'lib/mini_racer/truffleruby.rb', line 368

def load(str)
  raise TypeError, "wrong type argument #{str.class} (should be a string)" unless str.is_a?(String)
  # Intentionally noop since TruffleRuby mocks the snapshot API
end

#warmup!(src) ⇒ Object



365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/mini_racer/shared.rb', line 365

def warmup!(src)
  # we have to do something here
  # we are bloating memory a bit but it is more correct
  # than hitting an exception when attempty to compile invalid source
  begin
    ctx = MiniRacer::Context.new
    ctx.eval(@source)
    ctx.eval(src)
  rescue MiniRacer::RuntimeError => e
    raise MiniRacer::SnapshotError, e.message, e.backtrace
  end

  warmup_unsafe!(src)
end

#warmup_unsafe!(src) ⇒ Object

Raises:

  • (TypeError)


373
374
375
376
377
378
# File 'lib/mini_racer/truffleruby.rb', line 373

def warmup_unsafe!(src)
  raise TypeError, "wrong type argument #{src.class} (should be a string)" unless src.is_a?(String)
  # Intentionally noop since TruffleRuby mocks the snapshot API
  # by replaying snapshot source before the first eval/call
  self
end