Exception: Exception

Defined in:
opal/opal/rspec/fixes/opal/corelib/error.rb,
opal/opal/rspec/fixes/opal/corelib/error.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Exception

Returns a new instance of Exception.



44
45
46
47
# File 'opal/opal/rspec/fixes/opal/corelib/error.rb', line 44

def initialize(*args)
  # undefined check can be removed if https://github.com/opal/opal/pull/1117 happens
  `self.message = (args.length > 0 && args[0] !== undefined) ? args[0] : nil`
end

Class Method Details

.exception(*args) ⇒ Object



40
41
42
# File 'opal/opal/rspec/fixes/opal/corelib/error.rb', line 40

def self.exception(*args)
  new(*args)
end

.new(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'opal/opal/rspec/fixes/opal/corelib/error.rb', line 24

def self.new(*args)
  # undefined check can be removed if https://github.com/opal/opal/pull/1117 happens
  %x{
      var message = (args.length > 0 && args[0] !== undefined) ? args[0] : nil;
      var err = new self.$$alloc(message);

      if (Error.captureStackTrace) {
        Error.captureStackTrace(err);
      }

      err.name = self.$$name;
      err.$initialize.apply(err, args);
      return err;
    }
end

Instance Method Details

#exception(str = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'opal/opal/rspec/fixes/opal/corelib/error.rb', line 49

def exception(str=nil)
  %x{
      if (str === nil || self === str) {
        return self;
      }

      var cloned = #{self.clone};
      cloned.message = str;
      return cloned;
    }
end

#inspectObject



10
11
12
13
# File 'opal/opal/rspec/fixes/opal/corelib/error.rb', line 10

def inspect
  as_str = to_s
  as_str.empty? ? self.class.to_s : "#<#{self.class.to_s}: #{to_s}>"
end

#messageObject



6
7
8
# File 'opal/opal/rspec/fixes/opal/corelib/error.rb', line 6

def message
  to_s
end

#to_sObject



15
16
17
# File 'opal/opal/rspec/fixes/opal/corelib/error.rb', line 15

def to_s
  (@message && @message.to_s) || self.class.to_s
end