-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathmini_racer.rb
90 lines (75 loc) · 2.04 KB
/
mini_racer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require "mini_racer/version"
require "pathname"
if RUBY_ENGINE == "truffleruby"
require "mini_racer/truffleruby"
else
if ENV["LD_PRELOAD"].to_s.include?("malloc")
require "mini_racer_extension"
else
require "mini_racer_loader"
ext_filename = "mini_racer_extension.#{RbConfig::CONFIG["DLEXT"]}"
ext_path =
Gem.loaded_specs["mini_racer"].require_paths.map do |p|
(p = Pathname.new(p)).absolute? ? p : Pathname.new(__dir__).parent + p
end
ext_found = ext_path.map { |p| p + ext_filename }.find { |p| p.file? }
unless ext_found
raise LoadError,
"Could not find #{ext_filename} in #{ext_path.map(&:to_s)}"
end
MiniRacer::Loader.load(ext_found.to_s)
end
end
require "thread"
require "json"
require "io/wait"
module MiniRacer
class Error < ::StandardError; end
class ContextDisposedError < Error; end
class PlatformAlreadyInitialized < Error; end
class EvalError < Error; end
class ParseError < EvalError; end
class ScriptTerminatedError < EvalError; end
class V8OutOfMemoryError < EvalError; end
class RuntimeError < EvalError
def initialize(message)
message, *@frames = message.split("\n")
@frames.map! { "JavaScript #{_1.strip}" }
super(message)
end
def backtrace
frames = super
@frames + frames unless frames.nil?
end
end
class SnapshotError < Error
def initialize(message)
message, *@frames = message.split("\n")
@frames.map! { "JavaScript #{_1.strip}" }
super(message)
end
def backtrace
frames = super
@frames + frames unless frames.nil?
end
end
class Context
def load(filename)
eval(File.read(filename))
end
def write_heap_snapshot(file_or_io)
f = nil
implicit = false
if String === file_or_io
f = File.open(file_or_io, "w")
implicit = true
else
f = file_or_io
end
raise ArgumentError, "file_or_io" unless File === f
f.write(heap_snapshot())
ensure
f.close if implicit
end
end
end