Class: MiniRacer::Context::ExternalFunction
- Inherits:
-
Object
- Object
- MiniRacer::Context::ExternalFunction
- Defined in:
- lib/mini_racer.rb,
lib/mini_racer/truffleruby.rb
Instance Method Summary collapse
-
#initialize(name, callback, parent) ⇒ ExternalFunction
constructor
A new instance of ExternalFunction.
Constructor Details
#initialize(name, callback, parent) ⇒ ExternalFunction
Returns a new instance of ExternalFunction.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/mini_racer.rb', line 119 def initialize(name, callback, parent) unless String === name raise ArgumentError, "parent_object must be a String" end parent_object, _ , @name = name.rpartition(".") @callback = callback @parent = parent @parent_object_eval = nil @parent_object = nil unless parent_object.empty? @parent_object = parent_object @parent_object_eval = "" prev = "" first = true parent_object.split(".").each do |obj| prev << obj if first @parent_object_eval << "if (typeof #{prev} === 'undefined') { #{prev} = {} };\n" else @parent_object_eval << "#{prev} = #{prev} || {};\n" end prev << "." first = false end @parent_object_eval << "#{parent_object};" end notify_v8 end |