Module: RubyRunJs::JsGlobalMethods
- Extended by:
- Helper
- Defined in:
- lib/ruby_run_js/object_methods/js_global.rb
Constant Summary collapse
- RADIX_CHARS =
{ '1'=> 1, '0'=> 0, '3'=> 3, '2'=> 2, '5'=> 5, '4'=> 4, '7'=> 7, '6'=> 6, '9'=> 9, '8'=> 8, 'a'=> 10, 'c'=> 12, 'b'=> 11, 'e'=> 14, 'd'=> 13, 'g'=> 16, 'f'=> 15, 'i'=> 18, 'h'=> 17, 'k'=> 20, 'j'=> 19, 'm'=> 22, 'l'=> 21, 'o'=> 24, 'n'=> 23, 'q'=> 26, 'p'=> 25, 's'=> 28, 'r'=> 27, 'u'=> 30, 't'=> 29, 'w'=> 32, 'v'=> 31, 'y'=> 34, 'x'=> 33, 'z'=> 35, 'A'=> 10, 'C'=> 12, 'B'=> 11, 'E'=> 14, 'D'=> 13, 'G'=> 16, 'F'=> 15, 'I'=> 18, 'H'=> 17, 'K'=> 20, 'J'=> 19, 'M'=> 22, 'L'=> 21, 'O'=> 24, 'N'=> 23, 'Q'=> 26, 'P'=> 25, 'S'=> 28, 'R'=> 27, 'U'=> 30, 'T'=> 29, 'W'=> 32, 'V'=> 31, 'Y'=> 34, 'X'=> 33, 'Z'=> 35 }.freeze
Class Method Summary collapse
- .constructor_decodeURI(builtin, this, str) ⇒ Object
- .constructor_decodeURIComponent(builtin, this, str) ⇒ Object
- .constructor_encodeURI(builtin, this, str) ⇒ Object
- .constructor_encodeURIComponent(builtin, this, str) ⇒ Object
- .constructor_eval(builtin, this, x) ⇒ Object
- .constructor_isFinite(builtin, this, number) ⇒ Object
- .constructor_isNaN(builtin, this, number) ⇒ Object
- .constructor_parseFloat(builtin, this, string) ⇒ Object
- .constructor_parseInt(builtin, this, string, radix) ⇒ Object
- .property_values ⇒ Object
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_decodeURI(builtin, this, str) ⇒ Object
170 171 172 |
# 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) ⇒ Object
178 179 180 |
# 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) ⇒ Object
166 167 168 |
# 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) ⇒ Object
174 175 176 |
# 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) ⇒ Object
83 84 85 86 |
# 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) ⇒ Object
162 163 164 |
# 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) ⇒ Object
158 159 160 |
# 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) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# 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) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# 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 ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/ruby_run_js/object_methods/js_global.rb', line 75 def property_values { 'NaN' => Float::NAN, 'Infinity' => Float::INFINITY, 'undefined' => undefined } end |