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.



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

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.



50
51
52
# File 'opal/lib/opal/errors.rb', line 50

def label
  @label
end

#linenoObject Also known as: line

Returns the value of attribute lineno.



50
51
52
# File 'opal/lib/opal/errors.rb', line 50

def lineno
  @lineno
end

#pathObject

Returns the value of attribute path.



50
51
52
# File 'opal/lib/opal/errors.rb', line 50

def path
  @path
end

Instance Method Details

#diagnostic=(diagnostic) ⇒ Object



70
71
72
73
# File 'opal/lib/opal/errors.rb', line 70

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

#location=(location) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'opal/lib/opal/errors.rb', line 75

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



56
57
58
59
60
61
62
63
64
65
66
# File 'opal/lib/opal/errors.rb', line 56

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