Module: RubyRunJs::JsErrorMethods

Extended by:
Helper
Defined in:
lib/ruby_run_js/object_methods/js_error.rb

Class Method Summary collapse

Methods included from Helper

check_object, get_member, get_member_dot, is_accessor_descriptor, is_callable, is_data_descriptor, is_generic_descriptor, is_primitive, make_error, strict_equality

Methods included from ConversionHelper

#convert_to_js_type, #to_boolean, #to_int32, #to_integer, #to_number, #to_object, #to_primitive, #to_string, #to_uint16, #to_uint32

Class Method Details

.constructor(builtin, this, message) ⇒ Object



8
9
10
# File 'lib/ruby_run_js/object_methods/js_error.rb', line 8

def constructor(builtin, this, message)
  constructor_new(builtin, this, message)
end

.constructor_new(builtin, this, message) ⇒ Object



12
13
14
# File 'lib/ruby_run_js/object_methods/js_error.rb', line 12

def constructor_new(builtin, this, message)
  builtin.new_error('Error', message == undefined ? message : to_string(message))
end

.prototype_toString(builtin, this) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_run_js/object_methods/js_error.rb', line 16

def prototype_toString(builtin, this)
  if this.js_type != :Object
    raise make_error('TypeError', 'Error.prototype.toString called on non-object')
  end

  name = this.get('name')
  name = name == undefined ? 'Error' : to_string(name)
  msg = this.get('message')
  msg = msg == undefined ? '' : to_string(msg)
  if name == ''
    return msg
  end
  if msg == ''
    return name
  end
  "#{name}: #{msg}"
end