Object
# File lib/execjs/external_runtime.rb, line 32 def call(identifier, *args) eval "#{identifier}.apply(this, #{json_encode(args)})" end
# File lib/execjs/external_runtime.rb, line 15 def eval(source, options = {}) source = source.encode('UTF-8') if source.respond_to?(:encode) if /\S/ =~ source exec("return eval(#{json_encode("(#{source})")})") end end
# File lib/execjs/external_runtime.rb, line 23 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 46 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) json_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 37 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 73 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 61 def extract_result(output) status, value = output.empty? ? [] : json_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.