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.
128 129 130 131 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 157 |
# File 'lib/mini_racer.rb', line 128 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 |