module RubyRunJs::JsGlobalMethods

Constants

RADIX_CHARS

Public Class Methods

constructor_decodeURI(builtin, this, str) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 170
def constructor_decodeURI(builtin, this, str)
  str
end
constructor_decodeURIComponent(builtin, this, str) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 178
def constructor_decodeURIComponent(builtin, this, str)
  str
end
constructor_encodeURI(builtin, this, str) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 166
def constructor_encodeURI(builtin, this, str)
  str
end
constructor_encodeURIComponent(builtin, this, str) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 174
def constructor_encodeURIComponent(builtin, this, str)
  str
end
constructor_eval(builtin, this, x) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 83
def constructor_eval(builtin, this, x)
  # Todo
  raise make_error('TypeError', 'eval is not currently supported')
end
constructor_isFinite(builtin, this, number) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 162
def constructor_isFinite(builtin, this, number)
  to_number(number).finite?
end
constructor_isNaN(builtin, this, number) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 158
def constructor_isNaN(builtin, this, number)
  to_number(number).nan?
end
constructor_parseFloat(builtin, this, string) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 132
def constructor_parseFloat(builtin, this, string)
  input_string = to_string(string)
  sign = 1
  if input_string.length > 0 && input_string[0] == '-'
    sign = -1
  end
  if input_string.length > 0 && (input_string[0] == '+' || input_string[0] == '-')
    input_string = input_string[1..]
  end
  num = nil
  if input_string.start_with?('Infinity')
    num = Float::INFINITY
  else
    match_data = /^\d+\.\d*([eE][+-]?\d+)?/.match(input_string) ||
                /^\.\d+([eE][+-]?\d+)?/.match(input_string) ||
                /^\d+([eE][+-]?\d+)?/.match(input_string)
    if match_data
      num = match_data[0].to_f
    end
  end
  if num.nil?
    return Float::NAN
  end
  return num * sign
end
constructor_parseInt(builtin, this, string, radix) click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 89
def constructor_parseInt(builtin, this, string, radix)
  input_string = to_string(string).lstrip
  sign = 1
  if input_string.length > 0 && input_string[0] == '-'
    sign = -1
  end
  if input_string.length > 0 && (input_string[0] == '+' || input_string[0] == '-')
    input_string = input_string[1..]
  end
  radix = to_int32(radix)
  strip_prefix = true
  if radix != 0
    if radix < 2 || radix > 36
      return Float::NAN
    end
    if radix != 16
      strip_prefix = false
    end
  else
    radix = 10
  end
  if strip_prefix
    if input_string.length >= 2 && (input_string[0..1] == '0x' || input_string[0..1] == '0X')
      input_string = input_string[2..]
      radix = 16
    end
  end
  n = 0
  num = 0
  while n < input_string.length
    cand = RADIX_CHARS[input_string[n]]
    if cand.nil? || cand >= radix
      break
    end
    num = cand + num * radix
    n += 1
  end
  if n == 0
    return Float::NAN
  end
  (sign * num).to_f
end
property_values() click to toggle source
# File lib/ruby_run_js/object_methods/js_global.rb, line 75
def property_values
  {
    'NaN' => Float::NAN,
    'Infinity' => Float::INFINITY,
    'undefined' => undefined
  }
end