Class: RubyRunJs::JsRegExp

Inherits:
JsBaseObject show all
Defined in:
lib/ruby_run_js/objects/js_regexp.rb

Instance Attribute Summary collapse

Attributes inherited from JsBaseObject

#_class, #extensible, #own, #prototype, #value

Instance Method Summary collapse

Methods inherited from JsBaseObject

#_type, #can_put, #default_value, #define_own_property, #delete, #get, #get_items, #get_own_property, #get_property, #has_property, #put, #set_items

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

Constructor Details

#initialize(body, flags, prototype) ⇒ JsRegExp

Returns a new instance of JsRegExp.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ruby_run_js/objects/js_regexp.rb', line 9

def initialize(body, flags, prototype)
  super()
  @_class = 'RegExp'
  @prototype = prototype

  @flag_global = flags.include?('g')
  @flag_ignore_case = flags.include?('i') ? Regexp::IGNORECASE : 0
  @flag_multiline = flags.include?('m') ? Regexp::MULTILINE : 0
  @body = body

  begin
    @pattern = Regexp.new(@body, @flag_ignore_case | @flag_multiline)
  rescue
    raise make_error('SyntaxError', "Invalid RegExp pattern: #{@body}")
  end

  define_own_property('source', {
    'value' => @body,
    'enumerable' => false,
    'writable' => false,
    'configurable' => false
  })

  define_own_property('global',{
    'value' => @flag_global,
    'enumerable' => false,
    'writable' => false,
    'configurable' => false
  })

  define_own_property('ignoreCase',{
    'value' => @flag_ignore_case > 0,
    'enumerable' => false,
    'writable' => false,
    'configurable' => false
  })

  define_own_property('multiline',{
    'value' => @flag_multiline > 0,
    'enumerable' => false,
    'writable' => false,
    'configurable' => false
  })

  define_own_property('lastIndex',{
    'value' => 0.0,
    'enumerable' => false,
    'writable' => true,
    'configurable' => false
  })

end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/ruby_run_js/objects/js_regexp.rb', line 7

def body
  @body
end

#flag_globalObject (readonly)

Returns the value of attribute flag_global.



7
8
9
# File 'lib/ruby_run_js/objects/js_regexp.rb', line 7

def flag_global
  @flag_global
end

#flag_ignore_caseObject (readonly)

Returns the value of attribute flag_ignore_case.



7
8
9
# File 'lib/ruby_run_js/objects/js_regexp.rb', line 7

def flag_ignore_case
  @flag_ignore_case
end

#flag_multilineObject (readonly)

Returns the value of attribute flag_multiline.



7
8
9
# File 'lib/ruby_run_js/objects/js_regexp.rb', line 7

def flag_multiline
  @flag_multiline
end

#patternObject (readonly)

Returns the value of attribute pattern.



7
8
9
# File 'lib/ruby_run_js/objects/js_regexp.rb', line 7

def pattern
  @pattern
end