Object
# File lib/execjs/external_runtime.rb, line 31 def call(identifier, *args) eval "#{identifier}.apply(this, #{MultiJson.encode(args)})" end
# File lib/execjs/external_runtime.rb, line 14 def eval(source, options = {}) source = source.encode('UTF-8') if source.respond_to?(:encode) if /\S/ =~ source exec("return eval(#{MultiJson.encode("(#{source})")})") end end
# File lib/execjs/external_runtime.rb, line 22 def exec(source, options = {}) source = source.encode('UTF-8') if source.respond_to?(:encode) source = "#{@source}\n#{source}" if @source compile_to_tempfile(source) do |file| extract_result(@runtime.send(:exec_runtime, file.path)) end end
# File lib/execjs/external_runtime.rb, line 45 def compile(source) @runtime.send(:runner_source).dup.tap do |output| output.sub!('#{source}') do source end output.sub!('#{encoded_source}') do encoded_source = encode_unicode_codepoints(source) MultiJson.encode("(function(){ #{encoded_source} })()") end output.sub!('#{json2_source}') do IO.read(ExecJS.root + "/support/json2.js") end end end
# File lib/execjs/external_runtime.rb, line 36 def compile_to_tempfile(source) tempfile = Tempfile.open(['execjs', '.js']) tempfile.write compile(source) tempfile.close yield tempfile ensure tempfile.close! end
# File lib/execjs/external_runtime.rb, line 72 def encode_unicode_codepoints(str) str.gsub(/[\u0080-\uffff]/) do |ch| "\\u%04x" % ch.codepoints.to_a end end
# File lib/execjs/external_runtime.rb, line 60 def extract_result(output) status, value = output.empty? ? [] : MultiJson.decode(output) if status == "ok" value elsif value =~ /SyntaxError:/ raise RuntimeError, value else raise ProgramError, value end end
Generated with the Darkfish Rdoc Generator 2.