Class: RubyRunJs::JsObject
- Inherits:
-
JsBaseObject
- Object
- JsBaseObject
- RubyRunJs::JsObject
- Defined in:
- lib/ruby_run_js/objects/js_object.rb
Instance Attribute Summary
Attributes inherited from JsBaseObject
#_class, #extensible, #own, #prototype, #value
Instance Method Summary collapse
- #init_with_props(props, vals) ⇒ Object
-
#initialize(prototype = nil) ⇒ JsObject
constructor
A new instance of JsObject.
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(prototype = nil) ⇒ JsObject
Returns a new instance of JsObject.
7 8 9 10 |
# File 'lib/ruby_run_js/objects/js_object.rb', line 7 def initialize(prototype = nil) super() @prototype = prototype end |
Instance Method Details
#init_with_props(props, vals) ⇒ Object
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 |
# File 'lib/ruby_run_js/objects/js_object.rb', line 12 def init_with_props(props, vals) i = 0 props.each do |kv| prop, kind = kv if @own.key?(prop) if is_data_descriptor(@own[prop]) if kind != 'init' raise make_error('SyntaxError', "Invalid object initializer! Duplicate property name #{prop}") end else if kind == 'init' || (kind == 'get' && @own.key?('get')) || (kind == 'set' && @own.key?('set')) raise make_error('SyntaxError', "Invalid object initializer! Duplicate setter/getter of prop: #{prop}") end end end if kind == 'init' define_own_property(prop, { 'value' => vals[i], 'writable' => true, 'enumerable' => true, 'configurable' => true }, false) elsif kind == 'get' define_own_property(prop,{ 'get' => vals[i], 'enumerable' => true, 'configurable' => true }, false) elsif kind == 'set' define_own_property(prop,{ 'set' => vals[i], 'enumerable' => true, 'configurable' => true }, false) else raise "Invalid property kind - #{kind}. Expected one of init, get, set." end i += 1 end end |