Class: Opal::OpalBacktraceLocation

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/errors.rb

Overview

Loosely compatible with Thread::Backtrace::Location

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil, lineno = nil, label = nil) ⇒ OpalBacktraceLocation

Returns a new instance of OpalBacktraceLocation.



55
56
57
# File 'opal/lib/opal/errors.rb', line 55

def initialize(path = nil, lineno = nil, label = nil)
  @path, @lineno, @label = path, lineno, label
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



53
54
55
# File 'opal/lib/opal/errors.rb', line 53

def label
  @label
end

#linenoObject Also known as: line

Returns the value of attribute lineno.



53
54
55
# File 'opal/lib/opal/errors.rb', line 53

def lineno
  @lineno
end

#pathObject

Returns the value of attribute path.



53
54
55
# File 'opal/lib/opal/errors.rb', line 53

def path
  @path
end

Instance Method Details

#diagnostic=(diagnostic) ⇒ Object



73
74
75
76
# File 'opal/lib/opal/errors.rb', line 73

def diagnostic=(diagnostic)
  return unless diagnostic
  self.location = diagnostic.location
end

#location=(location) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'opal/lib/opal/errors.rb', line 78

def location=(location)
  return unless location
  self.lineno = location.line
  if location.respond_to?(:source_line)
    self.label = location.source_line
  elsif location.respond_to?(:expression)
    self.label = location.expression.source_line
  end
end

#to_sObject



59
60
61
62
63
64
65
66
67
68
69
# File 'opal/lib/opal/errors.rb', line 59

def to_s
  string = path
  string += ":#{lineno}" if lineno
  string += ':in '
  if label
    string += "`#{label}'"
  else
    string += 'unknown'
  end
  string
end